Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
int sonar_Ping(void) { #define PINGPIN 3 // assign a pin to the Ping Sensor #define DDR DDRA #define PORT PORTA #define PIN PINA rprintf("1 "); PORT_ON(DDR, PINGPIN); // Switch PingPin to OUPUT // ------Trigger Pulse-------------- rprintf("2 "); PORT_OFF(PORT, PINGPIN); // Bring PingPin low before starting trigger pulse delay_us(5); // Wait for 2 microseconds rprintf("3 "); PORT_ON(PORT, PINGPIN); // Bring PingPin High for 5us according to spec sheet. delay_us(5); // Wait for 5 microseconds rprintf("4 "); PORT_OFF(PORT, PINGPIN);; // Bring PingPin Low and standby //--------End Trigger Pulse--------------------- rprintf("5 "); FLIP_PORT(DDR, PINGPIN); // Switch PingPin to INPUT rprintf("6 "); loop_until_bit_is_set(PIN, PINGPIN); // Loop until the the PingPin goes high (macro found in sfr_def.h) //clears timer, reset overflow counter rprintf("7 "); reset_timer_0(); //reset timer 0 rprintf("78 "); loop_until_bit_is_clear(PIN, PINGPIN); // Loop until the the PingPin goes low (macro found in sfr_def.h) //read timer0's overflow counter //255 is count before overflow, dependent on clock rprintf("9 "); return (timer0GetOverflowCount()*255+TCNT0) * 2.068965517;//elapsed time x conversion }
System Warming Up.................Initialization Complete test 1 2 3 4 5 6 7 78 9 Range: 33 test 1 2 3 4 5 6
System Warming Up.................Initialization Complete test 1 2 3 4 5 6 7 8 9 Range: 59 test 1 2 3 4 5 6 7 8 9 Range: 57 test 1 23 4 5 6 7 8 9 Range: 59
when i wrote this code i was using on the sensor side (adc pins) because on the $50 robot those are the regulated power buses #define PINGPIN 2 // assign a pin to the Ping Sensor #define DDR DDRC #define PORT PORTC #define PIN PINC