Shop OBEX P1 Docs P2 Docs Learn Events
PING Ultrasonic sensor — Parallax Forums

PING Ultrasonic sensor

ScadaScada Posts: 1
edited 2010-06-23 16:52 in Accessories
I'm using a PIC16F877 microcontroller to send a pulse to a PING ultrasonic sensor to measure distances. If the pulse is sent to the sensor. the activity LED blinks and nothing happens again. This is the code to send and receive signal from the sensor.
void Get_distance()
{
·//unsigned short start_time,end_time;
·//unsigned short f_time;
·start_time=0;
·end_time=0;
·f_time=0;
·· ·//Clear TMR1 and enable TMR1 disable TMR1 interrupt
·TMR1ON=0;
·TMR1H=0x00;
·TMR1L=0x00;
·TMR1ON=1;
·TMR1IE=0;
·//Get fuel level in seconds
··TRISB3=0;
··· RB3=0;
··· _delay(2);
····RB3=1;···//Output trigger pulse
· ··_delay(5);···· //Trigger pulse is 5us long
· ··RB3=0;···//End trigger pulse
· ··_delay(200);·//Delay to take care of Thold-off
· ··TRISB3=1;··//Make RA0 an input

··do{
····if(RB3==1)
·· ··{
····· start_time=TMR1H;
·· ··· start_time<<=8;
·· ··· ·· start_time+=TMR1L;
······}
···}while(RB3==0);

···do{
····· if (RB3==0)
····· {
······· end_time=TMR1H;
·· ···· end_time<<=8;
·· ···· end_time+=TMR1L;
······ }
···}while(RB3==1);
·}···

Comments

  • dandreaedandreae Posts: 1,375
    edited 2010-06-23 13:14
    Try this link for more information:· http://www.ccsinfo.com/forum/viewtopic.php?t=38843&postdays=0&postorder=asc&start=0 I hope·this helps.

    Dave



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-06-23 16:52
    One thing I would recommend is making the I/O pin an input immediately afterthe end of the trigger pulse. Measurement of the return pulse width should start immediately when the I/O pin is driven high by the PING))).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
Sign In or Register to comment.