setting timer speed
- AndrewAPrice
- Member
- Posts: 2309
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
setting timer speed
I've been working on porting newlib lately that I've forgotten one important multitasking question. How do I set the rate at which the internal timer fires? I think 8ms/(12.5 times a second) is a good rate.
My OS is Perception.
Umm, 12.5 times a second would be 80ms, not 8ms.
Anyway.
The basic frequency is 1 193 182 Hz, you calculate the divider from this:
divider = 1193182 / desired_frequency_in_hz;
Then output 0x36 to PIT control port 0x43 to set the divider.
Output the least significant 8 bits to port 0x40, and
then the next 8 bits to the same port.
HTH
Anyway.
The basic frequency is 1 193 182 Hz, you calculate the divider from this:
divider = 1193182 / desired_frequency_in_hz;
Then output 0x36 to PIT control port 0x43 to set the divider.
Output the least significant 8 bits to port 0x40, and
then the next 8 bits to the same port.
HTH
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Try this:
In my OS I setup the timer to tick at 1000 Hz.
Code: Select all
/// Sets the clock rate, in hertz
void SetClockRate( short hz )
{
short divisor = 1193180 / hz; /* Calculate our divisor */
outportb(0x43, 0x36); /* Set our command byte 0x36 */
outportb(0x40, divisor & 0xFF); /* Set low byte of divisor */
outportb(0x40, divisor >> 8); /* Set high byte of divisor */
}
Last edited by pcmattman on Mon Sep 10, 2007 4:36 pm, edited 1 time in total.
- AndrewAPrice
- Member
- Posts: 2309
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Sorry. 125 times a second.Lode wrote:Umm, 12.5 times a second would be 80ms, not 8ms.
My OS is Perception.
Note that the divisor has a max length of 16 bits, which makes the minimum frequency 18.2Hz. See
<shameless plug>
http://www.jamesmolloy.co.uk/tutorial_h ... 20PIT.html
</shameless plug>
If you want a little more info / practical implementation.
JamesM
<shameless plug>
http://www.jamesmolloy.co.uk/tutorial_h ... 20PIT.html
</shameless plug>
If you want a little more info / practical implementation.
JamesM