Shop OBEX P1 Docs P2 Docs Learn Events
Is there some sort of event trigger on the basic stamp? — Parallax Forums

Is there some sort of event trigger on the basic stamp?

lordericolorderico Posts: 12
edited 2009-03-18 13:04 in BASIC Stamp
Is there a way a can have the basic stamp wait silently for input of some kind. When it receives input, then it runs code that processes what it has received.

Eric

Comments

  • RiJoRiRiJoRi Posts: 157
    edited 2009-03-17 19:30
    Look at PORT in the Help File.

    DO
    LOOP WHILE (IN0 = 0)

    This should loop forever until IN0 changes to a 1. You'll need to read the port and mask it off for testing multiple inputs.

    --Rich
  • lordericolorderico Posts: 12
    edited 2009-03-17 20:06
    Is there a way to check port 16 (the one that communicates to the computer)?
  • sylvie369sylvie369 Posts: 1,622
    edited 2009-03-17 20:21
    I think what you may want is this:
    BS2 Help file drone said...
    The POLLWAIT command is one of a family of unique "polling" commands on the BS2p and BS2pe modules. The other commands in this family include POLLIN, POLLMODE, POLLOUT and POLLRUN. The POLLWAIT command is used to pause program execution and go into a low-power state until any polled-input pin reaches the desired poll state.

    The "polling" commands allow the BASIC Stamp to respond to certain I/O pin events at a faster rate than what is normally possible through manual PBASIC programming. The term "poll" comes from the fact that the BASIC Stamp's interpreter periodically checks the state of the designated polled-input pins. It "polls" these pins after the end of each PBASIC instruction and before it reads the next PBASIC instruction from the user program; giving the appearance that it is polling "in the background". This feature should not be confused with the concept of interrupts, as the BASIC Stamp does not support true interrupts.

    The POLLWAIT command is unique among the polling commands in that it actually causes execution to halt, until a polled-input pin event occurs. The Period argument is similar to that of the NAP command; using the values 0 to 7 specifies the duration of the low-power period. After the low-power period is over, the BASIC Stamp polls the polled-input pins and determines if any meet the desired poll state. If no polled-input is in the desired state (as set by POLLIN command) the BASIC Stamp goes back into low-power mode, again, for the same duration as before. If any polled-input is in the desired state, however, the BASIC Stamp will continue execution with the next line of code.

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-03-17 20:49
    Optionally if your using a standard BS2 and want input on P16 take a look at the instruction SERIN, you can wait indefinitely for a predetermined character or characters or you can wait for a set length of time measurable in milliseconds.

    The recieved data on the serial line can be to·determine what action the·Stamp takes next, for example directed to a sub routine·, perform a calculation with the data·or control some I/O.

    Jeff T.
  • lordericolorderico Posts: 12
    edited 2009-03-17 20:59
    Thanks for the responses. My goal with this is to have the basic stamp sending out a pwm signal, while listening for input. The input will tell the stamp to stop/start the pwm signal, as well as to vary the duty cycle. I have tried SERIN, however in order to make the pwm signal continue correctly, I had to change the timeout of SERIN to a very low value. As a result, I could never send the data exactly at the time that the stamp was looking for it.

    I think polling sounds like a good idea. I control the signal on the computer with a java program, so I will probably have to learn the javax.comm API. Let me know if you have any thoughts on this idea.

    Eric
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-17 21:09
    You won't be able to monitor an input while the Stamp is generating PWM. The Stamps are "single threaded" and can only do one thing at a time. It's possible to get clever about interleaving some things like servo control pulses and reading some sensors, but that's not practical with things like PWM or receiving serial data.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-03-17 23:25
    If you can implement a flow control line on the PC side, maybe you can match that on the Stamp side with a 1 millisecond timeout or simple polling.

    An alternative is to offload the PWM to an external chp, such as the Parallax PWMPAL (#28020). That leaves the Stamp free to listen for the serial input and other supervisory functions. I don't know what function your PWM has. But for some applications the PWM from the BASIC Stamp command is not suitable due to its PFM waveform. The Stamp command is great for generating analog voltages and dimming LEDs but not so great for motor control. The PWMPAL can generate a more traditional PWM, constant frequency, variable duty cycle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • lordericolorderico Posts: 12
    edited 2009-03-18 13:04
    Thanks for the responses. The PWM signal I have is being used to control the speed of several motors. The PWMPal sounds like a good solution, as it can produce four independent PWM signals at once. I was also looking at the Motor Mind B. However, the MMB can only control one motor at once so I would need to buy three of them at $30 a piece to control all three motors.

    Eric
Sign In or Register to comment.