Maker Pro
Maker Pro

help with picaxe

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The specs say that each output can sink or source 20mA, but the max combined current is only 90mA. Why is the heck do they put so output pins on them if they can only do 90mA?

This is typically a package dissipation limit. If you draw more current in total then the chip will get too hot (this is somewhat simplistic, there may also be other reasons).

It is not typical to use the outputs of a microcontroller to drive a load directly. LEDs are an exception because they draw such a low current. Normally, you'll see loads driven by external transistors mosfets, etc. If you imagine that these devices may require only 1mA (or less) then you can see how the package limit is not a huge issue in most cases.

...so I would rather use common cathode...

I have some BC327 PNP transistors. Will that do the trick for my amplifier? If not, could you or Steve recommend something?
Yes, PNP transistors allow you to switch the common cathode LED directly, but you need to invert your signal. This can be a bit of a pain. It may be less of a pain to use another transistor to invert the signal so that both common anode and common cathode LEDs can be driven without changing the code.

Let's draw some circuits...

Here is the simplest way of driving common cathode LEDs:

attachment.php


Clearly you run into package dissipation issues, and the LED cannot require more voltage (or current) than the uC can provide at its output. R1 is used to set the current.

When the output id high, the LED is on. So the PWM ramping from 0 to 400 will go from off to a medium brightness.

And here is how you can simply drive a common anode LED [thanks for the correction]

attachment.php


Same comments about voltage and current.

Now, however, the LED is ON when the output is low, so using PWM to ramp from 0 to 400 will result in the LED going from fully ON to something a bit less bright.

In this case, you need to ramp from 1024 to 624. And you have to remember to tie the output high when you want the LED to be off.

So, you can do this

attachment.php


Here we drive a common anode [thanks again] LED via a transistor (NPN). R1 again provides the current limit, and R2 sets the base current into the transistor. R2 is often going to be about 100 times larger than R1 for low current LEDs (but that's a very rough calculation which may not apply to high current LEDs.)

This circuit has a number of advantages. Firstly, when the output is on, the LED is ON, so your programming is easy. Secondly, the LED can be operated from a voltage higher than the uC.

A similar circuit can be made for common cathode LEDs

attachment.php


This is pretty much the exact opposite. And it suffers few of the advantages of the circuit above.

The LED voltage can only exceed the uC voltage if the "ground" voltage is below the ground of the uC, and the LED operates in the opposite sense to the uC output.

But we can fix that...

attachment.php


Adding another transistor to invert the output, the fourth circuit gains all of the advantages of the third. R2 can be even higher in this case (up to 1000 times R1), with R3 and R4 being approximately equal and 10 to 100 times R1 (which sets the output current)
 

Attachments

  • Scan-140104-0002.jpg
    Scan-140104-0002.jpg
    23.2 KB · Views: 298
  • Scan-140104-0003.jpg
    Scan-140104-0003.jpg
    20.3 KB · Views: 265
  • Scan-140104-0004.jpg
    Scan-140104-0004.jpg
    24.7 KB · Views: 244
  • Scan-140104-0005.jpg
    Scan-140104-0005.jpg
    27.2 KB · Views: 305
  • Scan-140104-0006.jpg
    Scan-140104-0006.jpg
    32.4 KB · Views: 287
Last edited:

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
You do realize that you can purchase 4 lead Bi-LEDs don't you? 4 pin packages don't have the anodes or cathodes committed to a common pin. They're more versatile
than common cathode or common anode.

On the other hand common anode packages aren't hard to find.
Ebay BiLed Listings

Common Anode BiLed

BTW, Steve made a typo in his second schematic. That should read "common anode". ;)
He drinks a lot of beer you know! :p

Chris
 
Last edited:

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
You do realize that you can purchase 4 lead Bi-LEDs don't you?

Yes, I've seen them.


On the other hand common anode packages aren't hard to find.

Blue/Yellow Bi-Colored LEDs are rather difficult to come by an any configuration.

BTW, Steve made a typo in his second schematic. That should read "common anode".

Yes, I noticed that, but wasn't it the 3rd schematic?



When the output id high, the LED is on. So the PWM ramping from 0 to 400 will go from off to a medium brightness.

I'm confused. I used the PWM Wizard, and I select "100%" for the "Duty Cycle, as a percentage". It calculated the figures and returned the code "pwmout pin, 99, 400", 400 being the duty cycle @ 100%

In fact, I'm using this code on my 08M2 to ramp up an LED at one button push, then fade it off at a second button push. The LED ramps all the way up, and fades all the way off. I say "it ramps all the way up", because it's just as bright as it is being connected directly to the power supply @ 5V using the same current limiting resistor.


the LED is ON when the output is low, so using PWM to ramp from 0 to 400 will result in the LED going from fully ON to something a bit less bright.

