Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
This is worrying as servoPos is being initiated after interrupts are enabled.3rd BREAK
2005.12 us
ms =1
CNT = 1
SERVOPOS() 0-8 filled
i=9
Rest '0'
I don't see how this is possible. 0.12uS is 1 clock cycle.1st BREAK
0.12us
all '0'
The last one I've got is 18F4431 32MHz XTL REMOTE_SLAVE 164 3 020223 1600.txt'18F4431 32MHz XTL REMOTE_SLAVE 164 371 020223 2330
G'day M,This is worrying as servoPos is being initiated after interrupts are enabled.
You need to move these two lines further down,
Enable High 'This is set for SERVOS
Enable Low 'This is set for GPS later
To after these two,
INTCON.PEIE = 1
INTCON.GIE = 1
I don't see how this is possible. 0.12uS is 1 clock cycle.
Assuming the break point is in the ISR then the first thing it's doing is executing the ISR which it shouldn't be doing as nothing is setup. Or, is it mS?
One thing that's just occurred to me, there is no longer any interrupt priority used, should it still be "On High Interrupt"?
Mike.
Hi M,Edit, does the A.I. program get rid of all indenting?
Hi J,In #371:
CCPR1L = 0x13
CCPR2H = 0x07
Shouldn't it be CCPR1H
Hi M,No objection at all. Not being able to debug is a major stumbling block.
If someone can printout the timing of the CCP1 output that would be very useful.
Also, confirming that the timer2 interrupt is happening every millisecond.
I note that these two lines,
Enable High 'This is set for SERVOS
Enable Low 'This is set for GPS later
are still at the beginning of the code - lines 38 & 39.
Interrupts should not be enabled until after they are setup but in this case it shouldn't matter as no interrupts will occur until they are setup.
Mike.
#include <xc.h>
#include "config.c"
#include <stdint.h>
#define _XTAL_FREQ 32000000
#define NUM_SERVOS 10
uint16_t wordTemp;
uint32_t ms;
uint8_t count=0,servoCount;
uint16_t servoPos[NUM_SERVOS];
void main(void) {
OSCCON=0b01110000; //8MHz
PLLEN=1; //x4=32MHz
//setup 1mS interrupt = 8,000,000/16 = 500,000/10 = 50,000 set PR2=49 = 50,000/50 = 1000 = 1mS
T2CON=0b01001110; //pre=16 post=10
PR2=49;
TMR2IE=1; //timer 2 interrupts enable
T1CON=0; //timer 1 stopped
for(uint8_t i=0;i<NUM_SERVOS;i++){
servoPos[i]=i*1000+8000; //1ms(8000) to 1.875(7/8ths - 15000)ms in 1/8th mS steps
}
TRISC=0b11111100; //CCP0 & 1 output
PEIE=1;
GIE=1;
while(1){
//adjust servo positions here
}
}
void __interrupt() inter(void){
if(TMR2IE && TMR2IF){
ms++;
count++;
if(count>=20){ //start every 20mS
TMR1=0; //zero timer 1
T1CON=1; //start timer 1
count=0;
CCP1CON=0b1000; //CCP1 pin low and high on match - will be first pulse
CCPR1L=0x0d;
CCPR1H=0x07;
CCP1IE=1; //enable CCP1 interrupts
CCP1IF=0; //ensure interrupt flag is clear
servoCount=0; //reset servoCount
LATC0=1; //connected to data in of shift register will clock in a high when CCP1 goes high
}
TMR2IF=0;
}
if(CCP1IE && CCP1IF){
LATC0=0; //clear the data in pin
if(servoCount==9) //have we done all servos?
CCP1IE=0; //yes so no more CCP1 interrupts
if(CCP1CON==0b1000){ //have we started the 4000 cycle pulse
CCP1CON=0b1001; //yes so end the pulse after 0.5mS
wordTemp=CCPR1H*256+CCPR1L;
wordTemp=wordTemp+4000;
CCPR1L=wordTemp & 255;
CCPR1H=wordTemp/256;
}else{
CCP1CON=0b1000; //No so output the timed gap
wordTemp=CCPR1H*256+CCPR1L;
wordTemp=wordTemp-4000+servoPos[servoCount];
CCPR1L=wordTemp&255;
CCPR1H=wordTemp/256;
servoCount=servoCount+1;
}
CCP1IF=0;
}
}
for(uint8_t i=0;i<NUM_SERVOS;i++){
servoPos[i]=i*1000+8000; //1ms(8000) to 1.875(7/8ths - 15000)ms in 1/8th mS steps
}
RC2 pin is for digital I/O or CCP1 (or FLTA interrupt), not for SPI.Hi M,
As the SPI MOSI is on RC2, the RC PIN will need changed to RC1 sometime.
Is this a matter of changing all of the CCPR1 to CCPR2 etc?
C
Hi J,RC2 pin is for digital I/O or CCP1 (or FLTA interrupt), not for SPI.
Yes, everything will do it's thing and when it's complete it sets it's interrupt flag and generates an interrupt. If while a byte (from RS232) is being loaded into memory a timer 2 interrupt occurs then it'll interrupt once the current interrupt has finished. As all these things are happening at 8,000,000 instructions per second then nothing gets missed. An interrupt routine would have to be over 500uS (4000 instructions) long for an interrupt to be missed.Am I correct that the H/Ws works in parallel?