Page 1 of 1

PIT

Posted: Tue Feb 03, 2004 1:27 pm
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...! ;)

Re:PIT

Posted: Tue Feb 03, 2004 1:49 pm
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 ...

Re:PIT

Posted: Tue Feb 03, 2004 2:05 pm
by Guest
thank you! :D Ill try...


May the source be with you

Re:PIT

Posted: Tue Feb 03, 2004 2:14 pm
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...... :-*

Re:PIT

Posted: Mon Mar 22, 2004 5:25 pm
by Dragon88
I would surmise that that is caused by bochs essentially being a comp inside a comp.

Re:PIT

Posted: Tue Mar 23, 2004 6:00 am
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);

Re:PIT

Posted: Wed Mar 24, 2004 11:54 am
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