Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Prescalar and Postscalar

Status
Not open for further replies.

desijays

New Member
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.

But I don't understand the concept of postscalar.

Thank you
 
Hi desijays I'm also in the same situation like you worked with pre-scaller but don't know what is post-scaller & for what purpose is there.

I'm also waiting for a good reply.
 
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.
 
Nigle beat me to it:
----------------------------
The prescaler divides down the clock going into the counter register.

A postscaler of 1:1 is like a counter witout a postscaler.

With the postscaler 2:1 the counter must reach zero twice for the timer interupt flag bit to be set

With the postscaler 4:1 ... 4 times ....

etc
 
Last edited:
Hi thanks for the reply now we know where the pre & post scallers are.

If pre-scaller is set to 1:4 & post-scaller 1:2 same as directly load pre-scaler 1:8 without a postscaler 1:1

Thanks
 
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 agian.
 
desijays said:
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 again.

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.

Thank you.
 
kchriste said:
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.

Thanks kchriste its a very useful technic where I have never heard.
 
Status
Not open for further replies.

Latest threads

Back
Top