I/O Expander with PWM Input

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


I have an array of 30 LEDs with 30 transistors driving them (one for each LED), with the base of each transistor being driven by output pins of an MCP23017 I/O expander (so that I can turn on/off each LED individually):

 

 

I want to add a master brightness control (i.e. one control for all of the LEDs), and my plan is to implement this using the PWM output of my microcontroller.

 

I want all of the "Enable" signals from the I/O expander to be strobed with the PWM signal (i.e. an AND between the PWM signal and the enable signals) - the MCP23017 does not have this functionality, so does anyone know of an I/O expander chip that can do this (i.e. has a "strobe" or "waveform" input that is ANDed with the output pin signals)? Or any alternative solutions?

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

You can buy chips designed to drive LEDs which have a dimming function. Try NXP.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Thanks for pointing me in the right direction Brian - I've found some NXP chips that do exactly what I need.

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

Note that this arrangement is can be problematic if your chip is running at 3.3V...you will only get about 2.6V to drive the led (not good for many leds that take >3V!).  Better to switch the gnd, then it is not a concern (don't forget a base resistor).  In either case, don't forget your led resistors so your leds don't burn up!  Note some driver chips can limit the led current using one resistor  or pin selection to set drive current for all the leds

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Wed. Jul 3, 2019 - 02:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

+1 on what avrcandies said about having the transistor emitter connected to ground,

a resistor in series with the transistor base, and a resistor in series with the LED.

 

You can control the LEDs brightness by using a FET circuit (npn + pnp) to switch the Vcc to all the LEDs.

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

Agree with the above.

The LEDs and their current limiting resistors would be better placed on the high side of the transistor, with the transistor switching to ground.

An NPN transistor will work as the switch with a base resistor.

 

I might suggest changing the transistor to a small NFet, (2N7000, for example).

It will be a more efficient switch, and will burn up less energy as heat within the transistors.

As an NFet it doesn't need a series "Base", (Actually Gate), resistor, but one often puts a high value resistor from the Gate to Ground to hold the Gate low as the micro powers up, and the I/O pin is initially an input, and isn't actively driving the transistor.

 

Certainly it is possible to put a Fet in the Vcc or the Ground line, to turn all of the LEDs an and off together.

That requires a little bit of design work to drive a PFet high side driver connected to Vcc from the micro's I/O pin.

You haven't stated if the Vcc for the LEDs is the same as the Vcc for the micro or not, (e.g. is everything powered by +5V, or are the LEDs powered by +12V, and the micro by +5V, etc.?)

 

Another option, of course, is to put the Led and its resistor on the high side of the transistor, and the transistor connects to Ground.

 

Now put a Nand gate between the micro's I/O Pin and the Transistors, one Nand gate for each transistor.

The micro drives one input to the Nand, the PWM signal drives the other input to the Nand.

Now the PWM will control the LED's on time, and the micro is essentially a Master On/Off for each channel.

 

That would be an old school hardware approach to solving your problem.

 

Although wiring up a large board with 30 LED drivers would be a fun hardware project, as mentioned above LED driver chips make this low level hardware driver approach obsolete.

 

Finally, with a "fast enough" micro, one could do the PWM for each channel in software, and just use the simple transistor driver for each channel, without implementing a hardware PWM dimmer driver.

 

Lots of options.

 

JC

 

 

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

Thanks for all the suggestions and advice. I think that I'm going to go with replacing the IO expanders with PCA9685 chips - I need to read the data sheet more carefully, but it looks like I can ditch the transistors using this and just have series resistors, as avrcandies said.

 

I never thought about switching the GND side of the LED - I'll look into that to better understand the effect of it. Regarding using FETs/NFETs, I really need to dust off the electronics books and re-learn what I've long forgotten - it seems like I need to move beyond my half-baked remembrances.

 

I did think of trying something like DocJC's NAND suggestion, but increasing the part count and sorting out all of the additional routing would definitely be a last resort!

 

The software PWM is an interesting idea, but I'm not sure that I could get a high-enough frequency going, as the enable signals are outputs of IO expander chips with which I am communicating over I2C. I'm tempted to give that a try just for fun, mind you...

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

I don't know the PCA9685 but a regular Maxim MAX7219 can control 64 LEDs in an 8x8 matrix.   And control brightness.

All with 3 GPIO pins (or use SPI bus).

 

David.

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

DocJC wrote:
Finally, with a "fast enough" micro, one could do the PWM for each channel in software, and just use the simple transistor driver for each channel, without implementing a hardware PWM dimmer driver.
One such is the AVR32 UC3L that has a lot of hardware PWM.

AVR limitations are lack of PWM channels and lack of PWM resolution (typical; there are a relative few exceptions)

 

AT32UC3L0256 - Microcontrollers and Processors

[datasheet]

PWM Channels on All I/O Pins (PWMA) – 8-bit PWM with a Source Clock up to 150MHz

AVR32 UC3C have a reduced number of PWM controller channels (4) though increase the precision to 20 bits (more PWM on the 6 16b TC)

AT32UC3C2512C-AUTOMOTIVE - 32-bit PIC Microcontrollers

Servo Control - Xcelerator Block | Alorium Technology

...

However, generally speaking, Arduino-based servo control solutions suffer from servo jitter and twitching due to the 8-bit micro not being able to maintain precise timing required on the Pulse-Width-Modulation (PWM) signal that controls the servo.

...

By implementing the PWM functionality as a standalone hardware block in the FPGA, perfectly timed signals are continuously supplied to the servos without taxing the microcontroller at all.  Even better, the number of servos being driven can scale up without any additional burden to the board since they are each being controlled by a standalone XB block.

...

 

"Dare to be naïve." - Buckminster Fuller

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

If you are using a logic expander, why use transistors (unless you need some high currents)??...let the expander do the work!  Just need resistors.

 

You can run all of your leds to a single n chan mosfet to pwm the gnd connection & control the brightness...this pwm signal is best to come right from the avr pin

 

also, take a look at this ...does all the work for you

https://www.mouser.com/datasheet/2/408/TB62747AFG_datasheet_en_20170124-771489.pdf

 

Note, instead of grounding the resistor (per datasheet) , you should be able apply a pwm RC voltage to the resistor to control the brightness.  The resistor mimics a current sense*---when enough current is flowing the "large" voltage drop throttles back the drive.

If you apply a voltage rather than ground, it appears to the chip that more current is flowing than actually is....so it dims it down. 

 

* from datasheet R*Iled=approx 16.8

 

edit:fixed datasheet link

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Jul 5, 2019 - 07:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The MCP23017 data sheet says:

Maximum current out of Vss pin..................................150 mA
Maximum current into VDD pin.....................................125 mA
Maximum output current sunk by any output pin........25 mA
Maximum output current sourced by any output pin...25 mA

So if I drive 15 LEDs with ~25 mA each, that is 375 mA total, which is more than the total maximum rating of the chip... if I have understood the maximum ratings correctly. So that's why I was using the transistors.

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

So if I drive 15 LEDs with ~25 mA 

Wow---why so old-school high current?  You can get some pretty bright leds now that only need maybe 2-3 ma.  How bright do you need?

Yes, you are correct about overloading that chip. 

go back--i added some chip info to my previous post

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Jul 5, 2019 - 06:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://toshiba.semicon-storage.com/us/design-support/search/multiSearch.1.1.TB62747AFG.html?mskw=TB62747AFG&la=us

 

edit :

Thanks! ... I would of suggested a CPLD to get that amount of current.

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Fri. Jul 5, 2019 - 07:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

30 leds- you could multiplex these and probably avoid the port expander. Other possibilities is to use a device like a max7219 which is probably much the same cost as your port expander - and save on the thirty transistors/resistors. There’s also a chinese chip used in a lot of the 4digit displays you see on alibaba, the TM1637. Only usd $0.1909 for 1 at lcsc.com. Not sure if it does individual leds, so read the datasheet.

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

Since you are already using I2C, have a look at the TLC59116:

 

https://www.mouser.com/ProductDetail/Texas-Instruments/TLC59116ITPWRQ1?qs=sGAEpiMZZMvYKGyZxp8jxipEVi4QFZfK7G8tv4tdAUQ%3D

 

It has current limiting, dimming, group dimming, etc. and can detect failed LEDs.

 

I have been using it for about 10 years and it has worked out well.  I drive 20ma LEDs in outdoor ride-on railroad signals (ATMega1284P for processor):

 

http://www.minirailsolutions.com/

 

Regards,

 

Chuck Hackett