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.

TMS570LS1224: ultrasonic hc sr-04 with tms570ls1224

Expert 1660 points

Part Number: TMS570LS1224

Hello everyone i want to connect ultrasonic hc sr-04 with tms570ls1224

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 0 , I changed the period to 10us and selected pin 10 as output pin, and enabled PWM SIGNAL AFTER HETINIT.   

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

how to edit my work to generate one pulse of trig and echo not a series of pluses?? because i still can't get the sensor data

 

#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;

}

}

  • Hello,

    I read the hc sr-04 document, the trigger is one 10us pulse. You can use N2HET[10] as GIO, and use the RTI timer to toggle N2HET[10].

    1. gioSetDirection(hetPORT1, (0x1 << 10));   //N2HET[10] as output

    2. rtiInit();  --> RTI compare 0 is configured to be 10us

        then enable RTI interrupt notification, and enable IRQ interrupt; 

        rtiEnableNotification(rtiNOTIFICATION_COMPARE0);

        _enable_IRQ();

       then start RTI counter

       rtiStartCounter(rtiCOUNTER_BLOCK0);

    2. gioSetBit(hetPORT1, 10, 1);   //pull N2HET[10] to high

    3. In RTI notification function, pull down N2HET[10]

    I don't know how hc sr-04 works if it receives a series of pulse (PWM signal). 

         

  • Hello QJ

    i wanna make sure if i understood you correctly.

    in halcougen

    i just enabled het1 ,rti and  GIO .

    i also enabled het1 in PINMUX

    then in HET1 in cap0 i changed the low polarity to high polarity and set pin 30 .

    then  In (pin 24-31) i select bit 30 as pullup.

    This is the code

    #include "sys_common.h"
    #include "gio.h"
    #include "rti.h"
    #include "het.h"
    
    
    hetSIGNAL_t  duration;
    
    float distance;
    
    
    void rtiEnableNotification(uint32 notification);
    
    
    int main(void)
    {
        hetInit();
        gioInit();
    
        gioSetDirection(hetPORT1, (0x1 << 10));   //N2HET[10] as output
        rtiInit();
    
        while (1)
        {
            rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
            _enable_IRQ();
    
            rtiStartCounter(rtiCOUNTER_BLOCK0);
    
            gioSetBit(hetPORT1, 10, 1);   //pull N2HET[10] to high
    rtiEnableNotification(rtiNOTIFICATION_COMPARE0);

    capGetSignal(hetRAM1,cap0, &duration); distance =( duration.period * 0.034) / 2; } } void rtiEnableNotification(uint32 notification) { gioSetBit(hetPORT1, 10, 0); //pull N2HET[10] to low }

  • This is just my comments:
    1. use N2HET[10] as trigger. This pin should not be used for other purpose (PWM, edge detection, and capture)
    2. use N2HET[20] or other N2HET pin for edge detection, and enable edge interrupt for both edges. 
     
    When debugging your code, please probe the trigger signal and coming signal. If the coming signal is always LOW, the sensor is not triggered
     
    N2HET[10] is used to trigger the sensor:
    void rtiEnableNotification(uint32 notification)
    {
        gioSetBit(hetPORT1, 10, 0);   //pull N2HET[10] to low
           
            flag= 0x55AA;
    }
    void void edgeNotification(hetBASE_t * hetREG,uint32 edge)
    {
         if (first_edge == 1){           //first  edge is the rising edge of coming signal, and the 2nd edge should be the falling edge 
             t1 = edgeGetCounter(hetRAM1, edge);  
             first_edge=0;
          }else{
             t2 = edgeGetCounter(hetRAM1, edge);  
          }

    }

     
    }
    //N2HET[20] is used to capture the edge (both edge: falling and rising) of the input: 
    unsigned int first_edge, t1, t2;
    int main(void)
    {
            first_edge=1, t1=0, t2=0;
        hetInit();
        gioInit();
        gioSetDirection(hetPORT1, (0x1 << 10));   //N2HET[10] as output
        rtiInit();
        _enable_IRQ();
        rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
        gioSetBit(hetPORT1, 10, 1);   //pull N2HET[10] to high

        rtiStartCounter(rtiCOUNTER_BLOCK0);

            if (flag == 0x55AA){
                rtiStartCounter(rtiCOUNTER_BLOCK0);  
            }
        duration = t2 - t1;
    }