How do I change the timers prescaler?
The range is from 1ms up to 10 seconds or more.
How do I change the timers prescaler?
The range is from 1ms up to 10 seconds or more.
You look in the datasheet for the particular PIC you're using, look up the section on the particular timer you're about to use, say TMR1. It'll tell you where the prescaler selection bits are (usually in T1CON for TMR1) and how to set them to get various prescaler ratios.
IF you run the PIC at 4Mhz the timer ticks at 1Mhz, it's 16bits wide so the longest time it can measure is 65.5ms, each "tick" is 1us. On the 16F877, for example, the highest prescaler ratio is 1:8 so the longest time possible to measure is 524ms....
TMR2 has a prescaler possible of 1:16 which will give you just over one second. EDIT: Sorry TMR2 may only be 8bits but look it for the PIC in question.
Depending on what else you're going to do with the PIC there are various ways to go about this. You can run the PIC at a much lower frequency, like 100kHz or something like that. Or you can use an external oscillator to clock TMR1. If you design a 1kHz oscillator and set TMR1 up derive its clock extarnally (again, see T1CON register for TMR1 details) you'll be able to measte 65535ms or ~65seconds with a resolution of 1ms.
Make the oscillator 5kHz and you'll get 200us resolution and you'll still be able to measure up to ~13 seconds.
/Henrik.
Rough explanation of something.
Use an interrupt to start/stop the timebase/counter. Use a fixed timebase and monitor the timer overflow. at each overflow, increment a variable.
Select a interuptable pin
Set it to rising edge
once the interrupt happen Start the Timebase/counter
At next interrupt. Stop timer and process the maths.
Overflow can be managed with an ISR.
When well done, you can have a really accurate reading in uSec precision or so. Sounds like a OlympicTimer
Last edited by mister_e; - 7th March 2011 at 09:10.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks