2^16 = 65536, so 65535 is the maximum value that can be stored in 2 byte register. When loaded with 3035, 65535 - 3035 = 62500 timer ticks are required before overflow, which requires 8 * 62500 = 500000 clock cycles with 1:8 prescaler. It results 0.5 seconds, as clock cycles take 1 us with a 4 MHz XTAL.
(8 hours) * (3600 seconds per hour) * (2 overflows per second) = 57600
At each interrupt, reload that value back into TMR1 again,
That's easy, the 8 hour delay was made by counting half seconds. The figure 57600 is the number of half seconds in 8 hours. To change it to one hour, use the number of half seconds in that period instead:
1hr = 60 mins = 3600 seconds, so the number of half seconds in 7200. Simply change 57600 to 7200 and the period becomes one hour instead of 8.
A pre-scaler is just another counter placed ahead of the main counter, it's purpose is to slow the count down if a longer period is needed. The counter alone would be 1:1 pre-scale, changing it to 2:1 would make it count at half the speed, 1:4 at one quarter speed and so on. You just use the most appropriate setting for your application, as you needed fairly long delays, a high prescaler value was chosen.
Brian.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?