PDA

View Full Version : Timer1 issues



mitchf14
- 9th January 2009, 16:13
I'm learning how to use the hardware timers, and it can't seem to get the TMR1 working, i am using a pic16f628 with two 4 mhz crystals 1 on pins ra6,ra7 and they other on pins rb6,rb7 which i don't know for sure if it is necessary or should just use they internal crystal ?

This is the code i have so far


LED VAR PORTB.0
LED1 VAR PORTB.1
ON INTERRUPT GOTO TIMER1INT

LED = 0
LED1 = 0

TRISA = %00000000
TRISB = %00000000


INTCON.7 = 1 ' ENABLE THE GLOBAL INTERRUPT
PIE1.0 = 1 ' ENABLE THEY TMR1 INTERRUPT
T1CON.1 = 1 ' SETS THE MODE TO EXTERNAL CLOCK RB6,RB7
T1CON.2 = 0 ' SYNCORNOSES BOTH CRYSTALS
T1CON.3 = 1 ' ENABLES THEY OSCILATOR RB6,RB7 ON
T1CON.4 = 1 ' SETS THE SECOND BIT OF THE PRESCALER
T1CON.5 = 1 ' SETS THE FIRST BIT OF THE PRESCALER
TMR1L = 220 ' SETS THE LOW BIT PRESCALER
TMR1H = 11 ' SETS THE HIGH BIT PRESCALER
T1CON.0 = 0 ' ACTIVES THE TIMER

Start:


GoTo Start

TIMER1INT:

IF LED = 1 THEN
LED = 0
LED1 = 1
ELSE
LED = 1
LED1 = 0
ENDIF


RETURN

end

Could really use some help thanks.

Acetronics2
- 9th January 2009, 16:21
Hi,




A crystal oscillator circuit is built in between pins T1OSI
(input) and T1OSO (amplifier output). It is enabled by
setting control bit T1OSCEN (T1CON<3>). The oscillator
is a low power oscillator rated up to 200 kHz. It will
continue to run during SLEEP. It is primarily intended
for a 32 kHz crystal. Table 7-1 shows the capacitor
selection for the Timer1 oscillator.
The Timer1 oscillator is identical to the LP oscillator.
The user must provide a software time delay to ensure
proper oscillator start-up.



Does this Datasheet excerpt ring you a bell somewhere ???

use the main 4 Mhz osc ... ( TMR1CS = 0 )

Alain