Timer

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
Boe

Timer

Post by Boe »

I'm make a multitasker, but i can't setup properly the system timer.
Can you help me?
Anton

RE:Timer

Post 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.
gaffi

RE:Timer

Post 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
carbonBased

RE:Timer

Post 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
carbonBased

RE:Timer

Post 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
Post Reply