Shop OBEX P1 Docs P2 Docs Learn Events
Ping in assm — Parallax Forums

Ping in assm

ratronicratronic Posts: 1,451
edited 2007-04-11 22:03 in Propeller 1
Has anyone ever written assembly code to read a Ping sensor and would be willing to share that code w/ me. I am attempting to write that code in assembly from just the specs of the ping sensor and would like to see how somebody else did it for an example. This is first try at assembly other than blinking a led off and on.·Any help would be appreciated. Whether·there's an example to learn from or not I will get this beast coded and post it here!·· Thanks! Dave

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Fix it if ain't broke·
D Rat

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-11 19:12
    You should use the Ping sensor object from the Object Exchange, it uses the counter for the measurement so it should be relatively simple to convert it to assembly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-11 19:26
    D Rat,

    You can learn while you apply it…Reading the ping is pretty straight forward even in ASM and you have two methods of doing it…One would use the counters…I will explain how to do it the other way, which is more straight forward.

    The PING))) is triggered by a pulse from the Propeller. This pulse must be at least 2 uS, although 5 to 10 uS could be used. So to send a pulse make the pin·HIGH and set the direction register to 1 for that pin. Use the system counter to get your pulse width then make the pin an input by setting the direction register for that pin to 0 (the pin is pulled down and will return LOW).

    Now wait for the pin to go HIGH. Once it does, store the counter value and wait for the pin to go low. Store the new counter value. Subtract the first value from the second and you have your pulse width based on the system clock. With a little math you can convert that to distance, which divided by two will be the one-way distance. I hope this helps. Take care.

    [noparse][[/noparse]Edit] As per Paul's reply, that object is one I wrote and the above is the steps I took to get the readings.· I would've done the same for ASM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support


    Post Edited (Chris Savage (Parallax)) : 4/11/2007 10:05:01 PM GMT
  • ratronicratronic Posts: 1,451
    edited 2007-04-11 21:35
    Thanks! It may take me some time, but I will get it figured out!
    Thanks! Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Fix it if ain't broke·
    D Rat
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-11 22:03
    Small edit to my above post...Sorry...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.