PIT Timing

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
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

PIT Timing

Post by brodeur235 »

I'm not sure what's wrong, because I've debugged my code, and it does exactly what I ask it to. Here is the code I used to set the PIT frequency:

Code: Select all

	; make sure frequency is 1 word max
	and FREQ,0xFFFF
	
	; divide 1193180 (0x1234DC) by frequecy to get divisor to send to PIT ( dx:ax / bx = ax remainder dx )
	xor eax,eax
	xor edx,edx
	mov dx,0x0012
	mov ax,0x34DC
	mov ebx,FREQ
	div bx
	
	; save result
	push eax
	
	; tell the PIT we are about to send it a frequency divisor
	mov al,0x36
	out PIT_CMMD,al
	
	; restore result
	pop eax
	
	; send low and high bytes of divisor (respectively) to PIT
	out PIT_DAT1,al
	shr ax,0x0008
	out PIT_DAT1,al
FREQ is a double word in memory. It's value IS 100, just as I specified it to be in earlier code. I have verified this with much debugging. Also, the value I send to the PIT as a divisor is: 0x2E9B, which seems to be exactly correct. Okay... Now to the problem: Now that I've set the PIT frequency to 100, if I set up the ISR that handles IRQ 0 to ouput something whenever the PIT is divisible by 100, it goes way too fast. To get the ISR that handles IRQ 0 to output something approximately once every second, I have to output every time the PIT is divisble by 1825. This is WAY off... it should be 100, not 1825... Any suggestions as to why this is happening?

Brodeur235
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: PIT Timing

Post by Combuster »

Are you using bochs? if so, configure it properly (using the realtime or slowdown clock)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

Re: PIT Timing

Post by brodeur235 »

Are you using bochs? if so, configure it properly (using the realtime or slowdown clock)
Combuster, you are exactly right. Seems I was stressing over nothing. Thanks for your help,

Brodeur235
Post Reply