Shop OBEX P1 Docs P2 Docs Learn Events
BS2 output problems.. — Parallax Forums

BS2 output problems..

mikhael10121mikhael10121 Posts: 1
edited 2008-12-09 20:31 in BASIC Stamp
Hi there..

I just want to tell you that I was trying to use the basic stamp in my project. all what I needed to do is that I have 8 bits input (2 out of 8 are going to be high each time) and for each input I want to set up different pin high.

I wrote a code for it but somehow pin 9 (which should be an output pin) is always high. attached you can find my code after I changed it and made it one input pin high only and pin 9 stayed always high.

on my schematic I have pin 3 and 23 grounded and 5 V on pin 21.

Thanks for any help....

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-12-07 03:03
    First

    Let me welcome you to the Parallax Forum



    How are you·hooking these·INPUT PINS·up

    Do you ·have 10 k ohm resistor to VSS pin· to the INPUT pin
    And
    ·Do you have·a 220 ohm resistor·from·to the switch to VDD·and from the switch to the Basic Stamp PIN


    ·THIS IS A MUST if do not have your set up this way it will not work

    Also you need to do this to each INPUT PIN the same



    If you are using a optic sensor like a 4N25 then you do it like this· you may not need 24 volts on the input side

    your resistors will be lower for five volt would be ·about· 1 kohm or so· but the side that hook to the Basic

    Stamp would be the same·

    The name of the file is misleading 24 Volt Power Supply.jpg·· but it show how to hook up a optic sensor like the 4N25·



    One more thing the resistor that dose not have a value is 10 k ohm







    I hope that this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 12/7/2008 4:03:10 AM GMT
    1344 x 992 - 163K
    1696 x 944 - 95K
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-12-07 17:23
    What is the nature of the equipment that supplies the input to p0 through p7? If these are contact closures, then sam_sam_sam is correct and you need pullup (or pulldown) resistors. If, on the other hand, these are voltage levels that change from 0 to 5 volts, then you won't need any resistors unless you wish to use series resistors to protect the input pins in case of an input going outside the range 0-5 volts.

    Looking at your code, if no input (p0 through p7) is high, then none of your IF statements will branch, and you will fall into the code you label "nine:", and pin 9 will always be high because you put it high for 1/2 second, then put it low and instantly go to MAIN and quickly put it high again. Actually it will have dropped with your LOW 9 statement, but you set it high again very quickly.

    I'm guessing that what sam_sam_sam was trying to say is correct, and that your input circuits are not working as you expect them to. Have you actually measured the volages at your inputs (p0 through p7)?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-12-08 16:11
    Sam your schematic for the opto shows one lead of the phototransistor going to Vdd and the other to Vcc, which is usually the same circuit or a separate supply. Typically the emitter would go to ground (Vss) and the collector would be pulled high by a 10K resistor. The collector would also be connected to an I/O pin via a 220 series resistor for protection.

    The logic would be, if the LED was on the output would be LOW, otherwise it would be high. If you need it to be active high in the code you can read it inverted by putting a ~ in front of the pin constant.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-12-08 22:27
    Chris

    Thank You for point this out to me VCC should have been VSS I wrote the wrong label

    Typically the emitter would go to ground (Vss) and the collector would be pulled high by a 10K resistor. The collector would also be connected to an I/O pin via a 220 series resistor for protection.
    Thank You pointing this out to me as well

    The logic would be, if the LED was on the output would be LOW, otherwise it would be high. If you need it to be active high in the code you can read it inverted by putting a ~ in front of the pin constant.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-12-09 20:31
    It is a personal preference really more than anything else…but I tend to connect things, including opto-isolators conventionally and then deal with differences in code. For example…in a typical configuration that would end up being an active LOW input. So each time I read or test the status of the pin, I add a ~ (tilde) in front of the designator. For example:

    IF LeftIn = 0 THEN ‘ LOW when input is active

    becomes

    IF ~LeftIn = 1 THEN ‘ HIGH when input is active

    Another benefit to handling things like this in code is that you can handle certain unforseen changes to hardware.· Once I connected a keypad on a customer board and for whatever reason the connector would not fit in the normal manner.· It ended up being reversed making all my connections backward.· But in code it is so easy go from SHIFT-LEFT to SHIFT-RIGHT when scanning.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.