AVR and dim LEDs.

Hello all. I have been working with PIC microcontrollers for over 2 years now and I am familiar with and like them. However, recently I have started dabbling with Atmel AVR microcontrollers to see what they have to offer. Especially, since they seem quite popular these days and are showing up in more open-source products. I have done some simple flashing LED circuits with the ATmega8 and 48, and the ATtiny2313. I have been using the demo version of BASCOM and have just been doing simple one and two LED flashing circuits with very simple programs. The programs all seem to work fine on each of the chips. I have noticed, though, that the LEDs do not flash nearly as brightly with the AVR chips as they do with the PIC chips. Is that something unique to AVR chips, or is there some sort of pull-up resistor or other switch that needs to be set to allow for more current to pass throught the LED?

Reply to
artswan
Loading thread data ...

Check if you have configured the DDRx port direction registers properly.

--
:wq
^X^Cy^K^X^C^C^C^C
Reply to
Ico

You are probably trying to lit up the LEDs with the logic 1. This is not a good practice which originates from PIC appnotes. You should connect the LEDs to Vdd and lit them up with logic 0.

Why: the majority of the logic ICs (including PICs!) have the logic 1 much weaker then the logic 0.

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

There are limitations on the maximum that each I/O pin can sink or source, as well as limitations on aggregate sinking and sourcing; e.g., there is a limit on the combined I[OL] for Port C in addition to the limit on the total I[OL].

Although I will occasionally hang a "heartbeat" LED directly off of a port (and set it to sink the LED + limiting resistor), in general, and particularly when multiple LEDs are involved, I'll move the LEDs off to a transistor or an array (e.g., ULN2803) where they can be fed all of the current that they need.

--
Rich Webb   Norfolk, VA
Reply to
Rich Webb

Thank all of you for your assistance. I will try out your suggestions. As always, the Devil's in the details. LOL

Thanks again. :)

Art

Reply to
artswan

As already proposed, use the port to sink the LED curent. Use low current leds and do the calculations for a sensible current. Use the difference between the supply voltage and the LED voltage drop at the selected current and divide the difference by the selected current to get the required resistor.

Bye

--
Uwe Bonnes                bon@elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Reply to
Uwe Bonnes

Are you using the same brand and type of LEDs ? There are huge difference in brightness between various types, as well as different current requirements. Some LEDs are brighter at 2 mA than others at 20 mA. Also, compare the value of your current limiting resistor.

While it is true that most chips can sink more current than they source, the AVR source current should be enough to drive some LEDs. I'm doing it all the time on ATmega128. Check your LED datasheet for the recommended forward current, and check the AVR datasheets for max source/sink current.

If you have a voltmeter, you can measure the voltage directly at the output pin of the AVR chip (before the resistor). If it's close to the supply voltage, the max source current is not the problem.

Reply to
Arlet

AFAIK, this has to do with the technology rather then with the physics. The conventional silicon process does not allow making PNP and P-channel devices as good as NPN and N-channel.

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

N-channel MOSFETs are better (i.e. lower Rds(on)) than p-channel parts of the same silicon acreage. IIRC, it's something to do with a large (2:1?) difference in carrier mobility, check your solid-state physics textbooks if you're curious.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

... snip ...

In the days of germanium it was easier to make PNPs than NPNs. Once things switched to silicon, NPNs became the principal medium.

--
Chuck F (cbfalconer at maineline dot net)
   Available for consulting/temporary embedded and systems.
Reply to
CBFalconer

I used the same LED that I was using in a breadboarded PIC circuit, a pretty standard red LED I had bought in bulk from All Electronics a year or two ago. I also switched out with other red LEDs that I knew worked well. Same result, dim flashing LED. And, since I was using a short flash time (0.250 seconds) for both on and off states, and was running the circuit for only a few seconds to test it, I even took the

220 ohm resistor I was using in series with the LED and connected the LED directly from the output pin to ground. Same dim flashing LED.

Art

Reply to
artswan

Oh, one final note that I forgot to mention (silly me!), I connected the LED, both with a series 220 ohm resistor and without, from Vdd to the output pin, so as to have the AVR chip sink current rather than source it, and there was no longer any visible blinking of the LED.

Art

Reply to
artswan

You are risking damage to the LED and/or the chip by connecting it without a resistor.

Anyway, it looks like your problem is that you haven't set the pin to output mode.

for example if it was pin 0 on port C you would use:

sbi DDRC,0

When the data direction bit is low the port bit just switches on or off a pull-up resistor. That would explain the symptoms you are getting.

--
Mike
Reply to
Mike Warren

Yes there is, all PIC output pins have high current capability and can drive a LED directly, the ATmega's have high and low current ports, usually port B is the high current port and should be able to drive an LED directly like the PIC (at 5 volts anyway). So move the LED to a high current pin and you should work the same as the PIC.

In general the AVR's are lower power devices, optimized for battery power (more delicate), so they make sacrifices like this.

Reply to
steve

I agree, that's exactly what it looks like. Note that the PIC uses '0' in the direction register to turn a pin into an output, while the AVR uses '1'.

Reply to
Arlet

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.