thanks a lot guys
but this did not helped me
what i want to do is that i am trying to make a motor timer controller .at the heart of setup i am using pic 16f877a with a 24 Hz crystal (it can be changed) it has three switches attached which controls the time for which the motor will run if i press first key the motor should run for 1 hour if i press second then it should run for 2 hours if i press third it should run for 4 hour . i am new to controller and its programming so having problem with the concept of timer . even after going through the data sheet of controller i cannot understand the math used by the micro controller to calculate time. once i understand the concept how time is calculated by Uc i think i will be able to write the code.
if you could help me with this(math) then it will be very helpful.
thanks
Are you sure it's 24Hz?
Anyways, since you say it can be changed, I'll explain with 4 MHz crystal in mind.
If you have 4Mhz crystal, the instruction cycle is [( 1/(4 * 10^6) ) * 4] seconds = 1 µs. So, each instruction takes 1 µs. Each timer increment occurs each 1µs.
Let's say we're using Timer 1.
It is a 16-bit timer. So, it increments from 0 to (2^16)-1 = 65535. Each increment occurs each 1 µs. When the timer reaches 65535, the timer overflows. Since each increment takes 1µs, 65535 increments takes 65535 µs. Then, it takes 1 more µs for the timer to overflow to zero. This is when the interrupt flag is raised. So, starting from zero, interrupt occurs each 65.536 ms.
Using the prescaler, we can prolong this time. If we use the 1:8 prescale setting, each timer increment now takes (1 µs * 8) = 8µs. So, the interrupt occurs every (65.536 ms * 8) = 524.288ms.
Have you understood this much? This is more or less all the math required to calculate the time for one interrupt to occur.
If you are clear regarding this, I will try to explain interrupt implementation in this case(if you need help with these).
Hope this helps.
Tahmid.