Pulsing common ANODE LEDs via PWM

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I've bought a bunch of RGB LEDs, and based on the attached diagram, it looks like the LEDs are common ANODE.  I am looking to use an ATMEGA328 just to try out if I can pulse the Red, Green, Blue LEDs in this RGB LED via PWM.

 

My first question is to confirm that the RGB LED is indeed common ANODE.  Is that so?  Please see the attached diagram.

 

Below is additional information about this RGB LED.  My 2nd question is:  If it's indeed common ANODE, then I would have to connect this LED as an INPUT to the ATMEGA328 pins that support PWM, the OCxx pins.  However, the connection would have to be configured as an INPUT, because the ATMEGA328 would have to SINK the current to turn the LED on.  How would that work for pulsing the LED, since the OCxx pins would be required to setup as OUTPUT rather than INPUT, no?

 

Another question is that the LED will draw 20mA, or would require the ATMEGA328 to SINK 20mA.  I am not sure if it's 20mA per color, that is, 20mA each for red, green, and blue LEDs or 20mA for the three.  Assume it's the former, I could stick a 330ohm resistor at pin 1, the ANODE pin of the LED, to reduce the current 10mA, since an AVR can only sync 10mA max per IO pin, a total of 30mA, correct?  THANKS FOR ANY HELP TIP!

 

 

Model: 1210 (3528)
· Product Dimensions: 3.5 * 2.8 * 1.9
· Voltage: 2.0-2.2V Red brightness 500-550MCD wavelength :620-625NM
· Voltage: 3.0-3.4V blue brightness 700-750MCD wavelength :460-475NM
· Voltage: 3.0-3.4V Green brightness 800-850MCD wavelength :520-525NM
· Current: 20MA
· Soldering temperature: 250
· Viewing angle: 120

Attachment(s): 

Last Edited: Sat. Nov 29, 2014 - 05:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, it's a common-anode RGB LED.

 

No, you would not set the AVR pins to inputs.  Set them to outputs.  An output can either source current (in the 1 state) or sink current (in the 0 state).  Writing a 0 to the pin will turn on the corresponding LED.

 

You don't have to use the hardware PWM to drive the LEDs, though you certainly can.  You can also drive them using software PWM.  I have done this with a mega48, clocked at 18.432MHz.  I used a 60us timer interrupt, and 8-bit pwm, to drive 6 RGB LEDs (18 LEDs total).  The LED refresh rate (PWM rate) works out to about 65Hz, enough to eliminate flicker to my eyes at least. CPU time to handle 18 LEDs in the timer interrupt was about 5% of total CPU time.  Because of the AVR current limits per port and also per GND and Vcc, I used 3 common-cathode RGBs and 3 common-anode RGBs to stay within all current specs.

 

But now I've switched to the WS2812B RGB LED - they're so much easier!  Have a look here:

http://www.embeddedrelated.com/s...

Last Edited: Sat. Nov 29, 2014 - 06:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, the device is common anode - what would be wrong with pulsing PIN 1 with an output and tying PINS 2, 3,and 4 to an input and pulling them LOW based on which junction you wanted to illuminate? 

Just some guy

Last Edited: Sat. Nov 29, 2014 - 06:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@kk6gm: Thank you for a very good answer!

Last Edited: Sat. Nov 29, 2014 - 07:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

johnrk wrote:

Yes, the device is common anode - what would be wrong with pulsing PIN 1 with an output and tying PINS 2, 3,and 4 to an input and pulling them LOW based on which junction you wanted to illuminate? 

 

Nothing wrong.  I thought that sinking current was only for INPUT, and sourcing is for OUTPUT.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

unebonnevie wrote:
I thought that sinking current was only for INPUT, and sourcing is for OUTPUT.
Sinking and sourcing are electrical distinctions, not I/O distinctions.

 

An element (mcu pin, transistor, whatever) which sinks current has electrons (negative charge) flowing out, whereas an element which sources current has electrons flowing in.

 

