PDA

View Full Version : Timer / CCP Question



jamie_s
- 2nd November 2005, 04:19
Hi,

This is probably more a Microchip question rather than a PBP question, but seeing as im writing in PBP, I'll ask here 1st.

Basically what im trying to find out is whether the TMR1L and TMR1H are reset when the timer is activated by T1CON.0 = 1 or if i need to reset them manually as i have in my code below?



startloop:
CCP1CON = %00000110 ' Enable the CCP1 capture, 4th rising edge
T1CON.0 = 1 ' start the timer

loop:
IF (capture = 0) Then loop ' Wait here until captured

period.lowbyte = CCPR1L ' Store the captured value in
period.highbyte = CCPR1H ' period variable
T1CON.0 = 0 ' stop the timer
CCP1CON = %00000000 ' Disable the CCP1 capture
TMR1L = 0 ' Clear Timer1 low register
TMR1H = 0 ' Clear Timer1 high register

sougata
- 2nd November 2005, 05:03
Hi there,

Stopping the Timer only disables the clock input.(As far as the block for 18F452 says). So you have to manually reset the timer registers. It is worth noting that the TMR1H registers are actually updated when you write something to the TMR1L. Thus the TMR1H should be written first. This ensures that all the 16bits get updated at the same time.

Regrads

Sougata

jamie_s
- 2nd November 2005, 08:22
I forgot to mention the pic is a 16F628A, but should be the same in operation.

So, theoretically, I should clear the timer values before starting the timer and enabling the CCP.