Page 1 of 1

Question about the JMolloy PIT Code

Posted: Thu Jun 26, 2014 3:36 am
by Primis
While I was reading up on the 8254 PIT chip, I had thought it wise to make a header with all the bitmaps for the different parts of the command, that way I could make a really clear init function with somthing along the lines of:

Code: Select all

outb(PIT_CMD, PIT_CHANNEL_0 | PIT_LHBYTE | PIT_MODE_2 | PIT_BIN_MODE);
Now here's where it gets interesting. While I was doing this, I had been looking at the last time I had implemented this feature, which was a blind copy from James Molloy's Kerenl tutorial about 3 years ago. I had noticed that my old code looked like this:

Code: Select all

outb(0x43, 0x36);
Now, upon looking up the bitmap of that code against my newly made header defines, I noticed somthing that didn't add up; The old code was using a the square wave mode (Mode 3), not the rate generator mode (Mode 2). Now upon further investigation, I had noticed this is the same in both James' code, and in it's inspiration bkerndev. Am I missing somthing blaringly obvious here? Is that a typo in their code? Is there one on the wiki? Would this work regardless due to rising edge interrupts on the pic? If someone could shed some light on this, I would be very grateful.

Re: Question about the JMolloy PIT Code

Posted: Mon Feb 16, 2015 10:51 am
by Techel
Both modes 2 and 3 can be used to achieve periodic timer interrupts

Re: Question about the JMolloy PIT Code

Posted: Mon Feb 16, 2015 4:59 pm
by Brendan
Hi,
Primis wrote:Would this work regardless due to rising edge interrupts on the pic?
Yes.

The only difference would be with odd counts. For example, if you try to use count = 1111 then with rate generator you'd get an IRQ every 1111 ticks, and with square wave you'd get an IRQ after 110 ticks then one after 112 ticks then 110 ticks then 112 ticks...


Cheers,

Brendan