Whether or not this represents an input or an output is more to do with context.

 

When we say an mcu pin is an output we generally mean that the pin has been configured to deliver a significant (in relative terms) current, either as a sink or as a source.  Which it does at any given moment is under control of the mcu's hardware and/or software.

 

When we say an mcu pin is an input we mean that the pin has been configured to read the voltage delivered to (externally) and present on that pin.  For digital input pins, that voltage translates into one of two states: 0 for a low voltage (generally less than Vcc/2, ignoring hysteresis) and 1 for a high voltage (greater than Vcc/2).  Whether or not the pin as an input sources or sinks current while doing so is usually not a concern.

 

There are exceptions of course.  In an AVR where GPIO pins have individually selectable pull-up resistors, a pin will source a small amount of current while being held low by an external agent.  Some AVR (xmega) also have internal pull-down resistors.  When enabled, that pin will sink a small amount of current while being held high by an external agent.  In both cases the current sunk or sourced isn't important inasmuch as it has no relevance to the role of the pin as an input, but is important insofar as the design of the external circuit is concerned.

 

Just for the sake of completeness, even a pin configured for input without a pull-up or pull-down resistor will sink or source current based on the voltage delivered to it.  It will be an extremely small current usually on the order of nanoamps but it is there nonetheless.  Usually it is due simply to internal leakage within the device.  Every device datasheet specifies what the worst-case leakage current is for GPIO pins.  For AVR the maximum is usually specified as 1 microamp.

 

Also interesting to note is that while modern mcu including modern AVR have GPIO pins which can sink and source current as an output, some early mcus had outputs which could only sink current.  The 'high' output state was open collector (some could source, but much less current than they could sink).  As a result LED driven directly by the mcu were driven at the cathode, and any common-electrode LED devices (like 7-segment displays) were common anode.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Sat. Nov 29, 2014 - 08:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:

 

unebonnevie wrote:

I thought that sinking current was only for INPUT, and sourcing is for OUTPUT.

Sinking and sourcing are electrical distinctions, not I/O distinctions.

 

 

An element (mcu pin, transistor, whatever) which sinks current has electrons (negative charge) flowing out, whereas an element which sources current has electrons flowing in.

 

Whether or not this represents an input or an output is more to do with context.

 

When we say an mcu pin is an output we generally mean that the pin has been configured to deliver a significant (in relative terms) current, either as a sink or as a source.  Which it does at any given moment is under control of the mcu's hardware and/or software.

 

When we say an mcu pin is an input we mean that the pin has been configured to read the voltage delivered to (externally) and present on that pin.  For digital input pins, that voltage translates into one of two states: 0 for a low voltage (generally less than Vcc/2, ignoring hysteresis) and 1 for a high voltage (greater than Vcc/2).  Whether or not the pin as an input sources or sinks current while doing so is usually not a concern.

 

There are exceptions of course.  In an AVR where GPIO pins have individually selectable pull-up resistors, a pin will source a small amount of current while being held low by an external agent.  Some AVR (xmega) also have internal pull-down resistors.  When enabled, that pin will sink a small amount of current while being held high by an external agent.  In both cases the current sunk or sourced isn't important inasmuch as it has no relevance to the role of the pin as an input, but is important insofar as the design of the external circuit is concerned.

 

Just for the sake of completeness, even a pin configured for input without a pull-up or pull-down resistor will sink or source current based on the voltage delivered to it.  It will be an extremely small current usually on the order of nanoamps but it is there nonetheless.  Usually it is due simply to internal leakage within the device.  Every device datasheet specifies what the worst-case leakage current is for GPIO pins.  For AVR the maximum is usually specified as 1 microamp.

 

Also interesting to note is that while modern mcu including modern AVR have GPIO pins which can sink and source current as an output, some early mcus had outputs which could only sink current.  The 'high' output state was open collector (some could source, but much less current than they could sink).  As a result LED driven directly by the mcu were driven at the cathode, and any common-electrode LED devices (like 7-segment displays) were common anode.

 

