DIR OUT affect on pull-down sink current
BS2ILH
Posts: 9
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.
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
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.
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)
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.
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/