Re: Background Pulse Counter
I should add that with the DT Interrupts, I am only using Timer 1 for an internal event timer.
I would presume this would mean anything I use timer 2 or 3 for would leave DT Interrupts unaffected under this situation.
Thanks
George
Re: Background Pulse Counter
TMR0 can be setup as a 8 or 16 bit counter clocked by your signal attached to the T0CKI-pin, you can choose rising or falling edge. It can also be set to interrupt on overflow so if you want to run your sub every 2000 counts simply preload the TMR0 register pair with 63536 and after 2000 counts an interrupt will occur. Remember to reload the TMR0 register pairs again, otherwise it'll keep counting from 0.
Or you can just read the count at your leasure if that's better/easier/more suitable. When using 16bit mode there's a special order in which you must read/write the TMR0 register pairs, make sure to read the datasheet.
Re: Background Pulse Counter
This turned out the be far easier than I thought it would be.
I set T0CON for $E8
TMR0ON = Enable Timer 0
T08BIT = Timer0 8 bit
T0CS = Transition on TOCK1
T0SE = Low to High transition (beginning of 2uS pulse)
PSA = Timer0 prescaler is not assigned
T0PS2:T0PS0 all 0
Then I set the register to 0
TMR0L = $00
In my control loop which enables the device which provides the 2uS speed proportional pulses I read the TMR0L and when it equals to a predetermined value the sub is called and when the sub is finished the register is again set to zero.
It counts in the background and the control loop doesn't have to consume that many cycles reading the register so it really doesn't burden the control loop.
Thanks