Hi again,
What speed does irq 0 run at, how do I adjust its speed, can someone provide an example or a link to some docs.
Thanks.
What speed does the System Timer (IRQ0) Run At?
Re:What speed does the System Timer (IRQ0) Run At?
18.2 hz is the default.
Will give you approx 100hz (99.97 in reality) running as a square wave.
Curufir
Code: Select all
mov al,0x76
out 0x43, al
mov al, 0x9b
out 0x40, al
mov al, 0x2E
out 0x40, al
Curufir
Re:What speed does the System Timer (IRQ0) Run At?
Thankyou very much, would it be possible to get some explanation about the code, I would like to understand it rather just plug it into my OS.
I understand the ASM, but more about what ports these are? Why we send these values? etc...
thanks alot.
I understand the ASM, but more about what ports these are? Why we send these values? etc...
thanks alot.
Re:What speed does the System Timer (IRQ0) Run At?
Well I'm not gonna explain the first port operation. Mainly because there's 6 different modes of operation and 3 different timers on an 8254 chip. Let's just call it a command byte, you can look up the details yourself.
Ok, maybe just a little explanation
0x43 is the command port for the PIT. I send 01110110b to the port. This means: Use counter 1, read least significant byte and most significant byte, use mode 3 (Squarewave). Hopefully this demonstrates why I'm not running through the entire range of modes you can use the PIT in.
What I will do is explain the second part.
This loads the least, and most, significant byte of the value which the counter is to be loaded with.
Ok, what does that mean?
Simple. I'll explain as if there was only one timer (The other two use the same logic).
The timer's counter is loaded with a value (In the example this is the decimal 11, 931, ie 0x2e9b). The PIT itself is connected to a base clock that cycles at 1.19318 MHz. In this mode (Ie square wave) every time this base clock cycles the counter is decremented until it reaches zero. Once it reaches zero the IRQ 0 interrupt happens.
So in my example the interrupt gets called once every 1.19318Mhz/11931 = 100 Hz give or take a fraction.
As I said, I'm not going to go into the different modes of operation, but if you want things like variable timeslices etc then you'll want to use something other than the square wave generator. There's plenty of docs out there, it shouldn't be too hard to figure out which one you need.
Just a word of warning, apparently counter 1 is also used to tell the motherboard to refresh the ram, so I'd imagine if you set it too low odd things will happen.
Hope that helps.
Curufir
Ok, maybe just a little explanation
0x43 is the command port for the PIT. I send 01110110b to the port. This means: Use counter 1, read least significant byte and most significant byte, use mode 3 (Squarewave). Hopefully this demonstrates why I'm not running through the entire range of modes you can use the PIT in.
What I will do is explain the second part.
Code: Select all
mov al, 0x9b
out 0x40, al
mov al, 0x2E
out 0x40, al
Ok, what does that mean?
Simple. I'll explain as if there was only one timer (The other two use the same logic).
The timer's counter is loaded with a value (In the example this is the decimal 11, 931, ie 0x2e9b). The PIT itself is connected to a base clock that cycles at 1.19318 MHz. In this mode (Ie square wave) every time this base clock cycles the counter is decremented until it reaches zero. Once it reaches zero the IRQ 0 interrupt happens.
So in my example the interrupt gets called once every 1.19318Mhz/11931 = 100 Hz give or take a fraction.
As I said, I'm not going to go into the different modes of operation, but if you want things like variable timeslices etc then you'll want to use something other than the square wave generator. There's plenty of docs out there, it shouldn't be too hard to figure out which one you need.
Just a word of warning, apparently counter 1 is also used to tell the motherboard to refresh the ram, so I'd imagine if you set it too low odd things will happen.
Hope that helps.
Curufir