PDA

View Full Version : How to set Tmr1 to interrupt every 5 seconds



Tomexx
- 3rd December 2008, 03:07
Hi,
So I'm playing with DT's instant interrupts and even started to modify the T1CON register to adjust the prescaler. I'm using the 16F628A running at 4Mhz so it looks like the maximum time I can get from timer1 is about 0.5s

4Mhz/4 = 1us * 65535 = 0.0655ms * 8 (max prescaler) = 0.524s and that seems to work as my led blinks around 0.5s ON, 0.5s OFF

I'm very new to the interrupts and would like to trigger my interrupt if my switch on PortB.0 hasn't been pressed for at least 10 seconds.

How can I do that?

Thanks,
Tom



@ __config _HS_OSC & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
SWITCH VAR PORTB.0
LED1 VAR PORTB.1

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

T1CON = %00110001 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

Main:
PAUSE 1
GOTO Main

'---[TMR1 - interrupt handler]--------------------------------------------------
ToggleLED1:
TOGGLE LED1
@ INT_RETURN

Charles Linquis
- 3rd December 2008, 04:51
One way would be to increase your interrupt rate to once every 50 milliseconds. In your ISR, check for PORTB.0 to be low and increment a counter. If the counter reaches 200, before PORTB.0 goes low, then the button hasn't been pushed for 10 seconds.