Shop OBEX P1 Docs P2 Docs Learn Events
Ping Ultrasonic Sensor Help! — Parallax Forums

Ping Ultrasonic Sensor Help!

robo1robo1 Posts: 2
edited 2009-04-01 14:29 in Accessories
hey guys,

well i working on a robot for school and i used the parallax board to connect the sensor and get some values. it was easy to do the setup and all well now my question is how would i interface the same sensor on a logicflex(intel). im having difficulty doing that i have do alot of research can seem to find a way to do it. well below is the data sheet:

http://www.jkmicro.com/documentation/pdf/BrocLogicFlex.pdf

thank you

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-03-16 15:20
    You'll want to figure out how to send and receive pulses of a very specific width. Once you can do that, it's just math.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-16 15:44
    You would use one of the Digital I/O pins to interface to the PING. As SRLM indicated, you'll have to figure out how to do the timing. A lot will depend on the programming language you want to use and its facilities. We can't help you there.

    One possibility would be to continue to use the Stamp as a peripheral processor for the PING. The Stamp would simply get readings from the PING and send the values as numbers (digits followed by a space or carriage return) to the PC via one of the serial ports.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-31 22:46
    Your duplicate post in the robotics forum has been removed. Please post your follow up questions in this thread.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • robo1robo1 Posts: 2
    edited 2009-04-01 05:25
    well i was able to pogram the code but now im nt getting any value back from the sensor. please someone help me with my code.

    #include <stdio.h>
    #include <dos.h>

    //
    unsigned int GetTickCount(void){
    /* Created: 2/5/2009
    Author: AC
    Purpose: uses striaght up assembly to latch the current 'tick count' of the 8254 counter (coutner 1),
    assuming it's running at the full speed, and nobody has (expletive)ed with the PSCLK.
    Each 'count' is about .8380951104us / 2
    */
    __asm{
    pushf // save interrupt state
    cli // disable interrupts for the duration
    mov ax, 0x80 // command to latch coutner 0
    out 0x43, al // latch the coutner
    in al, 0x42 // Get LSB
    mov ah, al // Save LSB
    in al, 0x42 // Get MSB
    xchg al, ah // switch them around to be right
    popf // restore interrupts
    }
    //printf("%u\n", _AX);
    return (_AX);
    }






    main()
    {
    unsigned int count;
    int i=0;

    outportb(0x65,0x01); /*set port to output*/
    outportb(0x60,0x00); /* set the port to low*/
    outportb(0x60,0x04);/*trigger the port*/

    delay(5/1000); /*Delay according to of 5 microseconds*/
    outportb(0x60,0x00); /* set the port to low*/
    outportb(0x65,0x00);/* set the port to low*/
    while(inportb(0x60)==0x00){
    count=GetTickCount();
    printf("PORT A: %X\n",count); /*read and print port A value*/
    i=i+1;
    if(i>=20)
    break;
    }


    return 0 ;
    }
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-01 14:29
    I have no documentation on your "outportb" and "inportb" routines, but I can read the comments.

    1) You probably need a short delay after setting the port to low. I'd make it 50ms. If the PING is somehow falsely triggered while you're setting up things, this allows it to finish its cycle and become ready to be properly triggered.

    2) The "delay" routine probably only allows integer arguments. Your "5 / 1000" is not legal. I don't know what it actually would do, but you're not going to get the 5us delay.

    3) Again, you probably need a short delay after setting the port back to low after the pulse. The PING has a "hold off" period of about 750us before it sends its echo pulse and you want to wait at least 500us to 600us before looking for the pulse.

    These microsecond delays can be done with a set of nested FOR loops, but you'll have to do some experimenting to see what the counts have to be. For example, the following will result in some delay:
    for (i=0;i<32767;i++)
       for (j=0;j<32767;j++)
          ;
    


    Put this in a short program that displays a message before and after the loops and time the delay with a stopwatch. You may even need a 3rd loop around this to get enough of a delay to time by hand. Alternatively, you could use a delay like this to blink an LED and use a scope to time the pulses.
Sign In or Register to comment.