dongseop 0 Posted December 3, 2014 Share Posted December 3, 2014 Hello Stellaris Community. This is my first post up in this community. I will be very grateful if you give me some advice. I am not sure if it is okay to post this subject in this forum. I am using lm3s8962 board and Stellarisware 10636 library. HC-SR04 is a distance finder. I have been working on hc-sr04 devices for a long time. I really don't know why the result I get keeps unreliable. I may have a lot of questions. But I start by a question I am not sure of. First of all, I am aware of the device requirement. Those are the requirements of the datasheet hc-sr04. Working Voltage DC 5 V Working Current 15mA Working Frequency 40Hz http://www.micropik.com/PDF/HCSR04.pdf In order to work the device, I need to trigger at least 10uS high pulse to the trigger pin of the device. My question comes here. As the datasheet says, my mcu creates 3.3v GPIO pulse, and it provides up to 25mA current. Do you think triggering the 5.0V device with 3.3V gpio high pulse may not work well? This one can be a cause to affect the accuracy? I would appreciate your help. Dongseop Quote Link to post Share on other sites
flek12345 0 Posted December 3, 2014 Share Posted December 3, 2014 Well... I think I am using similar configuration. I connected: HC-SR04 pin named "Vcc" to Stellaris board pin named "VBUS" HC-SR04 pin named "Trig" to Stellaris board pin named "PE4" HC-SR04 pin named "Echo" to Stellaris board pin named "PF4" HC-SR04 pin named "Gnd" to Stellaris board pin named "GND" And it works... I think, GPIO E4 has level of 3.3V. And it seems is enough to trigger measurement. Also, "Echo" is correctly recognized on pin F4. It seems 5.0 V it is not too much for GPIO. I am also novice in this area. Maybe some expert should give us advice (comment). Quote Link to post Share on other sites
dongseop 0 Posted December 3, 2014 Author Share Posted December 3, 2014 I think when you take 5 voltage to 3.3 GPIO input, your device may be affected. You may need to add a resistor before 5 volts comes to your 3.3 GPIO. Quote Link to post Share on other sites
abecedarian 330 Posted December 4, 2014 Share Posted December 4, 2014 LM3S8962 is 5v0 tolerant on GPIO only if the processor pin is configured as an input, so the "ECHO" pulse is okay. A small current-limit resistor may be a good idea though. HC-SR04 logic levels are TTL, so any signal between GND and 0.8v is considered logic "LOW"; any signal above 2.2v to VCC is considered logic "HIGH". Therefore, driving the "TRIG" signal with 3v3 falls within the level requirements for the device. dongseop 1 Quote Link to post Share on other sites
dongseop 0 Posted December 12, 2014 Author Share Posted December 12, 2014 thanks for reply. The HC-SR04 module send out an 8 cylcle burst of ultrasound at 40kHz and raise its echo. I set my board's system clock as 50 mHz and calculate the pulse width from the echo pin of the hc-sr04. Do you think I need to change my board's system clock same as the system clock of the hc-sr04 module? Do I need to compensate the pulse width because I get the 40kHZ pulse? As I look at the datasheet, there is no specification which system clocks hc-sr04 use. I am guessing maybe this module is only made for Arduino. I found many references working the module with Arduino but Arm board. Quote Link to post Share on other sites
Kartman 0 Posted December 14, 2014 Share Posted December 14, 2014 The operation is the same regardless of what processor is used. Those ultrasonic modules have been around well before the Arduino. Basically you give the module a 10uS pulse to send the ping then measure the time for the return. The arduino code should work in energia. dongseop 1 Quote Link to post Share on other sites
dongseop 0 Posted December 15, 2014 Author Share Posted December 15, 2014 thanks for reply Kartman As the processor doesn't matter with the measurement, I have really no idea why I get the unreliable results. To trigger the device, as the datasheet recommends, I use a pwm signal with 60 ms period and its duty cycle corresponds to 10uS high pulse. Do you think it is not appropriate to trigger the device with a pwm signal? maybe when calculating the pulse width, pwm should not trigger the device. I am using code composer studio v6 and stellaris library. My target is lm3s8962. I appreciate your help. Quote Link to post Share on other sites
Kartman 0 Posted December 16, 2014 Share Posted December 16, 2014 I wouldn't use pwm. What does 60ms work out as distance? Also, if you're calculating whilst measuring distance then you may have the problems you describe unless you've taken steps to ensure the current measurement doesn't affect the calculation of the previous measurement. dongseop 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.