Shop OBEX P1 Docs P2 Docs Learn Events
INPUT Command Help — Parallax Forums

INPUT Command Help

ajs2001txajs2001tx Posts: 25
edited 2005-10-01 23:29 in BASIC Stamp
After reading the syntax guide I still have a question.·

I have a limit switch that am going to connect to ground and when the limit switch is toggled I want it to obviously pull·a pin low.· Because I don't want to pull two wires about 30 feet on a piece of equipment instead of just one.· So is that just done by:

LS PIN 1·····

INPUT LS···· 'Setting the LS pin as an input

????

I am being thrown a curve by the following wording from the PBASIC Help INPUT section.

[img]mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2\PBASIC.chm::/graphics/bs2all_inline.gif[/img]
Setup: INPUT 4Hold: IF (IN4 = 0) THEN Hold ' Stay here until P4 is 1
The code above will read the state of P4 as set by external circuitry. If nothing is connected to P4, it will alternate between states (1 or 0) apparently at random.

How fast is the alternation?·

And then if it as at a 1 then pulled to a 0 will it then "learn" and stay at a 1 waiting on the next 0?

I am just a farmer trying to automate piece of equipment so be patient with me on learning a new language like PBASIC.· ha ha.

Thanks for your help.

Andy

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-01 19:01
    Andy,

    ·· Unconnected inputs are said to be "floating".· This means the line isn't being pulled HIGH or LOW.· Stray EMI can cause the line to do just about anything.· There is no pattern.· Sometimes it won't toggle at all, but it will usually.· For this reason a pull-up to the opposite of the active state is used.· If your input (Pushbutton) is active LOW, then you would use a 10K resistor to pull the line HIGH when the button isn't pressed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ajs2001txajs2001tx Posts: 25
    edited 2005-10-01 20:31
    Chris,

    ···· Thanks for responding.· I understand now.· I have read about pullup and pull downs in Scott Edwards' book no less than 15 times but for some reason you just brought it home for me.· So I guess I would use the INPUT command in the code then?

    ··· As a discussion topic,·his book also says that it really doesn't matter what size resistor you use but keep it between 1k and 100k.· So in an effort to make things more difficult than they have to be, if you had to choose between only a 1k or 100k which would you choose?· And would the choice be the same for both pull up and pull down?

    Thanks again,

    Andy

    Post Edited (ajs2001tx) : 10/1/2005 8:39:51 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-01 21:05
    Andy,

    ·· By default, on power-up the BASIC Stamp I/O pins are inputs.· Unless you make them outputs, or use a command which does so, such as HIGH, LOW, etc. they remain INPUTs.· So in your code you don't need to specify a pin as an input at the beginning.·

    ·· Another approach is to define the state of all the pins right at the beginning of your code with one line of code.· You can use DIRS = %1111000011110000 as an example to make P0 - P3 inputs (Remember, binary reads right to left), P4 - P7 outputs, P8 - P11 inputs and P12 - P15 outputs.· Until changed, either by the DITS register, or by a command, such as mentioned above, they will remain this way.· You can also define groups of pins, but that is covered in the manual and/or help files·as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ajs2001txajs2001tx Posts: 25
    edited 2005-10-01 21:15
    Can a few pins share the same pull up or pull down?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-01 21:21
    Not a good idea.· Resistors are cheap, so it's better to have them all on different resistors.· In order for a pin to share a resistor, it would have to be shorted to it's neighbor.· At this point it would no longer be a separate I/O pin, but would follow it's neighbor.· Do you see what I mean?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ajs2001txajs2001tx Posts: 25
    edited 2005-10-01 21:25
    Well that is what I thought, but·on a pull up they are all "common" through Vdd on the other side of resistor.· But that is obviously the wrong way to think about it from what you are saying.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-01 23:29
    Because there is a difference in potential on the other side of the resistors the I/O pins can still be forced to the opposite state.· The way you suggested, that could never happen.· If you have two button sharing a pull-up resistor and you press one, it forces both low, since they're effectively connected together.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.