chThdSleepMicroseconds or GPT or VT timer

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

chThdSleepMicroseconds or GPT or VT timer

Post by ep.hobbyiest »

Hi,

I am using ultrasonic sensor (hc-sr04).
I read some threads about creating 10us timing.
chThdSleepMicroseconds - won't create accurate 10us(+/-3 us)
GPT - can create 10us delay

But here i don't have spare GPT timer to use :( . can i use VT timer instead. What will be accuracy.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleepMicroseconds or GPT or VT timer

Post by Giovanni »

Hi,

chThdSleepMicroseconds uses virtual timers internally, it is the same thing. Note that anything based on interrupts will not allow an accuracy of +-3uS because of jitter.

You need to use an HW timer with IRQ priority set to zero, something that the HAL does not allow. Those "fast" interrupts have much reduced jitter but you can't call any OS function from the IRQ handler.

Giovanni
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: chThdSleepMicroseconds or GPT or VT timer

Post by ep.hobbyiest »

Then instead of using timer can I use pwm?
I am thinking to start PWM for one pulse 10us only and later stop the PWM. Because that would be precise than timer. I can spare one time for that.
Is that possible?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleepMicroseconds or GPT or VT timer

Post by Giovanni »

Hi,

Yes, it is possible.

Giovanni
Post Reply