Hey Folks....more trouble for me....I'm using an mega8535 and I'm having trouble with the 16bit timer1. I have a sensor that is located off center on an inverted pendulum. I need to reset the timer every other time the timer1 capture interupt fires. That part is the easy part, I just XOR a bit each time and clear timer1 when it equals one. The hard part is I also need to know where the pendulum is! I tried comparing times between the first couple swings after the mega8535 is reset, but sometimes it thinks its on the left, sometimes it thinks its on the right ... I've spent all day on this problem. :roll: My timer1 capture interupt subroutine is below. I'd appreciate any help!
TIM1_CAPT: sbrs Flag, 7 ; Check if Time1 already Saved rjmp Save_Time1 sbrs Flag, 6 ; Check if Time2 already Saved rjmp Save_Time2 rjmp Flip_Flop Save_Time1: in Time1L, TCNT1L ; in Time1H, TCNT1H ; Save Time1 and set flag saying we did so sbr Flag, 0x80 rjmp Reset_Timer Save_Time2: in Time2L, TCNT1L ; in Time2H, TCNT1H ; Save Time1 and set flag saying we did so sbr Flag, 0x40 cp Time2L, Time1L cpc Time2H, Time2H brsh Exit_Timer_Capture Flip_Flop: ldi Temp, 0x01 eor Flag, Temp ; Switch bit 0 in Flag sbrs Flag, 0 ; skip if bit 0 is set rjmp Exit_Timer_Capture ; else jump to Done ; CODE HERE TO RUN EVERY OTHER TIME Reset_Timer: ldi Temp, 0x00 ; Reset Timer; out TCNT1H, Temp ; out TCNT1L, Temp ; Exit_Timer_Capture: ; reti