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.

CCS/TM4C1294NCPDT: HC - SR04 MEASURING DISTANCE PROBLEM

deleted

  • First, have you looked at the output of the HC-SR04 and verified that you are triggering it and getting a proper response?

    (Correction from original post. The time to measure is from trigger to echo, not length of echo signal.)

    The value captured in timer0 is the time in uS. (16MHz with a /16 prescale.) Divide that number by 58 to get the distance in cm. Use floats instead of integers if you want more resolution.


    Make sure that you protect the timer input capture pin PL4. The HC-SR04 is a 5V device and the TM4C1294N has 3.3V I/O. A 1K Ohm resistor in series should limit the current sufficiently.