Way to make the basic stamp wait for an input?
TboneH
Posts: 2
Hey guys, I need some help. I'm no expert, so don't kill me if I say something stupid. What I have is a slide carriage and switch system. I want the carriage to slide along until it hits a switch (wired normally open), and then stop. I'm using a plain old BS2 stamp, and I already have my switch and carriage motor wired to it. For now, we'll just assume that my motor output is pin 15, and my switch input is pin 0. I've tried using an IF THEN system that looks kinda like this:
IF (IN0 = 0) THEN
HIGH 15
ELSE
LOW 15
ENDIF
However, my carriage motor is very fast (it's out of an inkjet printer if that helps you imagine it). What ends up happening is that by the time the stamp recognizes that switch has been pressed, the motor is past it, and it doesn't shut off. What I want is for the stamp to send a high to 15 until it receives an input at pin 0 and then continue with the rest of the program. Any suggestions?
IF (IN0 = 0) THEN
HIGH 15
ELSE
LOW 15
ENDIF
However, my carriage motor is very fast (it's out of an inkjet printer if that helps you imagine it). What ends up happening is that by the time the stamp recognizes that switch has been pressed, the motor is past it, and it doesn't shut off. What I want is for the stamp to send a high to 15 until it receives an input at pin 0 and then continue with the rest of the program. Any suggestions?
Comments
It that's still not fast enough, you will probably have to hardwire something to stop the motor on time.
-Phil
Is that correct syntax? I can't test fully test it right now because I'm missing some necessary resistors, but experimenting with it it seemed to do the job.
And to tobdec, it is a brushed motor, but I think you misunderstood my problem. My problem was that using the IF THEN code, if the slide carriage didn't stop exactly on the switch, it would send a 0 again and the carriage would continue due to the way the code was written.
Since pin 15 only needs to be set high once, setting it high inside each loop will cause an unneeded delay.
This extra delay will cause the Stamp to be a little slower to sense the button press.
The BASIC Stamp implements the loop internally using GOTO primitives that were part of PBASIC 2.0 and earlier, and it is easy to see the time difference.
Another to try for speed would be That gains speed because it does not have to evaluate the math of in0=0. The simple fact that in0=1 counts as TRUE. But the microcode for the DO UNTIL syntax is not as fast as the DO : LOOP WHILE syntax.
Yet another, and probably the fastest option is the BRANCH instruction, which is itself a Stamp primitive.
Is above correct? have no chance to verify now.
Note that the minimum count will be CNT=2.
ok am i missing something? i copied this line (except i have pin 6 as input so i have in6) and try to run it i get the error:
Expected ':' or end-of-line
??????
In your Task8, the LOOP continues unless the data read from location 0 is non-zero. If you've just done Task7, that location will be left with a zero in it and the next time you do Task8, the LOOP will never exit.
Print out your program and take a pencil and point it at the Main label. Then advance the pencil one statement at a time pretending that your pencil is the Stamp executing the program. There's only one pencil and the Stamp does only what the pencil is pointing to. It's as if the rest of the program doesn't exist ... only that one statement.
You can use an external co-processor (another special purpose microcontroller) like these from ProteanLogic. These are pre-programmed microcontrollers that handle the serial input while the Stamp is doing something else. When the Stamp is ready, it can retrieve any characters that have come in while it was busy.
Alternatively, you can use some kind of external flasher that the Stamp can turn off and on, but the Stamp doesn't have to do the actual flashing and timing and it can sit there waiting for serial input characters.
The BS2 has flow control capabilities, for example, if you add the \15 as follows, then the Stamp generates a "not ready" level on pin p15 when it is busy in other routines, and that level will go to "ready" when it comes to the SERIN and is ready to receive. If the PC is also set up for RTS/CTS flow control, it will automatically hold off on sending the command until it gets the go ahead from the Stamp.
The PC can't preemptively take over at any time. However, SERIN also has a timeout option. For example, the following adds a 500ms timeout, with a branch out to label "nextup" if no data is received within 500ms.
As a workaround, to give the illusion of instant response, you can replace a PAUSE 500 with a SERIN + timeout. That might even work without flow control, because your program has lots of long pauses.