🧠 Concept Overview
🌊 How Ultrasonic Distance Measurement Works
- The ultrasonic sensor sends a 10 µs pulse via the
TRIG
pin. - The
ECHO
pin goes HIGH while the signal travels to the object and back. - The duration (in microseconds) that
ECHO
stays HIGH is proportional to the distance. - Speed of sound ≈ 343 m/s or 0.0343 cm/µs.
- Since the sound wave travels to the object and back, the formula is:
Distance (cm) = (Time (µs) × 0.0343) / 2
⚙️ Hardware Context
This calculation is based on:
- Buddy51 works
Timer
in Mode 1 (16-bit) - A standard 11.0592 MHz crystal
⏱️ Timer Tick Time Calculation
In Timer Mode 1, the timer increments every machine cycle. With an 11.0592 MHz crystal:
- One machine cycle = 12 / 11.0592 MHz ≈ 1.085 µs
- Each timer tick ≈ 1.085 µs
📏 Converting Timer Ticks to Distance
- Let
t
= timer ticks (1 tick ≈ 1.085 µs) - Time in microseconds =
t × 1.085
- Distance (cm) =
(t × 1.085 × 0.0343) / 2
- That simplifies to
distance = t × 0.0186
Since floating-point math is avoided in embedded C, we use integer math:
1 2 | distance_cm = ticks * 217 / 11600; |
📌 Summary
- Timer tick ≈ 1.085 µs
- Speed of sound = 0.0343 cm/µs
- Round-trip distance, so divide by 2
- Final formula:1distance_cm = ticks * 217 / 11600;
This method gives you accurate ultrasonic distance readings using only integer arithmetic, making it ideal for 8051 microcontrollers and SDCC projects.
Leave Your Reply
You must be logged in to post a comment.