Shop OBEX P1 Docs P2 Docs Learn Events
so if...... — Parallax Forums

so if......

cyplesmacyplesma Posts: 76
edited 2007-09-12 17:36 in BASIC Stamp
I have pins 0-7 set to be inputs

If I put a 5 volt (through the pullup resistor as noted on page 76 of the "What's a Microcontroller book) on any of these pins then I get a one back on all of them.

is the inputs on the stamp fried.

if i set one up as an output then just that pin goes high not the rest.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-09-12 04:55
    Hello,

    When input pins are not being driven or pulled HIGH/LOW they are floating and are easily influenced by the signals around them. Floating lines are not reliable to read so you should just read the lines you’re connected to unless you plan to pull-up/down the remaining lines. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • skylightskylight Posts: 1,915
    edited 2007-09-12 09:12
    would it then be better to assign all unused pins as outputs to save having to tie them down?
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-09-12 13:04
    Not really. The problem with pins assigned as outputs is if you later decide to use them, and tie one to ground or to +5, and forget to change your program, you'll burn out the pin.

    That's why on reset all pins are assigned as inputs -- that's the safe default value. And yes, you as a programmer need to learn that "reading an unassigned input" gives you garbage -- but that's MUCH better than accidentally burning out a pin.
  • cyplesmacyplesma Posts: 76
    edited 2007-09-12 13:18
    well their not unused pins.

    I'm trying to use pins 0-7

    I would like to use pins 2,3,5 as outputs or is intermixing pins like this a problem.

    If I set say pin 1 to 4vdc then I get a reading of 11111111 when I do the INL statement
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-09-12 13:45
    Let's see.

    ' 7, 6, 5, 4, 3, 2, 1, 0
    ' o, o, i, o, i, i, o, o
    '
    So, your input should be like: MyVal = INL & %00101100

    If you really don't have anything tied to pins 5,3, and 2, then they're "unused", and you can't depend on the value you read from them.

    So no, intermixing pins like this is not a problem, and if you DID have something tied to 5,3,2 you'd read that value, not the output value from pin 4.
  • cyplesmacyplesma Posts: 76
    edited 2007-09-12 13:55
    almost...

    pins 5,3,2 are outputs, I turn them one one at a time.

    when 2 is on 5,3 are off.

    I then read all 7
    I get "100" which is good.

    I then place 4vdc on pin 1
    I get "11111111" with pull up resistors which is not good. I should only get "110", right?

    I have tried it with pull down resistors (which gives me "100" constantly)
  • Lee HarkerLee Harker Posts: 104
    edited 2007-09-12 14:04
    Generally if you are not using a pin at all, then you should ignore its value when you read the port. If you are reading the value of a pin, you must make sure that the input is controlled in some way that you can be certain of its value. No floaties!·nono.gif··Also when you are grouping pins with some as outputs and some as inputs, it's best to use an organized scheme. If you group the pins 2,3 and 5 as input and 1,6 and 7 as output it is legal but allows a greater chance of confusion. It's handy if you maybe make pins 0-3 inputs and 4-7 as outputs or similar fashion. That way you can refer to the groups as nibbles. It can make your programming easier.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-09-12 14:09
    The real problem is that your inputs aren’t connected to anything…If they were they would not be floating and giving you the results you’re getting. When inputs are connected to ‘open’ devices such as switches they require either pull-up or pull-down resistors depending on the active mode of the switch.

    As for the question about making unused pins output…there are two schools of though on this. One is that the unused pins should be made outputs and set low. This is fine as long as you don’t connect an input device. Of course, catastrophes can happen in accidentally connecting an output pin if you change your hardware before changing your program too so I don’t see an issue with this. Just be careful and know those pins are outputs.

    The other school of thought says the pins should be weakly pulled-up or down. This is fine as well. You can get SIP resistor networks that are bussed and make it very easy to add pull-ups/downs to eight pins at once. Of course, you should really be reading a pin not connected to anything, but on the other hand oscillating open input pins can cause the microcontroller to use slightly more current when running. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • skylightskylight Posts: 1,915
    edited 2007-09-12 17:00
    I can understand the concerns raised about outputs accidently being overloaded, but isn't this true of other circuits put together haphazardly without forethought?

    In a working circuit if·certain·pins are not going to be used period then what's wrong with saving on component count and extra circuitry by assigning them as outputs?

    It's a foolish person that alters the software without checking what implications it has on the hardware connected or indeed leaving the hardware connected up or not altering it accordingly when changing the code

    What's confusing is that cyplesma first states that 0-7 are inputs then later states 5,3,2 are outputs? Maybe this is where things have gone wrong and they should be assigned outputs from the start that get turned on or off dependant of the state on pin 1?
    ·
  • cyplesmacyplesma Posts: 76
    edited 2007-09-12 17:11
    well what I'm trying to do is turn on/off a bank of switches.

    similar to a key matrix, but I was trying to do it without the RC circuit.

    I have 3 sets of 5 switches.

    granted the pin layout could be less confusing (for program, not for the wiring), but...

    I only have one bank of switches active at a time. So I figured I could just send a 1 from an output (pin 2) to it's 5 switches and collect the switch pressed by reading the INL but maybe I just need to read the IN bits instead. I was saving the value of INL to a byte and sending that to the debug window to verify that I have the switches wired the way I want them, but I get "11111111" on all 8 bits. when I press a switch.

    if I don't have a switch pressed, I get "00000100" which tells me the switches for pin 2 are active.

    Post Edited (cyplesma) : 9/12/2007 5:18:16 PM GMT
  • skylightskylight Posts: 1,915
    edited 2007-09-12 17:21
    ok makes sense now, yes you will need to tie the inputs as you are using switches.



    Am I right in thinking·the problem is as stated before by mixing inputs and outputs together and then trying to read the·pin values with an INL you are trying to read·states of·a low byte of pins of which some have been assigned as outputs therefore isn't this confusing the outcome?

    It must be better to seperate the inputs from outputs then you can read them without confusion.




    Post Edited (skylight) : 9/12/2007 5:35:16 PM GMT
  • cyplesmacyplesma Posts: 76
    edited 2007-09-12 17:36
    well that's kinda what I figured and did. I basically went back to the manual "what's a microcontroller" and retried the switch input again with both the pull up and pull down resistors.

    when I did this the first time a few months back I didn't notice if the other pins were doing anything or not I got the "1" when I wanted it too and didn't bother to check the other pins.

    but now that I have a need to check/use the pins this is when I find out what is happening.

    Now I do have my own resistor pack. I wired it up on a perf board it's basically 8 resistor networks where all the 10K resistors are tied to a common lead that can be plugged into vss or vdd and the connection between the resistors are connected by a wire that can be plugged into the breadboard, same for the other end of the 220 resistor. FYI: I also have a switch and a pot soldered onto this board, their pins connect to individual wires as well does not connect to the resistor network.

    but using just 5 of these PU/PD networks (for the 5 inputs) I either get 1.04v or when I get the 4.5v all the pins go high when I press any switch of the activated bank of switches.
Sign In or Register to comment.