First of all here is my working conditions:
ChibiOS version 3.3
Board: STM32F401RE-Nucleo.
My goal:
I want to generate a pulse of 10us width for a distance sensor(srf04) so that I can read the distance every half second for example.
What I did:
Create a thread to generate the pulse(10us) every 500ms
My code:
Code: Select all
63 /*
64 * HC-SR04 Trigger thread
65 */
66 static THD_WORKING_AREA(waThread2, 128);
67 static THD_FUNCTION(Thread2, arg){
68 (void)arg;
69
70 chRegSetThreadName("trigger");
71
72 while(true){
73 palSetPad(TRIGGER_PORT, TRIGGER_PIN);
74 chThdSleepMicroseconds(10);
75 palClearPad(TRIGGER_PORT, TRIGGER_PIN);
76 chThdSleepMilliseconds(500);
77 }
78 }
The result:
I can read the distance with the sensor but my trigger signal ( the pulse of 10us) is larger than 10us. The measure with an oscilloscope, gave me 200us.
Is it really the right method to generate a pulse width on a thread?
Is there another way to generate that signal for example by using timers?
Why did the function chThdSleepMicrosecond don't give me the right width?
Thanks you for your help
Theo.