PIT frequency problem

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
chosen_1
Posts:2
Joined:Tue Dec 28, 2010 12:34 am
PIT frequency problem

Post by chosen_1 » Tue Dec 28, 2010 12:50 am

Hi everyone,

I am following the tutorials and they are very nice.
Currently I am busy with nr. 16 about the PIC and the PIT.

The problem i encounter is that tick counter won't run with the frequency i want.
in the demo, if I change te folowing line:

Code: Select all

i86_pit_start_counter (100,I86_PIT_OCW_COUNTER_0, I86_PIT_OCW_MODE_SQUAREWAVEGEN);

into:

Code: Select all

i86_pit_start_counter (1,I86_PIT_OCW_COUNTER_0, I86_PIT_OCW_MODE_SQUAREWAVEGEN);

the counter still counts with a frequency of 100Hz instead of 1Hz.

I am running the code with Bochs.

What am i doing wrong?

Hoozim
Posts:34
Joined:Sun Nov 21, 2010 6:40 pm

Re: PIT frequency problem

Post by Hoozim » Tue Dec 28, 2010 2:28 am

I am not very familiar with Bochs (I use an actual computer for testing) but it may be that the emulated timer is limited to 100hz. Remember that the processor is time-multiplexed so Bochs only has a small fraction of the total processor time. The timer could be limited because of that and only recieves 100hz. If you have a physical maching available, try the code on that and see what happens.

If you post the method you are using, maybe I could debug it for you (if that is the problem).

I could also post my method if you want to see it, it works perfectly fine at 1hz even though I run it at 10hz to keep the processor free for the main kernel.

Good luck, Hoozim

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: PIT frequency problem

Post by Andyhhp » Tue Dec 28, 2010 3:46 am

@Hoozim: Bochs uses virtual time so timeslices are not relevent to the problem. Also, your logic would make a 1Hz signal more likely to occur than a 100Hz signal

@chosen_1: This is due to a limitation of the PIT hardware, you cant get a frequency less than 16 Hz. See http://wiki.osdev.org/PIT for more information.

~Andrew
Image

chosen_1
Posts:2
Joined:Tue Dec 28, 2010 12:34 am

Re: PIT frequency problem

Post by chosen_1 » Tue Dec 28, 2010 3:30 pm

Thanks for your replays.

But also if i set a frequency of 1000 Hz, the counter will only count with about 100 counts/sec.

The method I use is the demo code of tutorial 16:

Code: Select all

//! starts a counter
void i86_pit_start_counter (uint32_t freq, uint8_t counter, uint8_t mode) {

	if (freq==0)
		return;

	uint16_t divisor = uint16_t(1193181 / (uint16_t)freq);

	//! send operational command
	uint8_t ocw=0;
	ocw = (ocw & ~I86_PIT_OCW_MASK_MODE) | mode;
	ocw = (ocw & ~I86_PIT_OCW_MASK_RL) | I86_PIT_OCW_RL_DATA;
	ocw = (ocw & ~I86_PIT_OCW_MASK_COUNTER) | counter;
	i86_pit_send_command (ocw);

	//! set frequency rate
	i86_pit_send_data (divisor & 0xff, 0);
	i86_pit_send_data ((divisor >> 8) & 0xff, 0);

	//! reset tick count
	_pit_ticks=0;
}

Edit:
For some kind of reason it is working fine now, Maybe i made a mistake with renaming the kernel file the demo outputs. (I am using another extention in my bootloader). Thanks for your help.

Hoozim
Posts:34
Joined:Sun Nov 21, 2010 6:40 pm

Re: PIT frequency problem

Post by Hoozim » Tue Dec 28, 2010 3:42 pm

The hardware is limited. I completely forgot about that. I checked and my code runs at 100hz and works at 1000hz fine. I got the numbers backwards.

Hoozim
Posts:34
Joined:Sun Nov 21, 2010 6:40 pm

Re: PIT frequency problem

Post by Hoozim » Tue Dec 28, 2010 3:44 pm

I was for some reason thinking that 1hz was faster than 100hz.

Post Reply