Same confusion as above. If 400 is 100% of the duty cycle, why wouldn't 400 be completely OFF with a common anode LED?

Here we drive a common cathode LED via a transistor (NPN). R1 again provides the current limit, and R2 sets the base current into the transistor. R2 is often going to be about 100 times larger than R1 for low current LEDs (but that's a very rough calculation which may not apply to high current LEDs.)

This circuit has a number of advantages. Firstly, when the output is on, the LED is ON, so your programming is easy. Secondly, the LED can be operated from a voltage higher than the uC.

I'm confused. You've pictured a common anode LED in your schematic. I thought with common anode, the LED is OFF when the circuit is high, and ON when the circuit is LOW.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Yes, I noticed that, but wasn't it the 3rd schematic?

It was both. I think I had cathodes on the brain. (And I was in a hurry -- there's a lesson in that).

I'm confused. I used the PWM Wizard, and I select "100%" for the "Duty Cycle, as a percentage". It calculated the figures and returned the code "pwmout pin, 99, 400", 400 being the duty cycle @ 100%

The way I read it, 1024 was 100% duty cycle. You may be right.

Same confusion as above. If 400 is 100% of the duty cycle, why wouldn't 400 be completely OFF with a common anode LED?

Probably.
 

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
Could you guys check this and see if it's doable. I asked about this earlier in the thread......


Quoting myself

I'd also like to drive some LED strip from a Picaxe (with PWM), but the LED strip needs at least 9V to be bright enough to suit my needs, and the Picaxe can only output 5V. The main circuit in my model will be running on 9V to accommodate the LED strip that I use for static interior lights and the warp nacelles. I'll be using 5V regulators for any circuits operating from a picaxe, arduino etc. If I want to drive a section of LED tape from a picaxe output, would I connect the positive side of the strip to the 9V main and the negative side to the Collector (or Drain on the mosfet). Would that work with two different voltages?

Here was Steve's reply.....

Yes, the way you plan to connect the LEDs (to a 9V supply) is OK. Make sure that the negative ends of both supplies are common (and connect to the source (or emitter) terminal of the transistor.

Can I hook it up this way, or should I use a separate MOSFET for the LED strips?
 

Attachments

  • schematicB.JPG
    schematicB.JPG
    58.2 KB · Views: 149

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Yeah, that will work.

Note that the output is inverted, and that the way you've drawn it both LED strips are controlled from a single output.
 

richardb

Dec 21, 2013
48
Joined
Dec 21, 2013
Messages
48
Sorry if I'm missing something obvious as I didn't read the whole thread.
Could you do this by..
Connecting the base to the micro op no resistor needed.
Connect the collector to the 5v or higher supply
connect the emitter to the led via a resistor.
there will be a little voltage drop across the transistor and the led but @5V you should be ok.
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
Sorry if I'm missing something obvious as I didn't read the whole thread.
Could you do this by..
Connecting the base to the micro op no resistor needed.
Connect the collector to the 5v or higher supply
connect the emitter to the led via a resistor.
there will be a little voltage drop across the transistor and the led but @5V you should be ok.

Yes, but not with a MOSFET. What you're describing is an Emitter Follower also called a Common Collector amplifier. The down side of emitter followers, besides the higher base voltage needed, is they can't be saturated. For this application this is not a big deal but becomes an issue when dealing with very high collector current.

Chris
 

richardb

Dec 21, 2013
48
Joined
Dec 21, 2013
Messages
48
I was only suggesting to use it for this cct ;)

As I said I haven't read all the thread and as I understood it the op wanted to drive 20mA to a few LED's which was more than the total current that the device can handle.

Rich
 

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
Yeah, that will work.

Note that the output is inverted, and that the way you've drawn it both LED strips are controlled from a single output.

Inverted, as in high is OFF and low is ON? If so, yes, I'm aware of that..

I need both LED strips, and the blue side of both bi-colored LEDs to be controlled from a single output if possible. I would like to have the warp nacelles (blue LED strip), the deflector dish and the crystal on the saucer section to all ramp up in blue via PWM.

As they say, a picture is worth a thousand words......(see the pics below)

richardb said:
there will be a little voltage drop across the transistor and the led but @5V you should be ok.

The LED strips are barely bright enough to suit my needs at 9V, which is the rating of my power supply. If it were just the bi-colored LEDs it would be fine, but those strips would not be bright enough, or may not even come on at all with even a small voltage drop. How much "voltage drop are we talking about"? I have the strips in front of me as I type this, hooked up to a desktop power supply. If I lower the voltage to just 8.0V the LED strip is significantly less bright.

I would love to be able to use common cathode bi-colored LEDs, as it would greatly increase my options for purchasing my LEDs, but apparently using a PNP transistor is not a good option in this application.
 

Attachments

  • enterprise1.JPG
    enterprise1.JPG
    55.4 KB · Views: 178
  • enterprise2.JPG
    enterprise2.JPG
    25.6 KB · Views: 184

richardb

Dec 21, 2013
48
Joined
Dec 21, 2013
Messages
48
oops, I missed that re just bright enough with 9v, I assumed they were single leds with maybe 2v drop not chains.

i'll shutup now :)
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
I would love to be able to use common cathode bi-colored LEDs, as it would greatly increase my options for purchasing my LEDs, but apparently using a PNP transistor is not a good option in this application.

This getting confusing. If you get common anode bi-leds you would drive them with an NPN or the FETs you have. Your code would remain unchanged too!

Maybe it's just me. I'll admit that I haven't had a fun week! I've been in one of those "Computer Hell" vortexes. This thread doesn't help because we keep bouncing all over the place It would be nice to resolve each issue before moving on to the next and then jumping back to the other. I getting dizzy!

FYI, Led strings that are made for 12V operation (which swings closer to 14V - 15V in autos) are going to be feeble at 9V.

Chris
 
Last edited:

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
This thread doesn't help because we keep bouncing all over the place It would be nice to resolve each issue before moving on to the next

I apologize, Chris. I didn't realize I was being a pest, but with all due respect, how can things get "resolved" when you ignore what I'm trying to tell you?


If you get common anode bi-leds you would drive them with an NPN or the FETs you have. Your code would remain unchanged too!

Therein lies the problem. I'll say this once again. Blue/yellow bi-LEDs are a rare bird. The only common anode ones I've found are 10MM in size, which is too large for where I need to put them.

quoting myself....

from yesterday
Blue/Yellow Bi-Colored LEDs are rather difficult to come by an any configuration.
.

from friday
the ONLY blue/yellow I can find in common Anode is 10MM ones, so I would rather use common cathode, as I can get those in the 5mm or 3mm variety,


The last thing I want to do is be a bother to anyone. I'll work it out somehow. Thank you very much for everything you've done to help he me, Chris and again, I sincerely apologize for any aggravation I've caused you.
 

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
FYI, Led strings that are made for 12V operation (which swings closer to 14V - 15V in autos) are going to be feeble at 9V.

They are already installed in my model. They work just fine at 9V. They are not meant to be blinding bright. This is a 1/350 scale model. The lighting has to be scaled back in proportion to size :)
 
Last edited:

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
The LED strips are barely bright enough to suit my needs at 9V, which is the rating of my power supply. If it were just the bi-colored LEDs it would be fine, but those strips would not be bright enough, or may not even come on at all with even a small voltage drop. How much "voltage drop are we talking about"? I have the strips in front of me as I type this, hooked up to a desktop power supply. If I lower the voltage to just 8.0V the LED strip is significantly less bright.

I would love to be able to use common cathode bi-colored LEDs, as it would greatly increase my options for purchasing my LEDs, but apparently using a PNP transistor is not a good option in this application.

I don't see your issue with PNP's or for NPN - Common Collector configuration. Both will work to drive the common cathode bi-leds but the PNP will require a change in the PWM code. The common collector NPN can't drive your led string though.

They are already installed in my model. They work just fine at 9V. They are not meant to be blinding bright. This is a 1/350 scale model. The lighting has to be scaled back in proportion to size :)

