Add Ultrasonic Distance Sensor to S5D9 IOT board.
Learn to connect the 5V popular distance sensor to the 3.3V S5D9 IOT board.
Use one shot timer to generate the trigger pulse to start sensing.
Use timer and input interrupt to measure the return echo pulse from the sensor.
Diagram 1: Connect 4 pins (VCC, TRIG, ECHO, GND) to PMOD header.
Diagram 2: S5D9 generates the tigger pulse (Yellow Signal). Then the sensor sends back the echo pulse (Blue Signal) and the time width of the pulse can be converted to the measured distance.
1. Renesas E2 Studio Tool version 5.4.0.023
2. Renesas SSP version 1.30
3. S5D9 IOT ENABLER pack file
1.The Jlink debugger board (included in S3A7 kit or purchase from SeeedStudio)
2. HC SR04 Ultrasonic Distance Sensor (range 2cm-400cm)
3. S5D9 IoT board
Diagram 3: J6 jumper should be shorted such that it supplies 5V to the sensor.
Diagram 4: S5D9 Datasheet shows that P2_5 can tolerate a maximum voltage of 5.5V.
1. E2 Studio Installation. For this tutorial, use E2 Studio version 5.4.0.023 and SSP version1.30. (IOT Community page)
2. Blinkey Example with E2 Studio and Jlink Flash (IOT Community) - Need to know how to configure pins/thread.
3. Simple C language coding skill.
Software Configuration in E2 Studio
1. Configure 32 bit GPT Timer is set to generate the short trigger pulse and is used to measure the long return echo pulse.
2. Configure P205 input trigger driver for both rising and falling edge detection. So, the timer counter value at the start and end of the echo pulse can be recorded to determine the time delay of the pulse.
Non-RTOS Version : hal_entry.c, sensor_hc_sr04.c/h
RTOS Version : hal_entry.c (empty function), system_thread_entry (empty function), distance_sensor_thread_entry, sensor_hc_sr04.c/h
Run both code in debug mode. Break point at the line where distance is returned from the subroutine. You will get the value.
distance = hc_sr04_get_distance(); // Non-RTOS version. This line is in hal_entry.c
distance = hc_sr04_get_distance(); //RTOS version. This line is in distance_sensor_thread_entry.c
What to get from this tutorial?
1. Learn both non-RTOS and RTOS versions.
2. Learn to read data sheet for 5V tolerance port pins.
3. Use SSP Documents to learn about the GPT timer API calls.
4. C/C++ Optimization level (-00) in e2 studio. It can make debugging possible.
Step 1: Right click the project --> choose Properties
Step 2: Choose None (-00) and then later choose -02 when the code is bug free.
5. Endorse DSO (ie Digilent Analog Discovery with bus protocol recognition capability)
6. C keyword Volatile (very important to global variable or flag set/clear by ISR function or another RTOS thread).
volatile bool g_timerdone;
7. Show how to make include statement correctly for your .h/.c files for both non-RTOS and RTOS versions.
After downloading the project file, use import function in e2 Studio to stream the project into your workspace directory.