Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Changing port from input to output on the fly

Changing port from input to output on the fly

2006-01-31 by Ted Smith

I want to use an ATMEGA16 to drive three sets of transistors to each
switch 6 high brigtness LEDs in parallel from 1 output (240ma per set). 
There is not enough current in the AVR to connect the LEDs directly
without additional parts.
I propose to connect the AVR output pins directly to the base of a NPN
transistor.
Initially for the lights to be off, I would program the port pin as an
output at 0 volts so the NPN transistor would not conduct. 
To make the lights go on, I would change the port to an input (with
pullup resistor enabled). This internal 10k pull up resistor would
easily sink the transistor on and light up the leds connected between
the collector and vcc+ with their 165 ohm dropping resistors.
This would need no extra base resistors.

1. Can anyone see any problem with this? 

2. Is there any limit to the number of times you can change from an
input to an output and back again?

3. What would be the best way to do this with Bascom? 

There is a veiled note about having to make something tri-state when
changing from an output to an input in the specs but I cant understand it.

Re: Changing port from input to output on the fly

2006-01-31 by Dave VanHorn

> 1. Can anyone see any problem with this? 

The pullup resistors are weak, and their equivalent resistance value 
is not guaranteed.  Multiply that somewhat unknown number by the beta 
of your transistor, and you'll see how much collector current you'll 
get. 

You'll be happier with something like a 2N7000 mosfet. 
Draws no gate current, and acts more like a relay. 
Also, you'll want a pulldown resistor on the gate to assure that they 
are off when the processor is in reset.  Otherwise, they could all 
come on during reset, and that could have implications for your power 
supply.


> 2. Is there any limit to the number of times you can change from an
> input to an output and back again?

Nope.

> 3. What would be the best way to do this with Bascom? 

Try assembler?  :)

Re: [AVR-Chat] Changing port from input to output on the fly

2006-01-31 by Jim Wagner

Normally, you would do this just leaving the pin as an
output. Put a resistor between the transistor base and the
port pin to reduce the base current. A 1K ought to work in
your situation. 

But, for your further questions, there is no limit to the
number of time you can change a port pin from input to
output or back again. The only place in the whole micro
that has limited number of operations is write to
non-volatile memory (either flash or eeprom, though the
numbers are different).

Jim

On Tue, 31 Jan 2006 10:57:29 -0000
 "Ted Smith" <tedsmithau@yahoo.com.au> wrote:
> I want to use an ATMEGA16 to drive three sets of
> transistors to each
> switch 6 high brigtness LEDs in parallel from 1 output
> (240ma per set). 
> There is not enough current in the AVR to connect the
> LEDs directly
> without additional parts.
> I propose to connect the AVR output pins directly to the
> base of a NPN
> transistor.
> Initially for the lights to be off, I would program the
> port pin as an
> output at 0 volts so the NPN transistor would not
> conduct. 
> To make the lights go on, I would change the port to an
> input (with
> pullup resistor enabled). This internal 10k pull up
> resistor would
> easily sink the transistor on and light up the leds
> connected between
> the collector and vcc+ with their 165 ohm dropping
> resistors.
> This would need no extra base resistors.
> 
> 1. Can anyone see any problem with this? 
> 
> 2. Is there any limit to the number of times you can
> change from an
> input to an output and back again?
> 
> 3. What would be the best way to do this with Bascom? 
> 
> There is a veiled note about having to make something
> tri-state when
> changing from an output to an input in the specs but I
> cant understand it.
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.