Trouble Generating a 10 µs Trigger Pulse for HC-SR04 Using STM32 Timer Block in Simulink
Show older comments
Hi, I am trying to generate a 10 µs trigger pulse for the HC-SR04 ultrasonic sensor using a Timer block in Simulink on an STMF411RE. However, the trigger signal is not working as expected
Below is my current model setup:
- I read the TIM3 CNT value using the STM32 Timer block.
- I compare CNT > 10 using a Switch block to create the 10 µs HIGH pulse.
- The output is connected to GPIOB Pin 4 configured as the Trigger pin.
However, when I run the model on hardware, the Trigger output stays HIGH continuously instead of generating a 10 µs pulse.
In the Simulation Data Inspector, the timer counter appears to be working, but the Switch output remains at 1 all the time
Block Diagram :

Data Inspector :

Scope :

Although the Timer Counter block and Switch block behave exactly as expected in the Simulink simulation, the output on the hardware does not generate the correct trigger pulse.
What could be causing this, and how can I fix it? Tnank you
Accepted Answer
More Answers (0)
Categories
Find more on C2000 Microcontroller Blockset in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
