Hello everyone is there any examples on implementing ultrasonic hc sr-04 with tms570ls1224
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello everyone is there any examples on implementing ultrasonic hc sr-04 with tms570ls1224
Hello,
You can use either N2HET or ePWM or GIO to generate a 10us trigger pulse for HC-SR04, and use GIO or eCAP or N2HET to capture the rising and falling edge of the echo output from the HC-SR04. RTI can be used as the timer which counts the time between the rising edge and falling edge of the echo input signal.
I don't have examples, but it is not hard to implement.
hello QJ,
i connected N2HET1[10] to the sensor trig
and N2HET1[30] to the sensor echo.
in halcougen i just enabled het1 and GIO .
i also enabled het1 in PINMUX
and then went to het 1 (pwm 0-7) in PWM 1 , I changed the period to 10us and selected pin 10 as output pin, and enabled PWM SIGNAL AFTER HETINIT. in here do i need to change the duty cycle????
then in cap0 i changed the low polarity to high polarity and set pin 30 .
then i went to (pin 8-15) and enabled output direction for bit 10 . In (pin 24-31) i select bit 30 as pullup
about the code
#include "het.h"
#include "sys_common.h"
#include "gio.h"
hetSIGNAL_t duration;
float distance;
void main(void)
{
while(1){
hetInit();
gioInit();
gioSetDirection(hetPORT1, 0xBFFFFFFF); // 30 Input, 10 Output
gioSetBit(hetPORT1, 10, 1);
pwmSetDuty(hetRAM1, pwm0, 10U);
pwmStart(hetRAM1, pwm0);
capGetSignal(hetRAM1,cap0, &duration);
distance =( duration.period * 0.034) / 2;
}
}
Please see my reply: