As I said AVR 324p programming make me crazy. I am new for the microcontroller programming thing but I am trying my best. All what I am trying to do is using ultrasonic senosrs (SRF05) to detect any object. I donnot need to use PWM, but instead of that I used a delay. Trigger and echo signal result where satisfying (were checked using Oscilloscope) the problem was how I am ganna know the width of the echo signal. I am how the microcontroller will know ?? Some one gave me a suggestion to use a counter and delay but it didnot work. My code is below any one can help me ?
#include <avr/io.h>
#include <util/delay.h>
int main()
{
char time, count = 0;
DDRD = 0b00100001;
PORTD = 0x00;
while(1)
{
count = 0;
PORTD &= (1 << PD0); // put 1 at PD0
_delay_ms(50);
PORTD &= (~(1 << PD0)); // put 0 at PD0
_delay_ms(50);
while ((PIND & (1 << PD2)) == 0)
;
while ((PIND & (1 << PD2)) != (1 << PD2))
{
_delay_us(10);
count++;
}
}
return 0;
}
The second problem was with the servo motor (Futaba s3003). I need to deflect it to spesific angle but each time I am changing the duty cycle (1,1.5,2 ms) it goes to the same angle where the peroid is 20 ms ?? why