Shop OBEX P1 Docs P2 Docs Learn Events
Programming (Ping.spin) Trouble w/ PING))) — Parallax Forums

Programming (Ping.spin) Trouble w/ PING)))

mopheadmophead Posts: 2
edited 2011-01-13 11:51 in Accessories
Hello,

Im having trouble with the method (Ticks) in the object (Ping.spin) which is the example program for the Propeller Microcontroller in the ping sensor’s datasheet. Specifically I can’t get the method Ticks to return a correct time interval between the rising edge and the falling edge of the echo pulse, all I get now is some constant value because I tried a smaller resistor (220 Ohm). With the 1k resistor the program could sense the rising edge but not the falling edge, so it would always freeze the program

The following code of concern is below
waitpne(0, |< Pin, 0)
cnt1 := cnt
waitpeq(1, |< Pin, 0)
cnt2 := cnt
Microseconds := (||(cnt2 - cnt1) / (clkfreq / 1_000_000)) >> 1

More info: Gadget Gangster Propeller Platform
5V power supply to board and sensor
220 Ohm

The sensor is functioning properly, because I was able to get it to work with my arduino mega board which correctly calculated the time with the pulseIn() function. Any help or further explanation of what’s really going on with this code would be truly appreciated.


Thanks,
mophead

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-20 20:57
    You copied the code wrong. The waitpeq statement's 1st argument is 0. Look again at the documentation.

    The 220 Ohm resistor is way too low. You should actually use something like 2.2K. With a 220 Ohm resistor, the PING can damage the Propeller's I/O pin.
  • mopheadmophead Posts: 2
    edited 2010-12-22 12:21
    Thanks for your input, I copied the wrong code but later after i already posted the thread fixed it so that waitpeq(0, |<Pin,0) but had the same results then as before. I added > 1k ohms of resistance, but, unlike before, the ping sensor's LED doesn't blink which (correct me if I'm wrong) represents the actual ultrasound pulse. Also nothing outputs to the terminal. Man I'm stuck, I know the code isn't wrong, I've tried other pins, I've tried a smaller resistance which did blink the LED but as u said was dangerously low. Is there anything else I could try or test to provide you with more information?

    Thanks again for your help,
    mophead
  • dandreaedandreae Posts: 1,375
    edited 2011-01-06 07:53
    Are you able to try a resistor of 2.2K or 3.9K?

    Dave
  • Ray0665Ray0665 Posts: 231
    edited 2011-01-13 11:51
    Waitpeq and Waitpne use 32 bit arguments for the first two arguments
    waitpeq( |<Pin, |<Pin, 0) and waitpne( |<Pin, |<Pin, 0)
    not waitxx(1,|<Pin,0) (unless your ping is attached to pin 0)

    Pin could also be multiple pins ie $0000_0000_0000_00FF for the first 8pins
Sign In or Register to comment.