timer0, timer1

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
Adek336

timer0, timer1

Post by Adek336 »

Hi all!

Is there a way to get two independent timers running? That is IRQ0 and some other one.

Cheers and thanx in advance,
Adrian
CodeSlasher

RE:timer0, timer1

Post by CodeSlasher »

yeah, there are 3 timers (standard) in a pc. timer0 it the RTC, timer 1 is used to refresh memory and timer 2 is used for the pc speaker/cassette drive (correct me if i'm wrong :) ) well, timer 1 can't (shouldn't) be used else the pc will start behaving strangely. What you can do is use timer 2 as an alternative timer. You program it the same way as timer 0 but instead of setting it to reload it's count value after each interrupt, you could program it to fire once and then you could you it as a kind of alarm or event timer. Or you could use the extra timers in CMOS , think they are the periodic,alarm etc cant remember their names right now.
hope this helps
Adek336

RE:timer0, timer1

Post by Adek336 »

which irq does timer2 trigger? is it IRQ0? is it possible to say which timer happened? but timer1 doesn´t seem to trigger IRQ0, so perhaps its something else?

thanx,
Adrian
Stefan

RE:timer0, timer1

Post by Stefan »

pic0 timer0 => IRQ0
pic0 timer1 => unused (used to be DRAM refresh, leave it alone for compatability)
pic0 timer2 => Speaker (can be turned of at 61h, then can be used as count down)

pic1 timer3 => NMI (int 2) pin (watchdog)
pic1 timer4, 5 => dont remember

rtc periodic => IRQ8, freq in [8192Hz 4096Hz 2048Hz 1024Hz 512Hz etc]
rtc update-ended => IRQ8, 1Hz
rtc alarm => when H:M:S match up, eg *:*:20 gives 1/minute

Check RBIL.
CodeSlasher

RE:timer0, timer1

Post by CodeSlasher »

timer 2 uses int 0X1C,i think. a way to find out which int belong to a timer could be to write custome int handler ie
_int_0x01:
           lea si,[int_0x01_message]
           call print_string
           jmp $
_int_0x02:
           lea si,[int_0x02_message]
           call print_string
           jmp $

int_0x01_message db 'Int 0x01 just fired',0
int_0x02_message db 'Int 0x02 just fired',0
.....
.....

for all 256 entries in the IDT. Then program just the single timer you are trying to determine its INT number. Once the timer goes off the corresponding ISR will be called and you will know which number belongs to that timer.
hope this helps
            
Xenos

RE:timer0, timer1

Post by Xenos »

Normally, int 0x1C is called by the IRQ0 handler and allows users to place their timer routines without affecting system timings (floppy motor etc.)...

If you set timer2 to mode 0 (interrupt on terminal count), it will generate IRQ0. To find out, which timer has fired the interrupt, just read the timer value - it should be 0. This is a trick used to play 8bit samples...
Adek336

RE:timer0, timer1

Post by Adek336 »

Thank you all! Unfortunately Im still not able to enable timer2.

outportb(0x43, 48 + 128);
outportb(0x42, 0x20);
outpotrb(0x42, 0x20);  // this should enable timer2, binary, mode 0 - interrupt on terminal count, lsb and msb

unsigned long;
void timer()
{
   l++;
   printf("%d", l);
   asm volatile ("leave\niret");
}

i get 18 ticks per second, so it must be timer0 (also initialized). but there should be extra ticks related to timer2.

Cheers and thank you all,
Adrian
gaffi

RE:timer0, timer1

Post by gaffi »

Hi,
why don't you use some software timers? Therefore you'll have to set the (standard) timer to a small value (1KHZ?) and keep a list with your timer's counters. Decrement all couners every time IRQ0 is called.

counterA dd   10 ; 100 Hz
counterB dd  100 ;  10 Hz
counterC dd 1000 ;   1 Hz

IRQ0:
mov eax,[counterA]
dec eax
cmp eax,0
je alarmA
mov [counterA],eax

alarmA:
; do whatever you want to do, then reset the counter

...


Daniel Raffler
Xenos

RE:timer0, timer1

Post by Xenos »

It would be interesting to figure out if the timer is running at all. If you switch the speaker on, you should here something if the timer is operating.
Post Reply