This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| de:examples:sensor:ultrasonic [2009/09/20 10:54] – mikk.leini | de:examples:sensor:ultrasonic [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 69: | Line 69: | ||
| // Adjust timer period so that we get 1cm of | // Adjust timer period so that we get 1cm of | ||
| - | // distance every overflow. | + | // measured |
| - | ICR1 = 900; | + | // |
| + | // Formula: | ||
| + | // Timer period = clock rate / speed of sound in centimeters * 2 | ||
| + | // The period is multiplied by 2 because the sound travels | ||
| + | // forth and back. | ||
| + | ICR1 = 893; | ||
| // Enable overflow interrupt | // Enable overflow interrupt | ||
| Line 78: | Line 83: | ||
| // | // | ||
| // Delay | // Delay | ||
| - | // Time in ~0.06 of milliseconds | + | // Time in ~60 of microseconds |
| - | // (the time of sound wave travelling 1cm forth and back) | + | |
| // | // | ||
| void delay(unsigned int time) | void delay(unsigned int time) | ||