Thank you!  Learn new things every day! :-)  Just to confirm what you wrote above: "An element (mcu pin, transistor, whatever) which sinks current has electrons (negative charge) flowing out, whereas an element which sources current has electrons flowing in."  The "in" and "out" are correct?

Last Edited: Sat. Nov 29, 2014 - 08:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes.  Electrons have negative charge and flow out of, for example, the anode (negative terminal) of a battery, through the load being driven, and into the cathode (positive terminal) of the battery, having lost some energy to the load.

 

The terminology 'source' and 'sink' comes (I imagine) from a misunderstanding on the part of early researchers in the field of electricity, before the electron was identified as the charge carrier, and before that charge was determined to be negative in nature.  The same misunderstanding led to the selection of the arrow symbol for the diode pointing in the 'wrong direction'.

 

Ultimately the terminology is useful only to keep things straight in our heads.  The universe will do what it does regardless of what names we call it ;)

 

EDIT: sp

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Sun. Nov 30, 2014 - 02:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 The universe will do what it does regardless of what names we call it ;)

 Electron or hole flow? wink

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who are you calling a hole?!  wink

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I learned vacuum tubes (and thus electron flow) as a tyke.  Electron flow was really hard to maintain in the transistor era, and sometime long ago my brain switched to conventional flow, and I never think about it any more.  And if I mess with vacuum tubes for fun now and then, I revert to electron flow without a conscious decision.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:

Yes.  Electrons have negative charge and flow out of, for example, the anode (negative terminal) of a battery, through the load being driven, and into the cathode (positive terminal) of the battery, having lost some energy to the load.

 

The terminology 'source' and 'sink' comes (I imagine) from a misunderstanding on the part of early researchers in the field of electricity, before the electron was identified as the charge carrier, and before that charge was determined to be negative in nature.  The same misunderstanding led to the selection of the arrow symbol for the diode pointing in the 'wrong direction'.

 

Ultimately the terminology is useful only to keep things straight in our heads.  The universe will do what it does regardless of what names we call it ;)

 

EDIT: sp

 

Ok...The postive terminal attracts the electrons to flow out of the negative terminal.  It's true all these naming causing confusion.  I had always associated "anode" as being positive and "cathode" as being negative.

 

One last question:  I had never used common anode multi-color LEDs until.  With the RGB LED being common Anode, as per my original post of the schematic of the RGB LED, is it correct that I simply put a resistor (rather one for each of the colors) at the anode connection, that is, since I will be using 5V as my Vcc?  Or do I still have to put a resistor for each LED connection, that is, one resistor for RED, one for GREEN, and one for BLUE?  Below again is the electrical characteristics of the RGB LED.  I would like the former, that is, requiring only on resistor, thus, saving PCB space.  Thanks!

 

Model: 1210 (3528)
· Product Dimensions: 3.5 * 2.8 * 1.9
· Voltage: 2.0-2.2V Red brightness 500-550MCD wavelength :620-625NM
· Voltage: 3.0-3.4V blue brightness 700-750MCD wavelength :460-475NM
· Voltage: 3.0-3.4V Green brightness 800-850MCD wavelength :520-525NM
· Current: 20MA
· Soldering temperature: 250
· Viewing angle: 120

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

unebonnevie wrote:
Ok...The postive terminal attracts the electrons to flow out of the negative terminal.  It's true all these naming causing confusion.  I had always associated "anode" as being positive and "cathode" as being negative.

Sorta ;)

 

When you're talking about devices like diodes, the anode is the terminal which gets connected to the high-side i.e. more positive of the two circuit nodes, and the cathode terminal connects to the low-side i.e. more negative node.  In this arrangement the diode will be forward biased and will conduct current.

 

When speaking of current sources like batteries the anode refers to the negative electrode.

 

