Shop OBEX P1 Docs P2 Docs Learn Events
DIR OUT affect on pull-down sink current — Parallax Forums

DIR OUT affect on pull-down sink current

BS2ILHBS2ILH Posts: 9
edited 2009-12-26 18:46 in Learn with BlocklyProp
Hello all Stamps

I have a BOE BS2 with 6 pull-down switches, 2 LEDs, 1 photoresistor, 1 piez-speaker, 1 IR detector, and 5 servos.

All are wired as in the What's a Microcontroller manual. They operate serially (sp?) so there is no concern of using more than 1 item at a time (Current max drain). The question is :

Should i be changing the DIR or OUT of these just before and after i use them to eliminate ANY current drain .. as they might add up, i dont know. or PIN1 LOW ?

Actually DIR and OUT etc confuse me... but that would take a different and long response from someone.. later. Maybe i am not using I/O in a way that they (DIR IN OUT ) are needed. The code for the switches is usually : IF (RotarySwitch = 1) then GOSUB Something. The LEDS are simply flashed sometimes and the Servos use PULSOUT - which AFAIK changes the DIR IN OUT etc on its own. SO should i be changing DIR or OUT or IN to something to eliminate current drain ?

Thank you.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-24 00:06
    I think you're getting a bit too worked up about current demand and the deep meaning of the OUT and DIR registers. Of the things you've mentioned, the 6 switches, the photoresistor, and the IR detector all make use of the BS2's I/O pins as inputs where the Stamp normally draws next to no current. The photoresistor case is complex because you do use the I/O pin as an output sometimes when you're making a measurement, but it should be an input most of the time. The LEDs, piezo-speaker, and the 5 servos all use the I/O pins as outputs. When the LEDs are on, they draw current determined by the type of LED and, mostly, the value of the series resistor. When the output pin is set opposite to the state that will turn on the LED, it doesn't really use any current. The servos draw a little bit of current depending on the internal design of the servo. Without knowing that, it's impossible to guess how much current they draw in either state (high or low). It might be better to measure it, but it's going to be low, on the order of a fraction of a milliAmp. The piezo-speaker draws current transiently when the state of the I/O line changes. It acts like a capacitor that way.

    Remember that the IR detector and the servos are all going to draw current. You say you have pulldown resistors on the switches. Those will draw current if the switches are closed. All of this is likely to be much more than the current you'd save by changing output mode to input mode on the various output pins. In the case of the servos, you'll need to keep the I/O pins set to output low when they're not active or have pulldown resistors if the servos don't have that already. Otherwise, the servo inputs will react too much to noise.
  • BS2ILHBS2ILH Posts: 9
    edited 2009-12-24 05:04
    -I think you're getting a bit too worked up about current demand
    i thought i was, just wanted to check

    -all going to draw current
    yes, they are only on one at a time so i should be ok - unless a servo gets stuck and pulls a lot of current - i have checked the heat of the power transistor-after power was off- and it is not really even warm- so i think overall power consumption is ok.

    -In the case of the servos, you'll need to keep the I/O pins set to output low when they're not active
    ok i will work on that.

    i have reviewed INx OUTx and DIRx INPUT OUTPUT HIGH LOW
    i think i am mostly doing simple things so far and dont really use the control of pins and changing them.. once set they are inputs or outputs or kinda ignored and left to PULSOUT to handle

    i have a few questions that may be too worked up too:

    i read the INx value of the switches.
    Can you READ the DIR value ? IF DIR7=0 then do AAA or would that Set it?

    "INS always matches the actual states of the I/O pins, whether they are inputs or outputs. IN0, IN1, IN2... IN15
    the state of the pin itself is determined by the outside world when the pin is an input, and by the corresponding bit of ?PINS? when it's an output" OUT7 ?
    So IN7=OUT7 when DIR7=1 ??

    Thank you for helping me (and everybody else it seems)
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-24 05:48
    DIRS is just a 16 bit variable whose bits determine whether an I/O pin is an input or output. As a variable, it has a value that can be used for anything a variable can be used for.

    OUTS is similar to DIRS except that the value of the bits is used for the high/low state of the corresponding I/O pins for those that are in output mode. If a given I/O pin is in input mode, the OUTS bit has no effect (other than as a variable bit).

    INS is a special case as you've noted and the value of each bit reflects the actual state of the corresponding I/O pin whether it's an input or an output. As you've noted, INn is equal to OUTn when DIRn is 1.

    In most cases, I/O pins are set to either input or output mode during a program's initialization and left that way. The main exception is when an I/O pin is used for multiple purposes. Look at the PING))) documentation for one example.
  • BS2ILHBS2ILH Posts: 9
    edited 2009-12-26 18:46
    I added a Low Servopin to the beginning of the code, and PULSOUT will reverse that-do its thing and then return it - so the pins will not be antennae.

    Thanks for all the help and information.
    This is a link to see whst you have been helping : an HO scale train rotary dumper
    http://www.youtube.com/user/HOtrainHobby

    my blog- information about the changes-work done

    http://hotrainaction.blogspot.com/
Sign In or Register to comment.