Accurate sensing depended on timing. GPIO interrupts and hardware timer capture made it possible to measure ultrasonic echo delay precisely.
Embedded C
TI MSP432
GPIO Interrupts
Timer Capture
Ultrasonic
StatusCompleted
FocusEmbedded sensing
Core toolsEmbedded C · TI MSP432 · GPIO Interrupts
ECHO / TIMER CAPTURE
Project overview
I developed a collision detection system using bump and ultrasonic sensors. The MSP432 measured distance through ultrasonic echo timing and detected physical impact through bump-sensor input.
Technical details
How the system works.
A closer look at the architecture, implementation decisions, and validation behind this project.
01
System overview
The system combines two types of collision information. The ultrasonic sensor estimates how far away an object is before contact, while six bump sensors detect a physical collision and identify which side of the robot was hit.
The MSP432 connects those inputs to the motion response. Sensor events update the control state, and the firmware can reduce speed, reverse, or turn away based on whether the obstacle was detected at a distance or through direct contact.
02
Motor control with PWM
The motor driver uses separate signals for direction, wake control, and speed. P5.4 and P5.5 select motor direction, P3.6 and P3.7 wake the driver, and P2.6 and P2.7 carry the PWM outputs used to control speed.
I configured TimerA0 to generate the PWM waveform. TA0CCR0 defines a period of 10,000 timer counts, while a compare value such as TA0CCR3 = 2,500 keeps the corresponding motor output high for one quarter of each cycle. That produces a 25% duty cycle and gives the robot a controlled test speed for obstacle response.
03
Ultrasonic distance measurement
To begin a measurement, the MSP432 sends a 10-microsecond HIGH pulse to the ultrasonic sensor's TRIG input on P6.2. The sensor emits an ultrasonic burst and then drives the ECHO signal on P6.3 HIGH for the round-trip travel time of the sound wave.
A hardware timer measures how long ECHO remains high. Multiplying that duration by the speed of sound gives the round-trip distance, so the result is divided by two to calculate the one-way distance from the sensor to the obstacle. The updated value feeds the robot's state machine and supports a response before contact occurs.
04
Bump sensors and interrupts
Six bump sensors connect to Port 4 on P4.0, P4.2, P4.3, P4.5, P4.6, and P4.7. Internal pull-up resistors keep each input normally HIGH. Pressing a sensor pulls its line LOW and creates the falling edge handled by the Port 4 interrupt routine.
I assigned each sensor a signed weight based on position. The three right-side sensors contribute +3, +2, and +1; the left-side sensors contribute -1, -2, and -3. A positive total indicates a right-side collision, a negative total indicates the left side, and a value near zero represents a more direct front impact. The state machine uses that result to choose the turn direction.
I used a multimeter to confirm that each bump-sensor input was normally HIGH and dropped LOW when pressed. This verified the pull-up configuration and the electrical behavior before I relied on the interrupt code.
I then used an oscilloscope to inspect the falling edges and timer-driven signals. Seeing clean voltage transitions confirmed that the interrupt conditions were present, while observing the timing signals helped verify that PWM generation and ultrasonic measurement were operating as intended.
Multimeter checks for idle and pressed sensor voltage
Oscilloscope checks for clean falling edges
Timer and PWM waveform verification
End-to-end response through the control state machine
Engineering approach
From idea to working system.
01
Capture sensor events
GPIO interrupts allowed the system to respond to sensor transitions without relying only on continuous polling.
02
Measure echo delay
I used hardware timer capture to record ultrasonic echo timing precisely enough to support distance measurement.
03
Combine detection modes
Ultrasonic sensing provided distance awareness while bump sensors provided direct impact detection, giving the system two complementary inputs.
Technical highlights
What this project demonstrates.
01
Ultrasonic distance sensing
02
Bump-sensor impact detection
03
GPIO interrupt handling
04
Hardware timer capture
What I learned
The project developed my understanding of event-driven embedded code and showed how timer peripherals can turn a fast electrical signal into useful physical information.