This apparent disparity arises from the root definition for anode.

 

From the Wikipedia article:

An anode is an electrode through which positive electric charge flows into a polarized electrical device. The flow of charge is an electric current. A common mnemonic is ACID for Anode Current Into Device; the key notion is a positive current flows into the device; positive charges are entering the device through the anode. There is a complication because a current is often moving electrons, and the charge on an electron is negative. Positive charge flowing into the anode is the same as (negative) electrons flowing out of the anode. Consequently, the direction of electric current is opposite to the direction of electron flow: electrons flow out of the anode to the outside circuit.

That last statement is key:  "electrons flow out of the anode."

 

In the case of a battery, electrons (which have negative charge) flow out of the negative terminal of the battery.  The negative terminal is the anode.

 

If you have a diode connected in forward bias fashion to a battery, electrons flow out of the anode of the battery, into the cathode of the diode, out of the anode of the diode, and finally into the cathode of the battery.  Let's set aside for the moment the wisdom of connecting a lonely diode across a battery all by itself ;)

 

From the Wikipedia article for cathode:

A cathode is the electrode from which a conventional current leaves a polarized electrical device. This definition is sometimes remembered using the mnemonic CCD for cathode current departs. A conventional current describes the direction in which positive electronic charges move. Electrons have a negative charge, so the movement of electrons is opposite to the conventional current flow. Consequently, the mnemonic cathode current departs also means that electrons flow into the device's cathode.

Further:

Cathode polarity with respect to the anode can be positive or negative; it depends on how the device operates. Although positively charged cations always move towards the cathode (hence their name) and negatively charged anions move away from it, cathode polarity depends on the device type, and can even vary according to the operating mode. In a device which consumes power, the cathode is negative, and in a device which provides power, the cathode is positive:

  • In a discharging battery or a galvanic cell, the cathode is the positive terminal since that is where the current flows out of the device (see drawing). This outward current is carried internally by positive ions moving from the electrolyte to the positive cathode (chemical energy is responsible for this "uphill" motion). It is continued externally by electrons moving inwards, this negative charge moving inwards constituting positive current flowing outwards. For example, the Daniell galvanic cell's copper electrode is the positive terminal and the cathode.
  • In a recharging battery, or an electrolytic cell performing electrolysis, the cathode is the negative terminal, from which current exits the device and returns to the external generator. For example, reversing the current direction in a Daniell galvanic cell would produce an electrolytic cell,[1] where the copper electrode is the positive terminal and the anode.
  • In a diode, the cathode is the negative terminal at the pointed end of the arrow symbol, where current flows out of the device. Note: electrode naming for diodes is always based on the direction of the forward current (that of the arrow, in which the current flows "most easily"), even for types such as Zener diodes or solar cells where the current of interest is the reverse current.
  • In vacuum tubes (including cathode ray tubes) it is the negative terminal where electrons enter the device from the external circuit and proceed into the tube's near vacuum, constituting a positive current flowing out of the device.

An electrode through which current flows the other way (into the device) is termed an anode.

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Sun. Nov 30, 2014 - 08:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

unebonnevie wrote:

 

One last question:  I had never used common anode multi-color LEDs until.  With the RGB LED being common Anode, as per my original post of the schematic of the RGB LED, is it correct that I simply put a resistor (rather one for each of the colors) at the anode connection, that is, since I will be using 5V as my Vcc?  Or do I still have to put a resistor for each LED connection, that is, one resistor for RED, one for GREEN, and one for BLUE?  Below again is the electrical characteristics of the RGB LED.  I would like the former, that is, requiring only on resistor, thus, saving PCB space.  Thanks!

You need a resistor for each of the 3 LEDs.  Using just one resistor in the anode will (a) severely limit the total brightness you can get from your LED, and (b) distort your colors, e.g. as you turn on more green, less current will flow through red.

