SOCIALS 

SUBSCRIBE 

 Please subscribe.   So, you will get notification of the latest exciting posts. 

© 2023 by FEEDs & GRIDs. Proudly created with Wix.com

ABOUT FEEDs & GRIDs

My name is Mike.   This blog is made especially for you to enter my technology universe.  You will find new ideas and skills that may be helpful to you.   Feel free to leave your comments.   I am excited to hear from you.  Thank you. 

Add Ultrasonic Distance Sensor to S5D9 IOT board.

February 22, 2018

Project Goals

  • 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.

 

 

Software

 

1. Renesas E2 Studio Tool version 5.4.0.023

2. Renesas SSP version 1.30

3. S5D9 IOT ENABLER pack file

 

 

Hardware

 

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.

 

 

Prerequisites

 

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. 

 

 

Code: 

 

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

 

 

Testing: 

 

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.

 

Download

 

After downloading the project file, use import function in e2 Studio to stream the project into your workspace directory.

 

 

https://github.com/mikelisfbay/Renesas_s5d9_hc_sr04_ultrasonic_distance_sensor

 

 

Tags:

Share on Facebook
Share on Twitter
Please reload

RECENT POSTS

Please reload

FEATURED POSTS

I2C Tutorial for Renesas S5D9 board: Add ThreadX real time OS support. (Part 3)

February 18, 2018

1/5
Please reload

FOLLOW US

  • Grey Facebook Icon
  • Grey Twitter Icon
  • Grey Instagram Icon
  • Grey Google+ Icon
  • Grey Pinterest Icon
This site was designed with the
.com
website builder. Create your website today.
Start Now