View Full Version : Timers
mitchf14
- 15th November 2008, 15:46
I need some help with the hardware timers I'm using pic16f873 with a 20 MHz crystal, how could i create the same simple program below with a hardware timer i want a 10 second pause in between. The program is very simple example to help me learn to use the timers. thank you
Start
portb.2 = 1
pause 10000
portb.3 = 1
End
Charles Linquis
- 15th November 2008, 17:35
The "generic" way is to
Figure out the maximum "length" of the timers (use Mr. E's Multi-Calc).
Pick an appropriate timer and prescaler.
Figure out what the pre-load count should be for the time interval you need based on the timer, prescaler and oscillator.
The counter will increment from the pre-load value and when it reaches maximum count (0xFFFF for a 16 bit counter), it will set the timer's overflow flag bit (INTCON.2 in the case of TMR0).
So to intialize:
Load the counter with the pre-load count
clear the timer overflow flag bit
enable the timer
Then --
Top_Of_Main_program:
do some stuff here
IF INTCON.2 THEN ; the bit is set, so overflow has occurred.
TMR0H = HighByte of preload value
TMR0L = LowByte of preload value ; the order is important!
INTCON.2 = 0 ; Clear the flag bit
;Do what you want here when the timeout value is reached.
ENDIF
Goto Top_Of_Main_program
mitchf14
- 15th November 2008, 20:08
Thanks for the reply i will try that out.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.