EDIT: Actually it's even worse than that.  Each LED (R,G,B) will have a different characteristic voltage drop, with R being the lowest voltage.  Using a single resistor will essentially put any turned-on LEDs in parallel, and the lowest voltage LED will always hog the current.  You could have R on, then turn on G or B and see little if any G or B since their characteristic voltages are higher than R.

 

Again, if you want to save PCB space, look at the WS2812B parts.  You can drive literally hundreds with a tiny AVR, limited only by internal buffer RAM size.

Last Edited: Sun. Nov 30, 2014 - 10:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

unebonnevie wrote:
anode connection, that is, since I will be using 5V as my Vcc?  Or do I still have to put a resistor for each LED connection, that is, one resistor for RED, one for GREEN, and one for BLUE?  Below again is the electrical characteristics of the RGB LED.  I would like the former, that is, requiring only on resistor, thus, saving PCB space.  Thanks!
It's 'OK' in that nothing will get damaged, but you won't get the results you want.

 

The problem is that each of the three LEDs has a different forward voltage.

 

Let's look at a schematic for it:

 

Vcc <---/\/\/---+-------+-------+
                |       |       |
                |       |       |
               ---     ---     ---
               \R/     \G/     \B/
               ---     ---     ---
                |       |       |
                |       |       |
                + /     + /     + /
                 /       /       /
                +       +       +
                |       |       |
                |       |       |
                |       |       |
                +-------+-------+
                        |
                        |
                        |
                       GND

 

 

The switches represent each GPIO pin which when driven low will sink current from its LED's cathode.  When driven high, no current will flow because the diode will not be forward biased.

 

Let's make R 150 ohms.

 

Imagine now that we switch on the red LED.  Current will flow between Vcc and ground through the resistor and the LED.  How much current I flows will depend upon the value R of the resistor, the forward voltage Vf of the diode, and Vcc.

 

We know from Ohm's Law that the voltage across the resistor will be:

VR = Vcc - Vf
   = 5 - 2
   = 3 V

 

We also know from Ohm's Law that the current through the resistor (and LED) will be:

I = VR / R
  = 3 / 150
  = 0.02
  = 20 mA

 

We can calculate the effective resistance of the LED under these conditions:

RRED = Vf / I
     = 2 / 0.02
     = 100 ohms

 

Now Let's do the same thing with the green LED.

VR = Vcc - Vf
   = 5 - 3
   = 2 V
   
I = VR / R
  = 2 / 150
  = 0.01333
  = 13.33 mA
 
RGREEN = Vf / I
       = 3 / 0.01333
       = 225 ohms

 

So what happens if you turn them both on?

 

Vcc <---/\/\/---+-------+-------+
                |       |       |
                |       |       |
               ---     ---     ---
               \R/     \G/     \B/
               ---     ---     ---
                |       |       |
                |       |       |
                +       +       + /
                |       |        /
                +       +       +
                |       |       |
                |       |       |
                |       |       |
                +-------+-------+
                        |
                        |
                        |
                       GND

 

Ohm's Law tells us that the voltage across the red LED must be the same as the voltage across the green LED, because they are in parallel with each other with no other components in play.  However the forward voltage Vf of the red LED is 2 V whereas the forward voltage Vf of the green LED is 3 V.  How do we reconcile this.

 

The key lies in understanding the resistive nature of a semiconductor device like an LED.  In effect they have a voltage-dependent resistance.

 

What does this mean?

 

A normal 'ideal' resistor has a resistance that is constant.  That is to say the resistance of the device doesn't change when environmental conditions change.  If the voltage across the ideal resistor changes, the resistance does not.  The resistance vs. voltage graph is a flat line.  The current vs. voltage graph is a straight sloped line starting at 0,0 i.e. it is a linear relationship:

 

