Shop OBEX P1 Docs P2 Docs Learn Events
How can i check the data pattern coming out from the pin of BS2p? — Parallax Forums

How can i check the data pattern coming out from the pin of BS2p?

bbnqondbbnqond Posts: 16
edited 2009-04-08 13:25 in BASIC Stamp
Dear all,

I want to check the data pattern coming out from a pin of BS2p. The reason for doing this is that I want to ensure the data keep changing, such that if the data remain constant for a time will lead to a subroutine.

Also, i wonder if there are any ways to synchronise other MCUs with BS2p. If so, please suggest a MCU that is suitable for making a·4-button keypad.

Regards,
bbnqond

Comments

  • Craig EidCraig Eid Posts: 106
    edited 2009-04-07 06:42
    bbnqond,

    Regarding the data pattern, have you sent data to your PC using the DEBUG command? For more information view the DEBUG command in the Help file.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ························ Craig Eid


    ··········· Triad Research and Development
    Electical Engineering Design and Consulting Services

    ··················· www.TriadRD.com
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-04-07 08:48
    You do not actually say, but I assume you want the program running in the Stamp to be able to tell whether an output has changed.· If that is not what you mean, then you must state your desire more clearly.

    A program running in a Stamp can always read the state (1 or 0) of any of its input/output pins.· Most programs read the state of only those pins that are set as input, but a program can also read the state of a pin that it has set to output.· Do it in exactly the same way you would read an input.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • bbnqondbbnqond Posts: 16
    edited 2009-04-07 19:16
    Carl Hayes said...
    You do not actually say, but I assume you want the program running in the Stamp to be able to tell whether an output has changed. If that is not what you mean, then you must state your desire more clearly.


    A program running in a Stamp can always read the state (1 or 0) of any of its input/output pins. Most programs read the state of only those pins that are set as input, but a program can also read the state of a pin that it has set to output. Do it in exactly the same way you would read an input.

    yup, you get my point.
    let me explain what I want to do clearly.
    I was doing a project related to GPS. So far from now I am able to process the data smoothly, and getting the things i want. Yet, recently I would like to enhance my device with an emergency system, that is, to check if the user stayed at the same place for more than 2 hours. If so, it will trigger an subrountine and do something.

    My original concept of the flow is, firstly it obtained the latitude and longitude from the GPS receiver, modulated it into a pack of data and store it to the scratch pad ram. Each time it finished 1 round of obtaining GPS data, it will re-run the subrountine, then it will check if the longitude and latitude is the same as the previous record. If so, it will increase a flag by 1. The flow continious as time flies. Finally, if the counter reached a level, say 10000, it will automatically jumped to the emergency system.

    However, the concept seems complicate for me to implement it into BS2p, and I have already used up the number of variables. Thus, I have to think another way to solve the problem. Now, I would like to use an MCU to communicate with BS2p. The MCU will have a memory reserved for receving the data from BS2p and a counter that count the number of time that similar data received. BS2p will send the longitude and latitude data to another MCU, and this MCU will record the data. When BS2p transmits the data to that MCU again, that MCU will check if the data is the same as the one recorded previously. If the data are the same, it will discard that data and increase a counter; if it is not the same, store the new data. Once the counter reached 10000, that MCU will set a pin (assume P15) of BS2p to high and reset BS2p (making it like interruption). Finally, upon the reset of BS2p, it will check if P15 is high so that to trigger the emergency system.


    waha...I typed such a long passage. sorry for the crab.
    tongue.gif
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-04-07 23:30
    I think I understand. But you must consider that resetting the Stamp sets all pins to input, and also resets any output data. If you reset the Stamp, then (for example) set pin 3 to output, pin 3 will be 0 no matter what it was before the reset.

    Also, even if you stand still the Latitude and Longitude from the GPS will change continually over a range of perhaps 5o to 100 feet. It's not perfectly steady, even when you sit still.

    However, if it is the external device (MCU) feeding a high to P15 in your example, you can simply read P15 any time to see what the external device is saying.

    But why do all that? Your program must have a main loop somewhere. Why not just check P15 in that loop, and if it's high, go to your subroutine. No reset needed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • bbnqondbbnqond Posts: 16
    edited 2009-04-08 13:25
    Carl Hayes said...
    I think I understand. But you must consider that resetting the Stamp sets all pins to input, and also resets any output data. If you reset the Stamp, then (for example) set pin 3 to output, pin 3 will be 0 no matter what it was before the reset.

    Also, even if you stand still the Latitude and Longitude from the GPS will change continually over a range of perhaps 5o to 100 feet. It's not perfectly steady, even when you sit still.

    However, if it is the external device (MCU) feeding a high to P15 in your example, you can simply read P15 any time to see what the external device is saying.

    But why do all that? Your program must have a main loop somewhere. Why not just check P15 in that loop, and if it's high, go to your subroutine. No reset needed.

    The reason for doing that is that I want an immediate response to my interruption. cool.gif
Sign In or Register to comment.