The 16f877a has a timer that supports both postscalar and prescalar operations.
Could anyone please let me know the difference between the prescalar and postscalar functionality?
I tried using the prescalar functionality in the pic 16f877a and realized depending upon the number set as prescalar, that many instruction cycles would have to pass by before the timer increments by one.
It's dead simple, and explained in the datasheets and reference manuals.
A timer is a clock oscillator feeding a counter - a pre-scaler goes between the clock and counter, a post-scaler goes after the counter. There are specific advantages for either.
Thank you Nigel and 3vo. I now get an idea of the difference between the postscalar and prescalar. But I'll have to work it out on the controller for real, before I am convinced I figured it out.
Thank you Nigel and 3vo. I now get an idea of the difference between the postscalar and prescalar. But I'll have to work it out on the controller for real, before I am convinced I figured it out.
If you need to experience it start with the prescaler and postscaler set to 1:1 or off (same thing). Then activate the prescale to get a feel for how it works. Then the same with the post scaler. Have fun.
One advantage of having the postscaler set to more than 1:1 is when you use PWM. This would allow you to run the PWM rate at say 40Khz but you could set the postscaler to 1:40 so that the interrupt routine to update the PWM duty cycle only occurs at a 1Khz rate thus making it easy to output a low frequency sinewave using only one timer.
Thank you everyone for all the replies. So this is what I tried and this is what I observed.
I used the pic16f877a microcontroller. I used timer 2.
First I set the prescaler to 1:4 and as anticipated for every 4 instruction cycles the timer2 counter incremented by one.
Then I reset the prescalar to 1:1 and set the postscalar 1:2 and the timer 2 counter had to topple from '0xff' to '0x00' twice before the timer2 flag bit was set.
I hope my observations conform to the norm. Tonight I plan to set the prescalar and the postscalar to jus see how it works.
One advantage of having the postscaler set to more than 1:1 is when you use PWM. This would allow you to run the PWM rate at say 40Khz but you could set the postscaler to 1:40 so that the interrupt routine to update the PWM duty cycle only occurs at a 1Khz rate thus making it easy to output a low frequency sinewave using only one timer.