PDA

View Full Version : timer1 trouble



beginner10
- 19th August 2009, 11:20
Hello,

i'm using a pic16f882 with a 20 Mhz oscillator connected to pin 9 and 10.
i try to get a timer running with a tick every 0.1 second, but i cannot get it to work.

What's the problem?



@ DEVICE PIC16F882,HS_OSC
DEFINE OSC 20

' Timer1 Registers:
' Prescaler=1:8; TMR1 Preset=0; Freq=9,53674Hz; Period=0,1048576 s
T1CON.5 = 0 ' T1CON.T1CKPS1 = 1 ' bits 5-4 Prescaler Rate Select bits
T1CON.4 = 0 ' T1CON.T1CKPS0 = 1
T1CON.3 = 1 ' T1CON.T1OSCEN = 1 ' Timer1 Osc Enable: bit 1=on
pause 250 'delay for starting oscillator
T1CON.2 = 1 ' T1CON.T1SYNC = 1 ' Synchronization Control bit:
T1CON.1 = 0 ' T1CON.TMR1CS = 0 ' Source bit: 0=Internal clock (FOSC/4) / 1 ' External clock from pin T1CKI
T1CON.0 = 1 ' T1CON.TMR1ON = 1 ' bit 0 enables timer
TMR1H = $0 ' preset for timer1 MSB register
TMR1L = $0 ' preset for timer1 LSB register



when I try to read the TMR1H, it's counting like crazy, and keeps overflowing ( thus recounting to 255).

Thanks in advance

Archangel
- 19th August 2009, 17:30
Hello beginner1,
T1 is a 16 bit timer so it should overflow at 65535 not 255. Using Mister_E's PICMultiCalc
you should set your timer so: Preset at 34286, 1:16 prescale, will overflow @ 100.001 mSec