vascode / i2c-gps-nav

Automatically exported from code.google.com/p/i2c-gps-nav
0 stars 0 forks source link

Sonar Resolution issues #7

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I had some trouble with my Ultrasonic sensor not able to get a reading. It's 
like my sensor would crash sometimes but if I pulsed the line again I would get 
a reading.

I made a small change to the sonar_update function such that if no state change 
was received, it would reset and try again. Seemed to fix my problem.

void Sonar_update()
{

#if !defined(MAXBOTIX_PWM)

  if (Sonar_waiting_echo == 0)
  {
    // Send 2ms LOW pulse to ensure we get a nice clean pulse
    PORTC &= ~(0x08);//PC3 low    
    delayMicroseconds(2);

    // send 10 microsecond pulse
    PORTC |= (0x08);//PC3 high 
    // wait 10 microseconds before turning off
    delayMicroseconds(10);
    // stop sending the pulse
    PORTC &= ~(0x08);//PC3 low

    Sonar_waiting_echo = 1;

  // We never got a signal pulse back for some reason
  // We should have a pulse of up to 36 mS if nothing detected
  } else if((micros() - Sonar_starTime) > 50000) { 
    Sonar_waiting_echo = 0;
  }
#endif
}
#endif

Original issue reported on code.google.com by snowz...@gmail.com on 24 Apr 2013 at 3:41