PIT

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
I...am your father!

PIT

Post by I...am your father! »

Hi!
I implementated a PIT to my OS, and I use this function:
void init_timer(unsigned char FREQ)
{
unsigned int counter=1193181/FREQ;
outportb(PIT_CTRL, 0x43);
outportb(PIT_CH_0, counter%0xFF);
outportb(PIT_CH_0, counter/256);
}

what is the exact value that the PIT activates 1000 times a second or how can I calculate this???? Or do I have to calibrate this?
Thanks...! ;)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:PIT

Post by Pype.Clicker »

well, just use a short instead of a char and ask for FREQ=1000 ... this will be the best the PIT can offer ...
Guest

Re:PIT

Post by Guest »

thank you! :D Ill try...


May the source be with you
Guest

Re:PIT

Post by Guest »

Great it works perfect, but on an emulator like bochs or vmWare the seconds are too long... This made me crazy because i thought it was my fault :P

Thank you very very much...... :-*
Dragon88

Re:PIT

Post by Dragon88 »

I would surmise that that is caused by bochs essentially being a comp inside a comp.
proxy

Re:PIT

Post by proxy »

i noticed a bug in your code :P
you use the modulus operator to get the low byte of the counter variables like this:

Code: Select all

outportb(PIT_CH_0, counter%0xFF);
this will yeild a value between 0 and 0xfe, skiping one value. incorrect.

you have two choices to fix this minor, which depend on your preference of style (compiler will likely emit same code for both).

Code: Select all

outportb(PIT_CH_0, counter%0x100);
or

Code: Select all

outportb(PIT_CH_0, counter&0xFF);
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:PIT

Post by Neo »

Guest wrote: Great it works perfect, but on an emulator like bochs or vmWare the seconds are too long... This made me crazy because i thought it was my fault :P

Thank you very very much...... :-*
In BOCHS 2.0.2 and above you can use this to get a better simulation of the PIT. add this line to your bochsrc file

Code: Select all

pit: realtime=1
Only Human
Post Reply