Shop OBEX P1 Docs P2 Docs Learn Events
How to read multiple pings' value for basic stamp 2 at the same time — Parallax Forums

How to read multiple pings' value for basic stamp 2 at the same time

PeterJiangPeterJiang Posts: 9
edited 2012-11-28 12:22 in BASIC Stamp
Hello everyone! Here's a question about basic stamp 2 , hope someone can help >.<
I have 12 hall sensor,and i have to check all these sensor's output value at the same time and then send the output to matlab.
I tried to use the function "debug" to check every pings
The code is like below

Main:
DO
DEBUG BIN IN15,BIN IN14,BIN IN13,BIN IN12 ,BIN IN11 ,BIN IN10,BIN IN9,BIN IN8,BIN IN7,BIN IN6,BIN IN5,BIN IN4,BIN IN3,CR

LOOP
END

But it seems that every pings' value will show one by one,I want that all the pings' value can be read and then shown at the same time
Could everyone provide me some functionsto use or code?

Thanks,
Peter

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-27 10:16
    You can't do it. You can't read the PINGs all at the same time. You have to trigger them and time the resulting pulse one after the other. The worst case timing is just under 20ms per PING. 12 PINGs would take about 1/4 second to read.

    The Stamps are single threaded microprocessors. They do only one thing at a time. The PING is designed to be controlled using the PULSIN statement of the Stamp. This causes the Stamp to wait until the rising edge of an input pulse on a single I/O pin, then wait until the falling edge occurs while measuring the time between the rising and falling edges of the pulse. The time is returned by the PULSIN statement by storing it in a specified variable.

    The PING has to be triggered with a short output pulse and the input pulse begins quickly after the trigger pulse. You can read a single PING at a time, one after another, and store the results in a series of variables, then output the variables to MATLAB one after another with a single or multiple DEBUG statements.
  • PeterJiangPeterJiang Posts: 9
    edited 2012-11-27 11:17
    Thank you very much!
    The purpose for asking this question is that I want to test 12 hall sensors and observe their high-low voltage value
    for your comment above,I have to wait a cycle,spending 1/4 second,then I can read the value of the same PING again ,is that right :o ? But waiting 1/4 second for my hall sensor experiment is a little long time
    The changing of flux may be disappear within 1/4 second.
    So the only way to solve my question is extending the time for changing of flux?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-11-27 11:45
    Peter,

    Welcome to the forums! I am a little confused about what you're trying to read...are you trying to read multiple PING))) Ultrasonic Range Finders and Hall-Effect Sensors? Or are you just referring to the Hall-Effect Sensors when you say ping?
  • PeterJiangPeterJiang Posts: 9
    edited 2012-11-27 11:52
    Yep....I tried to read multiple pings at the same time,but now I know that it's impossible!
    I want to read the high-low voltage value for hall sensor,as the code above,high will represent"1" and low will represent"0",that is what i want to read.
    And here is the website for datasheet of the hall sensor
    http://www.feeling-tech.com.tw/km-master/ezcatfiles/cust/img/img/26/fs41g1-a_v12.pdf

    thanks for ur replying!
  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-27 20:20
    My comment (Post #2) was about the PING))) Ultrasonic Range Finder sensor. I thought you were mounting several of these in a hallway (hall) to sense the presence of objects (like people). A Hall-effect sensor, like you mean, is named after the scientist (Hall) who discovered the physical effect that is used. The name is always capitalized in English.

    If you connect the Hall-effect sensors to I/O pins 0-11 of a Stamp, you can easily read the state of all 12 sensors at the same time by using the expression "INS & $FFF" (without the quotes).

    INS is a 16-bit register that contains all 16 I/O pins of the Stamp represented as a single 16-bit value with I/O pin 0 as the least significant bit and I/O pin 15 as the most significant bit. Since you're using only 12 I/O pins, you only need the corresponding bits, so you mask the other 4 I/O pins off using "& $FFF". You can send this as 12 binary digits by using "DEBUG BIN12 INS". The "BIN12" will send only the least significant 12 bits which is what you want.

    Remember that your Hall-effect sensor has an open collector output. You'll need a pullup resistor on each Hall-effect output. A 4.7K to 10K resistor connected to Vdd (+5V) will do.
  • ercoerco Posts: 20,256
    edited 2012-11-28 08:28
    In his first post, I believe peter was using the word "ping" when he meant "pin".

    A few years ago, someone posed a question about PING when they actually meant PINK and there was a similar flurry of miscommunication for several replies. What a difference a letter makes! :)
  • PeterJiangPeterJiang Posts: 9
    edited 2012-11-28 10:37
    Yep!
    Using:DEBUG BIN12 INS is what I want.
    It shows around 12x40 data in the debug screen.
    So it's the maximum speed that basic stamp can show the data for my hall sensor experiment?
  • PeterJiangPeterJiang Posts: 9
    edited 2012-11-28 10:38
    And what's the different between pin and ping?
  • davejamesdavejames Posts: 4,047
    edited 2012-11-28 11:42
    PeterJiang wrote: »
    And what's the different between pin and ping?

    A "pin" typically refers to a particular BS2 input/output (I/O) connection, of which the BS2 has 16. The BS2 has other pins used for power, ground, reset, and communication.

    A "ping" in and around Parallax typically refers to an unltrasonic sensor:
    http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/CategoryID/51/List/0/SortField/0/Level/a/ProductID/92/Default.aspx
  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-28 12:22
    Yes, whatever you're seeing on your PC is as fast as it can be. The limiting factor is the transmission time for the data to the PC ... about 9600 Baud ... about 1 character per millisecond. If you use DEBUG HEX3 INS, you will see the data about 4 times faster since there will be only 3 characters sent per set of 12 bits rather than 12 characters for 12 bits. You'd have to unpack the data on the PC end of things and it's not that much faster. Theoretically, you could send two sets of 12 bits in 3 bytes, but it's not a big time saver. The Stamps are not that good at faster Bauds.
Sign In or Register to comment.