futz
Active Member
I wrote some 12F683 code to read an incoming servo pulse-train. Worked pretty well, but I have a small problem with it that I can't seem to find without a debugger. So I ported to 18F1320 (Junebug) and now I have a different problem that I can't find the solution to. It's probably something stupid I'm doing. 
The ISR captures the rising edge of each pulse just fine, but doesn't ever catch the falling edge. Here's the setup and ISR code:
Any ideas? I can post the whole thing if necessary.
EDIT: Oh ya, this might be pertinent - the incoming pulse-train is from a 3.3V ARM7. The 12F683 had no problem capturing it, so I doubt that that's the problem, especially since it captures the rising edges perfectly.
EDIT2: Just noticed that porta.RB3 is never going low. That's why it isn't capturing falling edges. Hmm... Wonder if I inadvertantly turned on weak-pullups? Checking now...
EDIT3: Nope, that wasn't it. Added a pulldown resistor just in case, but it didn't help.
The ISR captures the rising edge of each pulse just fine, but doesn't ever catch the falling edge. Here's the setup and ISR code:
Code:
ccp1con = 0b00000101; //capture rising edge
t1con = 0b00010001; //Timer1 enable, pre=2
t3con.T3CCP1 = 0; //Timer1 is clock source for CCP
rcon.IPEN = 0; //disable priority interrupts
pie1.CCP1IE = 1; //enable ccp1 interrupt
intcon.PEIE = 1; //enable peripheral interrupts
intcon.GIE = 1; //enable global interrupts
...
...
...
void interrupt(void)
{
if(porta.RB3){ //rising edge detected
start = ccpr1l; //store start value
start |= ccpr1h << 8;
ccp1con = 0b00000100; //set to capture falling edge
}
else{ //falling edge detected
end = ccpr1l; //store end value
end |= ccpr1h << 8;
ccp1con = 0b00000101; //set to capture rising edge
flag = 1;
if(end < start)
pwin = (0xffff - start) + end;
else
pwin = end - start;
}
pir1.CCP1IF = 0; //clear interrupt flag
}
EDIT: Oh ya, this might be pertinent - the incoming pulse-train is from a 3.3V ARM7. The 12F683 had no problem capturing it, so I doubt that that's the problem, especially since it captures the rising edges perfectly.
EDIT2: Just noticed that porta.RB3 is never going low. That's why it isn't capturing falling edges. Hmm... Wonder if I inadvertantly turned on weak-pullups? Checking now...
EDIT3: Nope, that wasn't it. Added a pulldown resistor just in case, but it didn't help.
Last edited: