Newbie IO Question on BS2
savage
Posts: 3
Hello fellow members, total newbie here trying to get better understanding of how the stamp chip's IO works, specifically the input.
(I have BS2 on a Board of Education)
If I drive +5VDC from the VDD on the board of education through a 10K resistor and into PIN0, it will set the IN0 to a value of "1".· However, when I remove the +5VDC from PIN0, the IN0 remains with a value of "1" and does not reset to "0" unless I ground out PIN0.·
Is this the expected behavior?· If so, how do I write my program to properly monitor inputs?· My sample program is below...
Thank You,
· ...Savage...
(I have BS2 on a Board of Education)
If I drive +5VDC from the VDD on the board of education through a 10K resistor and into PIN0, it will set the IN0 to a value of "1".· However, when I remove the +5VDC from PIN0, the IN0 remains with a value of "1" and does not reset to "0" unless I ground out PIN0.·
Is this the expected behavior?· If so, how do I write my program to properly monitor inputs?· My sample program is below...
' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[noparse][[/noparse] (I/O) Output Definitions ]------------------------------------------ SENSOR1 PIN 0 ' (I/O) Sensor ' -----[noparse][[/noparse] (Program Variables Definitions ]------------------------------------ SENSOR1_LastKnownState VAR Byte ' -----[noparse][[/noparse] (Program Initialization ]------------------------------------------- INPUT SENSOR1 ' -----[noparse][[/noparse] (Program Mainline ]------------------------------------------------- Mainline: ' check for changes from last known state IF (SENSOR1 <> SENSOR1_LastKnownState) THEN ' display new status IF (SENSOR1 = 0) THEN DEBUG "SENSOR1 IS <OFF>",CR IF (SENSOR1 = 1) THEN DEBUG "SENSOR1 IS <ON>",CR ' debug DEBUG "SENSOR1 STATE: ",BIN1 SENSOR1,CR ' syncronize SENSOR1_LastKnownState = SENSOR1 ENDIF ' slow things down a bit PAUSE 100 ' infinite mainline program loop GOTO Mainline EndProgram: END
Thank You,
· ...Savage...
Comments
The reason for using the resistor is that these pins can also be used as outputs and you might accidentally program them as such. If so and the output state is opposite from what the pin is connected to ... you'll burn out the I/O pin circuitry on the chip. The resistor prevents the damage by limiting the current.
Maybe I would be better off further explaining what I am trying to do and perhaps there is a problem with my circuit. I would like to use a magnetic contact closure sensor such as are found in alarm systems to control in input on the stamp (PIN0). Then I can perform whatever programming logic when the switch is closed/opened.
[noparse][[/noparse]+5VDC]
>[noparse][[/noparse]Contact Closure Switch]
>[noparse][[/noparse]10K Resistor]
>[noparse][[/noparse]Stamp Input Pin (IN0)]
Can I simply control the IN0's HI/LO state by sending the +5VDC like this?
The issue I am seeing is that PIN0 will go HI, but will not return to LOW when the voltage is removed.
So you said that when the PIN is open, it can pickup ambient voltage from moisture, etc, what do I need to add to prevent this and force the PIN LOW when the contact closure switch is open?
Thanks,
...Savage...
Jeff T
Thanks! That did the trick. I have a background in software, not hardware, so I'm still learning basic circuit logic
Thanks again... and also thank you Mike for helping shed some light,
...Savage....