Page 1 of 1

chThdSleepMicrosecond question

Posted: Fri Jul 01, 2011 3:30 am
by Saran_yim
Hi,

I do simple code in one thread just like this

palSetPad(GPIOB,0);
chThdSleepMicrosecond(50);
palClearPad(GPIOB,0);
chThdSleepMicrosecond(50);

but I cannot get 50 microsec delay but it is always 1 msec
I try with STM8S disocovery and STM32discovery board it is the same behavior.

So any way I can do?
Or I have to make my own delay function?

Thank you

Saran

Re: chThdSleepMicrosecond question

Posted: Fri Jul 01, 2011 7:33 am
by Giovanni
Hi,

The value is always rounded to the current system tick boundary, 1mS in most demos. If you need smaller delays then use the GPT driver, it includes a delay function capable of microseconds resolution (using an hardware timer).

Giovanni

Re: chThdSleepMicrosecond question

Posted: Fri Jul 01, 2011 10:00 am
by Saran_yim
stupid question what is GPT Driver?

Re: chThdSleepMicrosecond question

Posted: Fri Jul 01, 2011 10:16 am
by Giovanni
It is not a stupid question, I should have specified it.

GPT means General Purpose Timer, it is a new device driver model introduced in 2.3.2, it is not present in the stable version 2.2.x. This driver contains a function named gptPolledDelay() that can be used to introduce small polled delays in the code. An example of use of the GPT driver is present in the test application under ./testhal/STM32/GPT.

Giovanni

Re: chThdSleepMicrosecond question

Posted: Fri Jul 01, 2011 11:25 am
by Saran_yim
Thank you Sir.