The program for processing the response from the HC-SR04 is not working correctly

28 Views Asked by At

I am trying to measure distance using the HC-SR04 sensor and the ATmega32 microcontroller. I am using the following code.

PORTB|=(1<<PB1);
_delay_us(10);
PORTB &=~(1<<PB1);
while (!(PINB & (1 << PB0)));
TCCR1B|=(0<<CS12)|(0<<CS11)|(1<<CS10);
while (PINB & (1 << PB0));
pulse=TCNT1;
TCCR1B=0;
TCNT1=0;

As a result, I always get the same counter value. Can you help me figure out what I'm doing wrong?

0

There are 0 best solutions below