Switching Input Problem BS2
wvmusic
Posts: 4
I've been using a BS2 as a controller system to switch direction on a small DC motor. In the past I was using two switches for each direction. Ive incorporated a couple MOSFETs to help with the switching, but now I have a new issue.
When I send a signal to one of the input pins, it latches into place. I put a line of code to give me the input status of my switches and sure enough, once given +5, it latches into place until given a ground. It has not always been this way, wondering if I may have @!%#-ed something up on my BOE or on my BS2.
If anyone has any ideas on why my INPUT latches and won't go to 0 unless I verify ground I would appreciate it. As I said, in the past, I was able to simply not toggle the switch and it would go to 0. I'm not using a latching command or loop. This same principle worked just fine a month ago, and though Im using MOSFETs, even when I remove them and go back to the original setup, the switches are latching.
I know it is messy, but here is my code for controlling a bi-directional motor based on switched inputs and the height status of two PING sensors. It's a mock lift system that accounts for descent position and the user must verify certain characteristics of the system before completing the descent. Thanks for the help.
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM7}
Ping PIN 14
Ping2 PIN 15
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)
IsHigh CON 1 ' for PULSOUT
IsLow CON 0
height1 VAR Bit
height2 VAR Bit
safety1 VAR Bit
safety2 VAR Bit
rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word
Trigger2 CON 5 ' trigger pulse = 10 uS
rawDist2 VAR Word ' raw measurement
inches2 VAR Word
cm2 VAR Word
safety1 = 0
safety2 = 0
height1 = 0
height2 = 0
lower VAR Bit
lower2 VAR Bit
compare VAR Bit
on1 VAR Bit
on2 VAR Bit
up1 VAR Bit
down1 VAR Bit
Reset:
DEBUG CLS,
"Parallax PING))) Sonar", CR, ' setup report screen
"======================", CR,
CR,
"Time (uS)..... ", CR,
"Inches........ ", CR,
"Centimeters... ", CR,
" ", CR,
"Time 2 (uS) ", CR,
"Inches2....... ", CR,
"Centimeters2.. ", CR,
" ", CR,
"Tilt Status... ", CR,
"Switch Status. ", CR,
"CONTROL STOP. . ", CR,
"up. ", CR,
"down. . ", CR
Main:
DO
GOSUB Get_Sonar
GOSUB Get_Sonar2 ' get sensor value
inches = rawDist ** RawToIn ' convert to inches
cm = rawDist ** RawToCm ' convert to centimeters
inches2 = rawDist2 ** RawToIn ' convert to inches
cm2 = rawDist2 ** RawToCm ' convert to centimeters
GOSUB switches
DEBUG CRSRXY, 15, 3, ' update report screen
DEC rawDist, CLREOL, CRSRXY, 15, 4,
DEC inches, CLREOL, CRSRXY, 15, 5,
DEC cm, CLREOL,CRSRXY,15,7,
DEC rawDist2, CLREOL,CRSRXY,15,8,
DEC inches2, CLREOL,CRSRXY,15,9,
DEC cm2, CLREOL
DEBUG CRSRXY, 15, 11,
BIN safety1, CLREOL , CRSRXY, 15, 12,
BIN safety2, CLREOL, CRSRXY, 15, 13,
BIN height1, CLREOL, CRSRXY, 15, 14,
BIN up1, CLREOL, CRSRXY, 15, 15,
BIN down1, CLREOL
IF(IN3 = 1) THEN
up1 = 1
ENDIF
IF(IN3 = 0) THEN
up1 = 0
ENDIF
IF(IN2 = 1) THEN
down1 = 1
ENDIF
IF(IN2 = 0) THEN
down1 = 0
ENDIF
PAUSE 10
LOOP
END
switches:
IF(inches>inches2) THEN
height2 = inches-inches2
IF(height2<= 1) THEN
compare = 1
ELSE
compare = 0
ENDIF
ELSEIF(inches2>inches) THEN
height2 = inches2 - inches
IF(height2 <= 1) THEN
compare =1
ELSE
compare = 0
ENDIF
ENDIF
IF(inches <2) AND (compare = 1) THEN
height1 = 0
safety2 = 0
ENDIF
IF(inches > 5) AND (inches<8) AND (compare = 1) AND (safety2 = 0) THEN
height1 = 1
ENDIF
IF (inches< 6) AND (compare = 1) AND (height1 = 1) AND (safety1 = 1) AND (safety2 = 1) THEN
height1 = 0
ENDIF
IF(inches>=8) AND (safety2 = 1)AND (compare = 1) OR (safety1 = 0) THEN
safety2 = 0
ENDIF
IF(safety2 = 1) AND (inches<8) AND (compare = 1) THEN
lower2 = 1
ELSE
lower2 = 0
ENDIF
IF(height1 = 1) AND (inches < 6) AND (compare = 1) AND (safety1 = 1) AND (IN1 = 1) OR (lower2 = 1) THEN
safety2 = 1
ENDIF
safety1 = 1
IF(inches<13) AND (IN3 = 1) THEN
HIGH 7
HIGH 6
ELSE
LOW 7
LOW 6
ENDIF
IF(inches>5) AND (compare = 1) THEN
lower = 1
ELSE
lower = 0
ENDIF
IF(inches>1)AND (compare = 1) AND (height1 = 0) AND(safety1 = 1) AND (IN2 = 1) OR(lower = 1)THEN
HIGH 4
HIGH 5
ELSE
LOW 4
LOW 5
ENDIF
RETURN
Get_Sonar:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN
Get_Sonar2:
Ping2 = IsLow ' make trigger 0-1-0
PULSOUT Ping2, Trigger2 ' activate sensor
PULSIN Ping2, IsHigh, rawDist2 ' measure echo pulse
rawDist2 = rawDist2 */ Scale ' convert to uS
rawDist2 = rawDist2 / 2 ' remove return trip
RETURN
When I send a signal to one of the input pins, it latches into place. I put a line of code to give me the input status of my switches and sure enough, once given +5, it latches into place until given a ground. It has not always been this way, wondering if I may have @!%#-ed something up on my BOE or on my BS2.
If anyone has any ideas on why my INPUT latches and won't go to 0 unless I verify ground I would appreciate it. As I said, in the past, I was able to simply not toggle the switch and it would go to 0. I'm not using a latching command or loop. This same principle worked just fine a month ago, and though Im using MOSFETs, even when I remove them and go back to the original setup, the switches are latching.
I know it is messy, but here is my code for controlling a bi-directional motor based on switched inputs and the height status of two PING sensors. It's a mock lift system that accounts for descent position and the user must verify certain characteristics of the system before completing the descent. Thanks for the help.
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM7}
Ping PIN 14
Ping2 PIN 15
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)
IsHigh CON 1 ' for PULSOUT
IsLow CON 0
height1 VAR Bit
height2 VAR Bit
safety1 VAR Bit
safety2 VAR Bit
rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word
Trigger2 CON 5 ' trigger pulse = 10 uS
rawDist2 VAR Word ' raw measurement
inches2 VAR Word
cm2 VAR Word
safety1 = 0
safety2 = 0
height1 = 0
height2 = 0
lower VAR Bit
lower2 VAR Bit
compare VAR Bit
on1 VAR Bit
on2 VAR Bit
up1 VAR Bit
down1 VAR Bit
Reset:
DEBUG CLS,
"Parallax PING))) Sonar", CR, ' setup report screen
"======================", CR,
CR,
"Time (uS)..... ", CR,
"Inches........ ", CR,
"Centimeters... ", CR,
" ", CR,
"Time 2 (uS) ", CR,
"Inches2....... ", CR,
"Centimeters2.. ", CR,
" ", CR,
"Tilt Status... ", CR,
"Switch Status. ", CR,
"CONTROL STOP. . ", CR,
"up. ", CR,
"down. . ", CR
Main:
DO
GOSUB Get_Sonar
GOSUB Get_Sonar2 ' get sensor value
inches = rawDist ** RawToIn ' convert to inches
cm = rawDist ** RawToCm ' convert to centimeters
inches2 = rawDist2 ** RawToIn ' convert to inches
cm2 = rawDist2 ** RawToCm ' convert to centimeters
GOSUB switches
DEBUG CRSRXY, 15, 3, ' update report screen
DEC rawDist, CLREOL, CRSRXY, 15, 4,
DEC inches, CLREOL, CRSRXY, 15, 5,
DEC cm, CLREOL,CRSRXY,15,7,
DEC rawDist2, CLREOL,CRSRXY,15,8,
DEC inches2, CLREOL,CRSRXY,15,9,
DEC cm2, CLREOL
DEBUG CRSRXY, 15, 11,
BIN safety1, CLREOL , CRSRXY, 15, 12,
BIN safety2, CLREOL, CRSRXY, 15, 13,
BIN height1, CLREOL, CRSRXY, 15, 14,
BIN up1, CLREOL, CRSRXY, 15, 15,
BIN down1, CLREOL
IF(IN3 = 1) THEN
up1 = 1
ENDIF
IF(IN3 = 0) THEN
up1 = 0
ENDIF
IF(IN2 = 1) THEN
down1 = 1
ENDIF
IF(IN2 = 0) THEN
down1 = 0
ENDIF
PAUSE 10
LOOP
END
switches:
IF(inches>inches2) THEN
height2 = inches-inches2
IF(height2<= 1) THEN
compare = 1
ELSE
compare = 0
ENDIF
ELSEIF(inches2>inches) THEN
height2 = inches2 - inches
IF(height2 <= 1) THEN
compare =1
ELSE
compare = 0
ENDIF
ENDIF
IF(inches <2) AND (compare = 1) THEN
height1 = 0
safety2 = 0
ENDIF
IF(inches > 5) AND (inches<8) AND (compare = 1) AND (safety2 = 0) THEN
height1 = 1
ENDIF
IF (inches< 6) AND (compare = 1) AND (height1 = 1) AND (safety1 = 1) AND (safety2 = 1) THEN
height1 = 0
ENDIF
IF(inches>=8) AND (safety2 = 1)AND (compare = 1) OR (safety1 = 0) THEN
safety2 = 0
ENDIF
IF(safety2 = 1) AND (inches<8) AND (compare = 1) THEN
lower2 = 1
ELSE
lower2 = 0
ENDIF
IF(height1 = 1) AND (inches < 6) AND (compare = 1) AND (safety1 = 1) AND (IN1 = 1) OR (lower2 = 1) THEN
safety2 = 1
ENDIF
safety1 = 1
IF(inches<13) AND (IN3 = 1) THEN
HIGH 7
HIGH 6
ELSE
LOW 7
LOW 6
ENDIF
IF(inches>5) AND (compare = 1) THEN
lower = 1
ELSE
lower = 0
ENDIF
IF(inches>1)AND (compare = 1) AND (height1 = 0) AND(safety1 = 1) AND (IN2 = 1) OR(lower = 1)THEN
HIGH 4
HIGH 5
ELSE
LOW 4
LOW 5
ENDIF
RETURN
Get_Sonar:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN
Get_Sonar2:
Ping2 = IsLow ' make trigger 0-1-0
PULSOUT Ping2, Trigger2 ' activate sensor
PULSIN Ping2, IsHigh, rawDist2 ' measure echo pulse
rawDist2 = rawDist2 */ Scale ' convert to uS
rawDist2 = rawDist2 / 2 ' remove return trip
RETURN
Comments
Could you edit your post? Thanks much.
DJ
Anyways, Ill try the pull-up resistors and see if I get a better result. Thanks for the help.
Also, if your whole point in replying to my post is to criticize me, please find something better to do with your time. I'm new to Microcontrollers and appreciate the help.
Maybe that way you will not get comments on the format. Or maybe not - some folks just like to make noise. If you cannot impress with briliance, dazzle them with BS.
.
Anyway - I would check
Ping = IsLow ' make trigger 0-1-0
If you are setting the Ping low - I did not see anywhere in your code setting the direction of that pin to output.
Personnaly I would read the state ot the pin first, just to make sure.
From your description it was not clear to me what exactly you changed in hardware from you originally working code.
(That's why I did not make my initial comment on pull-up / pull- down resistors.)
Vaclav
IF(IN3 = 1) THEN
up1 = 1
ENDIF
IF(IN3 = 0) THEN
up1 = 0
ENDIF
IF(IN2 = 1) THEN
down1 = 1
ENDIF
IF(IN2 = 0) THEN
down1 = 0
ENDIF
can be crunched down to
UP1=IN3
DOWN1=IN2
or since your program appears to check them each loop, you can simply use aliases, or simply refer to them in your following code as IN3 (instead of UP1) and IN2 (instead of DOWN1).
"People really mad about my language? Are we children?" - we aren't, but there are plenty of children that frequent these forums. Will you please edit your post?
Are we children?..........> No but we have Forum members that ARE under the age of 18 years old So if you feel the need to swear Please use this ******* or nothing at all
I do not argee with you on these points
Here is why because by what you are saying are we setting a GOOD example of how to ack on this forum ?
The idea is that the pull-up or pull-down resistor is "just enough" to make the circuit a 0 or 1, but any input from the outside will be so much stronger that the input will change. Common values for pull-up or pull-downs are 5k-20k. If you connect an input pin through a 10k resistor to 5v, that pin will always see 1. But if a switch connected *directly* to the pin is switched to ground, the incoming 0 (ground) is so much "stronger" than the 5v coming through the 10k resistor that the input pin will see a 0. When the switch is released, the circuit is immediately "pulled" back to 5v.
You often see pull-ups or pull-downs on transistor bases for the same reason, so the input of the transistor does not "float around" and accidentally switch on or off.
The Stamp manual and "What's a Microcontroller" both have examples of using pull-ups and such.
P.S. -- to everyone else, wv seemed still unclear on *why* the pullup resistors were necessary, yet the thread descended into bickering over whether or not it is OK to edit a post for vulgar langauge, and the original question remained somewhat unanswered. Given that a huge portion of Parallax's promo material and writing efforts are geared towards the elementary, middle-, and high-school educational markets, it's a no-brainer that foul language is going to be -- and should be -- heavily redacted. Personally, I see no reason to use such language in an online community anyway (and believe me, I swear like an old-time sailor at home).