timer irq
Posted: Thu Jun 24, 2004 5:02 pm
i'm trying to setup a timer using irq line 0. I remapped the IRQ's to 0x20 and 0x28. what would the best way of doing this be? thanks
This depends what you intend using the timer for. Some OS's use it to increase a system timer, for e.g. it could be used to increment a counter 1000 times per second. Then the OS would use this counter for delay loops and timing.northfuse wrote: i'm trying to setup a timer using irq line 0. I remapped the IRQ's to 0x20 and 0x28. what would the best way of doing this be? thanks
Code: Select all
overhead = (IRQspeed*frequency) / CPUspeed
accuracy = 1/frequency
Where,
overhead = the amount of CPU time spent handling the timer IRQ
accuracy = the maximum amount of error the value in the counter may be
CPUspeed = the number of cycles the CPU can execute in a second (on average)
IRQspeed = the number of cycles executed to handle the IRQ
frequency = the frequency of the timer
Code: Select all
overhead = (100*10000000) / 100000000 = 1 (or 100% of CPU time spent handling the timer IRQ)
Code: Select all
overhead = (100*10000000) / 3000000000 = 0.03333 (or 3% of CPU time spent handling the timer IRQ)
Code: Select all
frequency = (overhead*CPUspeed) / IRQspeed
Code: Select all
frequency = 0.01 * CPUspeed / 100 = CPUspeed / 10000
..and therefore:
accuracy = 10000 / CPUspeed
Unmasking IRQ0 in the PIC is easy...northfuse wrote: thanks for the insight. But, right now, i'm trying to figure out how to setup the code in the idt and unmask the interrupt. I'm pretty sure that I installed it right in the idt, but i don't know how to unmask the interrupt to allow it to fire interrupt requests.
Code: Select all
%define PIC1 0x20
%define PIC2 0xa0
in al,PIC1+1
and al,11111110b
out PIC1+1,al
You'd need to set the timer mode and it's frequency. Here's some basic code:northfuse wrote: Thanks! it works. how would i go about reprogramming it to a different frequency (i.e. 100 Hz instead of 18.6 Hz)? or, if there is any documentation that you know of, that would be a help too. thanks again
Code: Select all
%define PITchnl0 0x40
%define PITcntrl 0x43
mov al,0x34 ;Init timer 0 using mode 2
out PITcntrl,al
mov bx,[divisor]
mov al,bl ;Set the PIT channel 0 frequency
out PITchnl0,al
mov al,bh
out PITchnl0,al
Code: Select all
%define PITchnl0 0x40
%define PITcntrl 0x43
mov al,0x34 ;Init timer 0 using mode 2
out PITcntrl,al
mov al,(11932 & 0xFF) ;Set the PIT channel 0 frequency to about 100 Hz
out PITchnl0,al
mov al,(11932 >> 8)
out PITchnl0,al