Hi! I have two question, can you help me?
1) I'm using TMR1 as a timer and it ticks every 100ms. Now, I would like to measure an external clock (RPM) (0 - 1000Hz) and display it every 500ms on a LCD display. The extenal source is connected to RA4 and think it is possible to use TMR0 as a counter. The problem is that TMR0 is a 8-bit timer and it counts till 256 until overflow. So, my question is: If I set TMR0 prescaler to 1:4, would it be possible to count 256*4 = 1024 until overflow? I mean, will TMR0 count every 4 external ticks?
Here is Bruce's TMR0 counter prescaled 1:1 from the forum. It uses interrupt but as my TMR1 ticks every 100ms, i think it's not necessary to interrupt TMR0.
2) If a set TMR2 prescaler to 1:256 and set TMR2 = 0, it will interrupt every ~65,5ms (4MHz crystal). I a set the postscaler to 1:16, will it interrupt every 16*65,5ms = 1,048s?Code:TRISA = %00010000 ' Set PORTA.4 (TOCKI) to input for timer0 OPTION_REG = %00111000 'Transition on TOCKI (RA4), 'Increment on falling edge 'Prescalar assigned to WDT for a 1:1 TMR0 ratio. INTCON.2 = 0 ' Clear Timer0 int flag INTCON.5 = 1 ' Enable Timer0 int TMR0 = 0 ' Set TMR0 to 0. ON INTERRUPT GOTO LapCount Main: ' Do something here goto Main disable LapCount: TMR0 = 0 ' Indicate we're in interrupt handler INTCON.2 = 0 ' Clear TMR0 Interrupt Flag (Bit 2) Resume Enable
Thanks in advance.
Sylvio




Bookmarks