Restore accidentally deleted code in 4e61155

This commit is contained in:
Rihards Skuja 2018-01-19 20:06:26 +02:00
parent 6c94180d77
commit 92c3842ca9
No known key found for this signature in database
GPG Key ID: 53FA13A3F7F8571B

View File

@ -5,7 +5,7 @@
#include "led.h" #include "led.h"
volatile uint32_t trig_counter; volatile uint32_t trig_counter;
uint32_t no_of_ticks; volatile uint32_t no_of_ticks;
void init_sonar(void) void init_sonar(void)
{ {
@ -36,15 +36,19 @@ uint16_t read_sonar(void)
sei(); sei();
// Count cycles until ECHO goes low // Count cycles until ECHO goes low
while (CHK(ECHO_PIN, ECHO_BIT)) { while (CHK(ECHO_PIN, ECHO_BIT)) {
++no_of_ticks; if (no_of_ticks + TCNT1 > SONAR_TIMEOUT) {
if (no_of_ticks > SONAR_TIMEOUT) {
return SONAR_ERROR; return SONAR_ERROR;
} }
} }
TCCR1B = 0x00; TCCR1B = 0x00;
cli(); cli();
no_of_ticks += TCNT1;
return (uint16_t)(no_of_ticks / (CYCLES_PER_US * 58)); return (uint16_t)(no_of_ticks / (CYCLES_PER_US * 58));
} }
ISR(TIMER1_OVF_vect)
{
no_of_ticks += TIMER_MAX;
}