Skip to content

Latest commit

 

History

History

hc-sr04

Sensor datasheet

  • Needs a 10uS pulse
  • Reading at 30Hz

Tricks

  • Useful stm32 timer formulas
  • Remember to start the timer
  • Using bypass clock at 8MHz coming from ST-Link board
  • Using TIM4, and CH3 and CH4 (for testing) for trigger
  • APBx clocks are at 96MHz
  • Prescaler at 50-1
  • Period at 64000-1
  • This gives a timer frequency of 30Hz
  • Pulse is set to 19200 giving a 10ms pulse on PD14
  • Using TIM4, CH1, PD12 for input capture, set to rising and falling edges
  • Using interrupts to calculate the period of the echo pulse and the related distance
  • Output (distance) is printed to USB configured as a virtual serial device