Page 1 of 1
Timer
Posted: Tue Jun 24, 2003 11:00 pm
by Boe
I'm make a multitasker, but i can't setup properly the system timer.
Can you help me?
RE:Timer
Posted: Wed Jun 25, 2003 11:00 pm
by Anton
Send the code witch you have at the moment. (When i read the refs on programing the timer, i had no problems.)
Anton.
RE:Timer
Posted: Wed Jun 25, 2003 11:00 pm
by gaffi
You'll have to reprogram the PIC.
Here's a very good step by step manual:
http://users.win.be/W0005997/GI/pic.html
--
gaffi
RE:Timer
Posted: Wed Jun 25, 2003 11:00 pm
by carbonBased
void timerSetFreq(short freq) {
long counter = PIT_FREQ / freq;
outportb(TIMER_CTRL, TIMER0 + TIMER_WHOLE + TIMER_MODE2);
outportb(TIMER0_CNTR, counter % 256); // send LSB
outportb(TIMER0_CNTR, counter / 256); // send MSB
return;
}
where:
freq = times/second for timer int to be called
TIMER_CTRL 0x43
TIMER_WHOLE (1 << 4) + (2 << 4)
ie: if you want to set just the LSB, send (1 << 4)
just the msb, send (2 << 4)
otherwise, send both
TIMER_MODE2 (2 << 1)
There are 5 modes, all (x << 1). See the docs for an explaination of
each. Mode 2 is most frequently used.
TIMER0_CNTR (0x40)
Of course, this only utilizes Timer0, there's also Timer1 and 2, but... this'll get you up and running (or at least, should)
Cheers,
Jeff
RE:Timer
Posted: Wed Jun 25, 2003 11:00 pm
by carbonBased
And, I forgot, PIT_FREQ is 0x1234DD. That's defined by the PIT hardware. Essentially, that's the numerator, and you supply the denominator for the timer hardware.
A denominator of 1 (the default, I believe) is the slowest, at 18.2 times per second (?), the higher the denominator, the faster the PIT ticks.
Cheers,
Jeff