First of all, I am beginner with RTOS and FreeRTOS.
I am working in a proyect with a ultrasonic sensor HC-SR04 but I am not sure how to face it.
I want measure a obstacule distance with this sensor and if this distance is less than x cms then stop my rover.
First of all, I think use a software timer for schedule the execution of my measure function. This function will set a HIGH level pulse in the trigger pin of HC-SR04. Then I have to wait to a HIGH level on echo pin and measure the time in HIGH level. Here is my problem how to manage to measure it, do I need a Interruption when detect the LOW to HIGH level change on echo input, do I need another interruption for HIGH to LOW level change? How to link it togegher and measure this time? Any clue?
I imagine the time between the high level pulse on the output pin and
the high level pulse on the input pin will be extremely short – even in
the worst case scenario – in which case it is probably best measured by
some form of capture mode in the hardware. Otherwise, if the assumption
that it is very short is correct, then just polling the input would
probably give you the best accuracy provided no [other] interrupts or
other tasks executed while you are polling.
The main issue is because I have to keep 10 microsecons pulse in the trigger output and I don’t know how to face this in freeRTOS.
This scale of pulse control/measurement tends to be best done with hardware, not software, and especially not software trying to do something else at the same time.
Many processors designed for this sort of application have ways to configure some pins to generate precisely controlled pulses, and measure pulse timing to near processor clock resolution. This is the sort of thing I would use for this type of application.