Problems with the Button command
Mrdavidjenkins
Posts: 49
Good Afternoon,
I have a problem with a relay closing and giving me multiple counts.· The Relay sounds good and the line between the relay and the stamp is about 3ft.· I am trying to use a BUTTON command and am having no luck.· I am getting usually 10 button presses when I expect to get only 1.· (The code below is based upon the code in the help files.)
' {$STAMP BS2sx}
' {$PBASIC 2.5}
btn···· PIN 5
mycount VAR Word
btnwrk· VAR Byte
btnwrk = 0
DO
······· PAUSE 5
······· BUTTON BTN, 1, 255, 255, btnwrk, 1, readlight
ret:··· PAUSE· 5
'·· Works Better if below is inserted, but still not properly
'······ PAUSE 500
LOOP
READLIGHT:
·· mycount = mycount + 1
· DEBUG "My Count is ", DEC· mycount, CR
GOTO Ret
AS I understand it, the syntax I have above has·the delay set to 255, so only there is no repeat, but is debounced.· The rate is set at 255, but this should be irrelevent because there is no delay.
Can you help me with this Counting problem?
Thanks
Dave
I have a problem with a relay closing and giving me multiple counts.· The Relay sounds good and the line between the relay and the stamp is about 3ft.· I am trying to use a BUTTON command and am having no luck.· I am getting usually 10 button presses when I expect to get only 1.· (The code below is based upon the code in the help files.)
' {$STAMP BS2sx}
' {$PBASIC 2.5}
btn···· PIN 5
mycount VAR Word
btnwrk· VAR Byte
btnwrk = 0
DO
······· PAUSE 5
······· BUTTON BTN, 1, 255, 255, btnwrk, 1, readlight
ret:··· PAUSE· 5
'·· Works Better if below is inserted, but still not properly
'······ PAUSE 500
LOOP
READLIGHT:
·· mycount = mycount + 1
· DEBUG "My Count is ", DEC· mycount, CR
GOTO Ret
AS I understand it, the syntax I have above has·the delay set to 255, so only there is no repeat, but is debounced.· The rate is set at 255, but this should be irrelevent because there is no delay.
Can you help me with this Counting problem?
Thanks
Dave
Comments
·· What exactly happens when you press the button?· How is your button connected?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I am using the circuit similar to the one shown on page 135 of BASIC STAMP SYNTAX AND REF MANUAL 2.1 - Active High. That is, I have a 220 ohm Resistor and a 10 k ohm resistor in the active-high scheme. In place of the PB switch, I have a Radio Shack Relay that is triggered by a Allen Bradley retroflective sensor.
When I run the code above, I get incremental mycount output from 1 to 7 on first momentary interuption . Then I get 8 to 15 on the second momentary interuption. Then I get 16 to 20 on the third interuption. I have only interupted the beam 3 times, but I get 20 mycounts back from the computer. If I put my hand over the sensor for , say, 5 seconds, I get a mycount of 20 to 50.
' {$STAMP BS2}
' {$PBASIC 2.5}
IncCount······· PIN···· 5
myCount········ VAR···· Word
Reset:
· myCount = 0
Main:
· DO
··· IF (IncCount = 1) THEN
····· myCount = myCount + 1
····· DEBUG HOME, "Count is ", DEC myCount
···· ·PAUSE 100
··· ENDIF
· LOOP UNTIL (myCount > 10)
· GOTO Reset
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
THanks
Dave
I tried your idea and really appreciate it - but it was not successful. The pause 100 reads 1 thru 6, then 7 thru 11 then.. . And increasing the pause length improves it substantially. If I change your pause statement from 100 to 2000, it does work fine, but the app requires about 40 strokes per minute.
I am beginning to suspect that the hardware is snafu. If so, do you have a test that I could try? (No oscillascope)
Would you suggest using a transistor or set of transistors? The Allen bradley needs 15 volts, so I have a separate transformer for that. The output from the allen bradley is 15 volts as well. Ideally, I could build a box that would I could swap out - keeping the circuits as separated as much as possible to protect both the stamp and the allen bradley (which is pretty expensive).
Appreciate your thoughts.
·· The test for the code Jon supplied would be to replace the Relay contacts with a switch and try that.· Bear in mind that an active high input would require a 10K pull-down resistor to ground (Vss).· Without it the input may actually oscillate, give you readings like you describe.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Now... you could probably get away with a connection between the AB device and the Stamp using a 22K resistor.·
AB ---> 22K ---> Stamp
This would limit the current flow into the Stamp to a safe level.· We do this with RS-232 stuff all the time.· In that case you'd have an active-high input.· Of course you'd need to connect Vss on both sides as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
All of your attempts and efforts to remove this proposed "jitter" or bounce from this signalling system have been most laudable. One thing is missing so far, which may be of extreme importance, however. To date there has been no determination WHERE the actual signal repetition is occuring and what it looks like. It might be wise to grab an oscilliscope and check, serially, every output and every input in the signal path until the repetition is found. At that juncture, you'll then know how to properly deal with it.
As a general rule, signal conditioning, to be most effective, needs to be done as close to any source of "interference" as is humanly possible. If for some reason the photo-electric sensor is spitting out a signal that looks like it came from output pin of a 555 timer, then all the de-bouncing in the world two or three stages down the road, will be quite ineffective in turning it back into a one-shot pulse.
Just an outside pair of eyes chiming in
Regards,
Bruce Bates
Post Edited (Bruce Bates) : 10/11/2005 7:11:28 AM GMT
·· Mr. Jenkins already pointed out that he had no scope.· To that end, a workaround was suggested which might reveal the source of the jitter, or at least rule out one device when it was suggested he replace the currently connected device with a push-button.· Not very hi-tech, but will at least narrow the problem down significantly to the Stamp Input.· Jon also suggested an alternative which would potentially isolate the bounce/jitter problem.· these are currently being tested.· I guess my point is, sometimes you need lo-tech.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 10/11/2005 2:22:40 PM GMT
I replaced my mechanical radioshack relay with a vn012 optical relay (thanks Jon W) and am still having problems. I used the code that Jon W suggested (thanks again), but it did not work well and I had to modify it
' {$STAMP BS2sx}
' {$PBASIC 2.5}
IncCount PIN 5
myCount VAR Word
Reset:
myCount = 0
Main:
DO
IF (IncCount = 1) THEN
PAUSE 100
IF (INccount = 0) THEN
myCount = myCount + 1
DEBUG HOME, "Count is ", DEC3 myCount
PAUSE 100
ELSE
PAUSE 100
ENDIF
ELSE
PAUSE 100
ENDIF
LOOP UNTIL (myCount > 10)
GOTO Reset
I still get a bounce off of this and get a couple of false positive. Anyone have any neat thoughts? I will tryChris's button later this weekend. And I will post the circuit I built a little later.
In other news, I bought one of the USB osciliscopes from Parallax and it arrived today. I just opened it and will play with it, but I need to learn how to use the unit now and need to figure out how to apply this to problem.
Thanks, everyone.
I tried the suggestion that Chris Savage suggested and put in a push button on the relay.· This was cool - I was able to see the bounces that I had in the past.· This tells me that the problem is very probably not the relay, but something bouncy inside the circuitry.·
I reviewed the circuit, drew it up and attached it.·
I am looking at the circuitry, but nothing appears to be the problem.·· I have now have a oscilloscope, but I don't know how to use it.· Can anyone suggest how to use it with this problem, or give me a plan of attack.
Thanks
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Thanks everyone.
Still having problems with the Allen Bradley Sensor.· Two problems:
Oscilloscope:· When I hook up the Parallax Ocilloscope to the circuit, the debug mode shuts down and I cannot test the circuits.· Weird.· Attached Diagram shows the circuit and the hookup.
1) What Am I messing up Here?
2)· I really liked the idea that Jon put together and the ideas behind it.· I would like to use an opto transistor like he shows in the diagram to eliminate all bounce, but my work with the 3908 and the 4n26 has not worked.· Jon, could I have a little more description of the circuit and the·use of a 22·K resistor?·
I apologize for my ignorance.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
How about BUTTON BTN,1,255,20,BtnWrk,1,readlight?
How about adding a·1K resistor between the "high side" of the switch contacts and VDD?
Thanks everyone·for your help.· I am attaching the Allen Bradley sheets for the 42KL-U2LB-F4 unit that I am using.· I put the relay in as because I thought it would help isolate the Basic Stamp from any high voltage, but I am extremely interested in doing whatever you suggest and will do what every you suggest.· (Details would be extremely welcome and very helpful.)··
Thanks again.
Dave
1)·Put a 10K pull-up (not down, as in your original circuit) on your BASIC Stamp input pin
2) Connect BASIC Stamp Vss to Ground on the sensor -- should be pin 3 (see pdf link below)
3) Connect BASIC Stamp input pin to NPN output on the sensor·-- should be pin 2
Run this little test program:
Main:
· DEBUG Home, BIN1 IN0
· GOTO Main
Don't get crazy if it shows you a 0 for a condition where you want a 1 -- PBASIC can invert this in code:
Main:
· DEBUG Home, BIN1 ~IN0
· GOTO Main
Using an active-low input is easier when you have different device voltages; ground is common, so switching to it is not a problem.· And as I just showed you, PBASIC will handle making an active-low input look active-high.
This is the document I used for reference: http://www.ab.com/catalogs/sensors/catalognumberpdf/ch1/1-39_1-53.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 10/23/2005 4:17:51 PM GMT
Best
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Here is a drawing of the circuit that I would like to put together.· Does this show the circuit you described?· The "WHAT IS A MICROCONTROLLER" book, on page 79, the circuit shows using a Vdd with a 10 k resistor, but I am not sure how to include it, unless I do what I show in yellow on the attached?
Thanks!
Dave
Thanks
Dae
·· I just looked up the part on the Allen-Bradley website and per your diagram I would recommend having the 10K pull-up on the white wire as it exits the device.· You should only have a 220 ohm resistor between the white wire and the Stamp I/O pin though.· When the device is not active you will get a HIGH/1 on the I/O pin.· When the device is triggered you will see a LOW/0 on the I/O pin.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Addition: Your wiring connections are backward -- please read your AB docs carefully; pin 3 is ground (connect to the Stamp's Vss pin), pin 2 is the switched connection (connect to your input).· This information is in the graphic you provided.··Remember, this is a transistor (even though they simplify the diagram as a switch)·and it must be correctly biased to conduct.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 10/23/2005 10:41:01 PM GMT
·· Yes, sorry if I wasn't clear...I was just made aware of your separate power supply...I didn't see that connection in your schematic.· Always try to include all data in the schematic when you include one.· · You don't want to pull-up to the other supply, otherwise you could burn a Stamp I/O pin.· Physically though the device should be the equivalent of a transistor, so pulling it up to the Stamp Vdd should work just as any standard transistor, so long as the ground (Vss) is common to the device.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Is this a reasonable design?··
(This is for work.· I will send you a picture of the $275 custom box I have made for it if you want.)
Dave
·· I think you have it now.· That should work.· Good luck, and sure, post your cabinet picture.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
We're all hoping this finally works -- you've been at it a little while now.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Initially, it looks really really good. What a relief.
Seriously, Thanks a lot.
I took the liberty of sending you some almonds. Should be there end of week or early next week. Hope Chris and Jon work in same general area.
Really appreciate your help
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax