Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 16th April 2008, 08:30 AM   (permalink)
Default Prescalar and Postscalar

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
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 16th April 2008, 09:35 AM   (permalink)
Default

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.
Suraj143 is offline   Reply With Quote
Old 16th April 2008, 09:41 AM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now   Reply With Quote
Old 16th April 2008, 09:42 AM   (permalink)
3v0
Default

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 by 3v0; 16th April 2008 at 09:51 AM.
3v0 is offline   Reply With Quote
Old 16th April 2008, 10:01 AM   (permalink)
Default

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
Suraj143 is offline   Reply With Quote
Old 17th April 2008, 09:01 AM   (permalink)
Default

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.
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 17th April 2008, 09:57 AM   (permalink)
3v0
Default

Quote:
Originally Posted by desijays
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.
3v0 is offline   Reply With Quote
Old 18th April 2008, 04:09 AM   (permalink)
Default

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.
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline   Reply With Quote
Old 18th April 2008, 08:04 AM   (permalink)
Default

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.
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 21st April 2008, 02:52 AM   (permalink)
Default

Quote:
Originally Posted by kchriste
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.
Suraj143 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 09:32 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.