Have you ever wondered how everyday devices—like parking sensors, obstacle detection robots, or even automatic taps—measure distance so accurately? I wanted to explore the same idea but do it using an FPGA, where everything happens at the hardware logic level instead of relying on microcontrollers. That’s how this project began.
I built a distance measurement system using the Basys 3 FPGA development board and the popular HC-SR04 ultrasonic sensor. The goal was simple:Trigger the ultrasonic sensor, measure the echo time using FPGA logic, and convert it into a readable distance in real time.
But doing this on an FPGA brought interesting challenges. Unlike Arduino, there are no built-in delay functions or timers—we design the timing hardware ourselves. I implemented:
A pulse generator to send the 10 μs trigger signal
- A pulse generator to send the 10 μs trigger signal
An echo timing counter using the Basys 3’s 100 MHz clock
- An echo timing counter using the Basys 3’s 100 MHz clock
A finite state machine (FSM) to control the workflow
- A finite state machine (FSM) to control the workflow
A distance calculator that converts clock cycles into centimeters
- A distance calculator that converts clock cycles into centimeters
A 7-segment display driver to show the measured distance live
- A 7-segment display driver to show the measured distance live
The result? A fully hardware-level distance measurement system that outputs the object’s distance with impressive speed and accuracy. Watching the 7-segment display update instantly as the object moved closer or farther was the most satisfying moment.
This project helped me understand:
how ultrasonic sensors work at the signal level,
- how ultrasonic sensors work at the signal level,
how to design timing circuits in Verilog/VHDL,
- how to design timing circuits in Verilog/VHDL,
how FSMs efficiently control hardware operations,
- how FSMs efficiently control hardware operations,
and how much control and precision FPGAs offer compared to microcontrollers.
- and how much control and precision FPGAs offer compared to microcontrollers.
In future versions, I plan to add:
filtering to remove noise,
- filtering to remove noise,
a VGA graphical distance display,
- a VGA graphical distance display,
and a UART interface to stream the results to a PC.
- and a UART interface to stream the results to a PC.










_3u05Tpwasz.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)
Comments