UTMonkey
Member
I would like to have a TIMER0 interrupt fire "around" 300 times a second.
Here is my working out, please point out any misunderstandings
1. The uC is running at 8Mhz so FOSC/4 = 2MIPS
2. The TIMER0 interrupt will fire at 8 bit rollover (FF->00) or 16 bit rollover (FFFF->0000), depending on a clear\set of the relevant bit.
3. An increment of TIMER0 will take 1 instruction (or tick?), so 256 (or 65536) ticks later the interrupt will fire.
4. If my uC is running at 2MIPS the interrupt (without prescaling) would fire7,812 times a second (8 bit) or 30 times (16bit).
If the above is correct I guess I would need to muck around with TIMER0's prescaler.
Here goes:-
Prescale set @ 1:2 TIMER0 interrupt will fire 3,906 times (8bit) or 15 times (16bit) a second.
Prescale set @ 1:4 TIMER0 interrupt will fire 1,953 times (8bit) or 7 times (16bit) a second.
Prescale set @ 1:8 TIMER0 interrupt will fire 976 times (8bit) or 3 times (16bit) a second.
Prescale set @ 1:16 TIMER0 interrupt will fire 488 times (8bit) or Once (16bit)
Prescale set @ 1:32 TIMER0 interrupt will fire 244 times a second (8bit) or every second (16bit)
Prescale set @ 1:64 TIMER0 interrupt will fire 122 times a second (8bit) or once every 2 seconds (16bit)
Prescale set @ 1:128 TIMER0 interrupt will fire 61 times a second (8bit) or once every 4 seconds (16bit)
Prescale set @ 1:256 TIMER0 interrupt will fire 30 times a second (8bit) or once ever 8 seconds (16bit)
These are very rough calculations as I don't know how to include the remainder element of prescaling.
So looking back at my original requirement if I wanted to have the TIMER0 interrupt to fire 300 times, a prescaling value of 1:16 (488) comes closest to what I want? Is their a better way of doing this?
Mark
Here is my working out, please point out any misunderstandings
1. The uC is running at 8Mhz so FOSC/4 = 2MIPS
2. The TIMER0 interrupt will fire at 8 bit rollover (FF->00) or 16 bit rollover (FFFF->0000), depending on a clear\set of the relevant bit.
3. An increment of TIMER0 will take 1 instruction (or tick?), so 256 (or 65536) ticks later the interrupt will fire.
4. If my uC is running at 2MIPS the interrupt (without prescaling) would fire7,812 times a second (8 bit) or 30 times (16bit).
If the above is correct I guess I would need to muck around with TIMER0's prescaler.
Here goes:-
Prescale set @ 1:2 TIMER0 interrupt will fire 3,906 times (8bit) or 15 times (16bit) a second.
Prescale set @ 1:4 TIMER0 interrupt will fire 1,953 times (8bit) or 7 times (16bit) a second.
Prescale set @ 1:8 TIMER0 interrupt will fire 976 times (8bit) or 3 times (16bit) a second.
Prescale set @ 1:16 TIMER0 interrupt will fire 488 times (8bit) or Once (16bit)
Prescale set @ 1:32 TIMER0 interrupt will fire 244 times a second (8bit) or every second (16bit)
Prescale set @ 1:64 TIMER0 interrupt will fire 122 times a second (8bit) or once every 2 seconds (16bit)
Prescale set @ 1:128 TIMER0 interrupt will fire 61 times a second (8bit) or once every 4 seconds (16bit)
Prescale set @ 1:256 TIMER0 interrupt will fire 30 times a second (8bit) or once ever 8 seconds (16bit)
These are very rough calculations as I don't know how to include the remainder element of prescaling.
So looking back at my original requirement if I wanted to have the TIMER0 interrupt to fire 300 times, a prescaling value of 1:16 (488) comes closest to what I want? Is their a better way of doing this?
Mark