See your reply in bold. :confused:

I apologize, Chris. I didn't realize I was being a pest, but with all due respect, how can things get "resolved" when you ignore what I'm trying to tell you?
.

Yes, I'm probably guilty of that. I have been quite preoccupied this past week. I think I'm going to devote more time to my own projects. I'm sure Steve will help you along.

Chris

http://www.digikey.com/
 

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
CDRIVE said:
See your reply in bold.

I don't see the source of your confusion. I didn't say the LED strips did not work properly at 9V, I said they are barely bright enough at 9V, but bright enough nonetheless. I was simply pointing out to Richard that they would not be bright enough if there was much of a voltage drop below 9V....which is exactly what I wrote. :)

CDRIVE said:
I don't see your issue with PNP's or for NPN - Common Collector configuration.

My "issue" is that you recommended against it earlier in this thread.......

robertgzzt said:
Or if I use an NPN transistor, connect the base to the picaxe output pin, the collector to the +POS rail and the emitter to the LED's anode?

CDRIVE said:
No, that would be a 'Common Collector', also known as an 'Emitter Follower' amplifier. It's possible to use emitter followers here but I wouldn't recommend it over a 'Common Emitter' configuration as described here. > Connect the Emitter to GND and LED to Vdd through appropriate limiting resistor. The Base gets connected to the Picaxe through a 1K resistor to limit base - emitter current.