(stolen from http://www.davidbridgen.com/mixers.htm)

 

A diode is different.  As the voltage across a diode increases, the current through the diode increases, but not linearly.  The relationship between voltage and current is exponential.  To the eye, the graph of this relationship looks like this:

 

(stolen from http://www.physics.csbsju.edu/trace/CC.html)

 

Although the above graph is for a normal non-LED silicon diode with a nominal Vf of 0.7 volts or so, it illustrates the nature of an LED's I vs. V curve.  A very nearly zero but slow increase of current as voltage rises, until the 'knee' in the curve, after which the current rockets upwards with each tiny increase in voltage.  In other terms, the effective resistance of a diode goes down as the voltage across it goes up.  The 'knee' represents the onset of the diode's rated forward voltage.

 

From this you can infer that the forward voltage also changes with the current going through the diode.

 

How does this relate to our circuit?

 

We know that when both the red and green LED are on the voltage across each of them must be the same.  What we find is that this voltage will be the lower of the two forward voltages, in this case the forward voltage of the red LED.  The effect is that the current going through the green LED, which has the higher nominal forward voltage, will be much less than it would be if it were by itself.  This is because its effective resistance (at a voltage lower than it's nominal forward voltage) is much greater than that which results from the rated current at that nominal forward voltage.

 

In other words, Vf of all LEDs in parallel will be clamped to the lowest forward voltage of those LEDs.  As a result the higher-voltage diodes will have a much higher effective resistance, and thus will conduct a much lower current, and will emit much less light.  The voltage across the higher-voltage diodes in this circuit will be 'before the knee'.  In the case of a red and a green LED, the difference in forward voltage is so great that the current through and light emitted by the green LED will be negligible.

 

The moral of the story is that you need individual series resistors on the cathode of each LED in the common anode package.

 

EDIT: corrected some errors and added linear graph

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Mon. Dec 1, 2014 - 06:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@joeymorin & @kk6gm:  THANK YOU VERY MUCH FOR YOUR ANSWERS.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kk6gm wrote:

Yes, it's a common-anode RGB LED.

 

No, you would not set the AVR pins to inputs.  Set them to outputs.  An output can either source current (in the 1 state) or sink current (in the 0 state).  Writing a 0 to the pin will turn on the corresponding LED.

 

You don't have to use the hardware PWM to drive the LEDs, though you certainly can.  You can also drive them using software PWM.  I have done this with a mega48, clocked at 18.432MHz.  I used a 60us timer interrupt, and 8-bit pwm, to drive 6 RGB LEDs (18 LEDs total).  The LED refresh rate (PWM rate) works out to about 65Hz, enough to eliminate flicker to my eyes at least. CPU time to handle 18 LEDs in the timer interrupt was about 5% of total CPU time.  Because of the AVR current limits per port and also per GND and Vcc, I used 3 common-cathode RGBs and 3 common-anode RGBs to stay within all current specs.

 

But now I've switched to the WS2812B RGB LED - they're so much easier!  Have a look here:

http://www.embeddedrelated.com/showarticle/528.php

 

Thanks, I am able to make a RGB LED pulse all 3 leds with 15 lines of code.  Using the WS2812B RGB LED, which I also bought some, is actually NOT simple as you mentioned, because you have to use assembly due to the insane time requirement of the WS2812B.  However, your article REALLY HELPS! THANKS!.  Ok, your article does not mention if you use WinAVR or Atmel Studio.  Do you have the Makefile by any chance?  I can look on the net for a Makefile that would compile an assembly module and link to the C module.

 

Thanks!

Last Edited: Mon. Dec 15, 2014 - 05:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used Atmel Studio for the WS2812 code.  Just add the .s file to the project, and in the C file declare the ASM function as external.  It should all be in the tutorial - if not, I'll update the tutorial.

 

I've still got a few bags of regular RGB LEDs (both leaded and SMT).  Never touch them anymore.

 

Remember the code works for 8MHz AVR (convenient for most AVR internal oscillators).  For a higher clock you'd have to add NOPs (easy) or rearrange the code (hard to imagine the benefit of that).

Last Edited: Mon. Dec 15, 2014 - 06:49 AM