CDRIVE said:
Both will work to drive the common cathode bi-leds but the PNP will require a change in the PWM code. The common collector NPN can't drive your led string though.

I'll just create an entirely separate circuit to drive the LED strips. I can do that with an 08M2 as it'll only require a single pwm output.

Now, if I use the common anode bi-leds, those LEDs have to be driven through the cathodes. Would that not mean the LEDs are ON when the output is low and OFF when the output is high, BUT, if I drive them in the common-emitter configuration via an NPN or N-Ch MOSFET (cathodes connected to the drain), then the code does NOT have to be inverted, is this correct?

I would rather use common cathode, again, this gives me much better options. I can buy them in 5MM or even 3MM size, but I'm not clear on the best way to drive them. I don't give a hoot if the code has to be inverted. I don't see why anyone would find it difficult to invert two numbers (0-400 and 400-0).
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
Well I think I've caught up on some of my own projects. This gives me some time to answer your last reply. Actually, this post isn't necessarily exclusively for you. It's intended more for any nubes,... electronics or uC.

Why I didn't recommend Emitter Follower Drivers for use with uC's :

This requires multiple reasons that are not an issue with experienced electron heads but will most assuredly be confusing for nubes. After all we have more threads asking how to determine LED current and calculate limiting resistors than any other topic.

(1) An Emitter Follower will loose ~ .7V of LED drive voltage as measured from the emitter to ground. If a Darlington is used you will loose ~ 1.4V.

(2) Because of (1) series strings of LED's are out of the question. Especially for LED's with high voltage drop characteristics. Even a single Blue LED is pushing the envelope and could cause issues on battery operated uC's as they drain.

(3) Many embedded programmers are now using 3V uC's , which makes Emitter Followers nearly all but useless with them.

Why I did not recommend PNP's.

(1) Because PNP's were originally designed to be used with a negative supply rail. To use them with a conventional (+) supply rail we have to invert them by connecting the Emitter to the (+) rail. Most nubes find the inverted operation of them very confusing.

(2) Every uC output pin has a logic 1 (high) spec. If this voltage is less than the Vdd by as little as .7V a PNP will not turn off completely. If this happens it forces the programmer to modify the code to place the pin in an Input state or Off. In the case of a Picaxe PWM pin this is not an option. The other option would be additional components by adding a Diode in series with the Base.

So, there it is in a nutshell. None of the above is an issue for pros because they're aware of the pitfalls and know how to deal with them.

Chris
 

robertgzzzt

Jun 26, 2013
98
Joined
Jun 26, 2013
Messages
98
I've got some common cathode blue/yellow bi-colored LEDs that I picked up on e-bay from a Chinese vendor. I have a 20M2 on the breadboard with two of those blue/yellows, the two blue anodes connected to one pwm output and the two yellows connected to another pwm output, through two BC548s in an emitter follower config (collector to 5V positive rail, base to the uC output via 1K resistor, and emitter to LED anodes via CL resistors). It seems to be working fine. The blue side of these LEDs is good and bright, but not so much with the yellow, but I don't think that has anything to do with the way I have them connected, as the yellows are also weak when running them directly from the benchtop power supply at their rated forward voltage with no CL resistor.

An Emitter Follower will loose ~ .7V of LED drive voltage as measured from the emitter to ground. If a Darlington is used you will loose ~ 1.4V.

Then should I figure ohm's law based on a supply voltage of 4.3V (when using emitter follower)?

One thing I'm still not clear about, If I use those 10mm common anode LEDs (the only common anodes I could find in blue/yellow), so then I can connect my NPN transistors in the "common emitter" configuration (base to uC via 1K resistor, emitter to ground, collector to LED cathodes via CL resistor, and anodes to positive rail), wouldn't my code have to be inverted since the LEDs are being controlled from the cathode side?
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
Then should I figure ohm's law based on a supply voltage of 4.3V (when using emitter follower)?

Yes but 4.2V is more realistic.

One thing I'm still not clear about, If I use those 10mm common anode LEDs (the only common anodes I could find in blue/yellow), so then I can connect my NPN transistors in the "common emitter" configuration (base to uC via 1K resistor, emitter to ground, collector to LED cathodes via CL resistor, and anodes to positive rail), wouldn't my code have to be inverted since the LEDs are being controlled from the cathode side?

No, the collector current remains in phase with the base current. It's the collector voltage that's 180 deg out of phase with the base voltage.

Chris
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
through two BC548s in an emitter follower config (collector to 5V positive rail, base to the uC output via 1K resistor, and emitter to LED anodes via CL resistors). It seems to be working fine.

I missed this earlier. Emitter Followers don't require a base current limiting resistor.

Chris
 
Top