Author Topic: Which micro to use for fading 15 LEDs and cutom presets?  (Read 26261 times)

0 Members and 1 Guest are viewing this topic.

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
Which micro to use for fading 15 LEDs and cutom presets?
« on: December 20, 2015, 08:33:41 am »
5 years later edit: I was a preeeetty dense 15 year old, lol. Everyone who put up with me here is a saint! I never made this, because, well, I was too dense to do so  :-[

Hello! New member here! Had to create a gmail just becuase my hotmail wasn't getting the activation email!!
Anyway, I am still in highschool, planning to study electrical engineering. I wanted to make a gift to all my friends, using a micro that would drive 15 LEDs in a randomly fading in and out order. LEDs in the sides of the box and in the front where my friends' names would be. Each letter from their names would have a corresponding LED. When a button is pressed the front LEDs would stop fading in and out, then one at a time they would light up in a sequence that would make a word. example: mad dad from Adam (just a lil gag).

So in summary, aside from programming I would need a micro that could blink and fade 15 LEDs, And accept a button press as an input.
I dont know anything about the micro controller specifics, but i think i would need 15 PWM channels. Ive only found one micro (an atmega) with such capability, but that costs 10$ a piece (please nothing more than 1.5$ a piece as i am building 10-15 of these...

I was thinking about using shift registers with a 8 pin micro, here is a part i found to meet my specifications: TLC5943, any advice?
also i did try arduino with the poor dust collecting arduino uno i have (never had the time, or the need to), I do program lightly in VB and C++...

in case my post is unclear i need recommendation on what to use, either a shift register and a micro or a micro alone, and which is most suitable?
« Last Edit: September 19, 2020, 03:14:46 pm by AnasMalas »
 

Offline owiecc

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: dk
    • Google scholar profile
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #1 on: December 20, 2015, 08:57:00 am »
You don't need to use PWM. You can use a pulse code modulation. It requires only one timer and you can dim as many LEDs as you have GPIOs. The scheme works by setting the timer in consequently longer pulses and flipping the GPIO pin if necessary. Pulse 1 is T. Pulse 2 is 2*T. Pulse 3 is 4*T. This way you can code the LED intensity in binary and you only need one timer. You can find the details in: "Extended parallel pulse code modulation of LEDs", I. Ashdown - SPIE Optics & Photonics, 2006. PM me if you cannot find the article.
 
The following users thanked this post: AnasMalas

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #2 on: December 20, 2015, 09:33:33 am »
You don't need to use PWM. You can use a pulse code modulation. It requires only one timer and you can dim as many LEDs as you have GPIOs. The scheme works by setting the timer in consequently longer pulses and flipping the GPIO pin if necessary. Pulse 1 is T. Pulse 2 is 2*T. Pulse 3 is 4*T. This way you can code the LED intensity in binary and you only need one timer. You can find the details in: "Extended parallel pulse code modulation of LEDs", I. Ashdown - SPIE Optics & Photonics, 2006. PM me if you cannot find the article.

That thing is really too advanced for me (the pdf), i understood the general scheme of things though.
would ATmega328P be good for my task if i can learn to PCM?
 

Offline owiecc

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: dk
    • Google scholar profile
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #3 on: December 20, 2015, 09:56:25 am »
I think that any micro will be good. That is the beauty of PCM. Use the one you know how to program or the one you have a dev board.
 
The following users thanked this post: AnasMalas

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12807
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #4 on: December 20, 2015, 10:20:34 am »
I've done software 3 channel (RGB) LED dimming (128 levels, 60Hz update rate) in C on a 4MHz  PIC16F675 using the not very efficient HiTech C free mode.    I don't see any particular problems doing it on an ATmega328P as long as you stay away from the horribly inefficient Arduino libraries and hit the hardware at the register level directly.  It has the added advantage that you can use a cheap multipack of chinese Arduino clone boards to keep the total cost down - just add resistors, high efficiency LEDs, a button and some code.

See: http://www.batsocks.co.uk/readme/art_bcm_1.htm for a more accessible description of the modulation scheme.
 
The following users thanked this post: AnasMalas

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #5 on: December 20, 2015, 10:27:01 am »
KISS. Use addressable RGB LEDs.

http://www.instructables.com/id/Use-a-1-ATTiny-to-drive-addressable-RGB-LEDs/

Note that you only need _one_ output pin to control a bunch of these LEDs, dimming, changing color, individually addressable, etc.

Here's a demonstration unit I made using an Arduino Uno and some WS2812 NeoPixels from AdaFruit. They are available singly, and in preassembled strips and rings. And even, IIRC, in 5mm 2-lead package, if the SMDs are not desired.



Packaged up and driven by a Pro Mini, with several different functions in the program sketch:



« Last Edit: December 20, 2015, 10:36:55 am by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 
The following users thanked this post: AnasMalas

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #6 on: December 20, 2015, 10:33:55 am »
Yeah, keep it simple, with the right panel/strings you can do a lot with just a little.

1024 RGB LEDs (3072 PWM channels) controlled by MBI5024GF (16 channel constant current LED driver)
http://belchip.by/sitedocs/00006155.pdf

That looks a lot like this TI TLC59282 chip
http://www.mouser.com/ds/2/405/tlc59282-557358.pdf


 
The following users thanked this post: AnasMalas

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #7 on: December 20, 2015, 11:35:52 pm »
Thanks everyone, although I wasnt really planning on using tri-color LEDs, but i might consider it!
I have some questions:
What would happen if i used inefficient code? As i myself dont have much experience in anything but calculating the surface area of a wall and saying hello world  ;D
Second question, to miguelvp: what is the difference between that and TLC5943? TLC59282 allows PCM while TLC5943 allows PWM? is that all?

so you all are suggesting using a small micro with a shift register instead of using a bigger micro such as ATmega328P? And throwing PWM out of my mind.

also what was in my mind is to first have a simple program the randomly fades in or out a random LED.  That should be a little code only, correct? then have sections for each LED that need to be called, such that i can have a code similar to(this is just a psuedocode):
if button = pressed
  Wait = 100 //amount of delay in the program blocks, so that i dont need to retype the whole block for a different delay.
  LED = 4 //which LED to fade
  call "LED"
  Wait = 40
  LED = 15
  call "LED"

while the code block would be like
LED:
  fade in (Pin LED) //Here LED is an integer. so pin #
  delay wait  //Here wait is a number, how much delay
  Fade out (pin LED)


is that a good way to do it? or is it inefficient?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12807
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #8 on: December 21, 2015, 12:21:46 am »
If your code is too inefficient, it takes too long to execute.  If its something time-critical like controlling the brightness of multiple LEDs, they will flicker or strobe instead of dimming smoothly.  WS2812 NeoPixels have quite tight timing constraints to control them at all.  The other LED drivers that have an interface with a serial clock signal are somewhat more forgiving of sloppy (but correct) code.
 
The following users thanked this post: AnasMalas

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #9 on: December 21, 2015, 02:10:16 pm »
Quote
either a shift register and a micro or a micro alone, and which is most suitable?

Fairly simple:

1) generate a pwm signal to control all the LEDs.
2) use 15 pins, either directly from the mcu or through shift registers, to turn on / off those LEDs individually.

This will route the pwm signal to 15 leds and you can see them fad in / out.

In case you are using a shift register with output enable pins, you can simplify the design by applying the pwm signal to the output enable pin.

A slightly more complicated approach can be used to AND or OR a few pwm signals to create differing speeds of "fading".
================================
https://dannyelectronics.wordpress.com/
 
The following users thanked this post: AnasMalas

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #10 on: December 21, 2015, 02:33:27 pm »
ok, an exercise in learning...
one microcontroller
one PWM pin (optional)
three 595 shift registers (up to 9)
eight RGB LEDs (up to 24)

shift the LED patterns in real-time to achieve bit banging PWM
the hardware PWM is to simplify 'fade all' but is not needed.
thus demo is running a string of 72 bits (only 24 are connected to LEDs)

http://youtu.be/eewAOwAOzpw
Don't ask a question if you aren't willing to listen to the answer.
 
The following users thanked this post: AnasMalas

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #11 on: December 21, 2015, 02:54:37 pm »
Quote
either a shift register and a micro or a micro alone, and which is most suitable?

Fairly simple:

1) generate a pwm signal to control all the LEDs.
2) use 15 pins, either directly from the mcu or through shift registers, to turn on / off those LEDs individually.

This will route the pwm signal to 15 leds and you can see them fad in / out.

In case you are using a shift register with output enable pins, you can simplify the design by applying the pwm signal to the output enable pin.

A slightly more complicated approach can be used to AND or OR a few pwm signals to create differing speeds of "fading".

i want the LEDS to indevidually and randomly fade
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #12 on: December 21, 2015, 04:52:18 pm »
i want the LEDS to indevidually and randomly fade
See vid above.
If you just want to copy what someone else has done, ask.
if you want to know how to approach it, you're well on the way.
The code is not simple, beginner stuff, but is straightforward.
The biggest challenge on a minimal, low-end CPU is keeping the timing tight for smooth fades and animation.
Don't ask a question if you aren't willing to listen to the answer.
 
The following users thanked this post: AnasMalas

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
The easiest person to fool is yourself. -- Richard Feynman
 
The following users thanked this post: AnasMalas

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #14 on: December 21, 2015, 05:33:03 pm »
-- agree with the addressable LEDs, but almost all the issues of developing your own code still apply.
I wrote that bit banging PWM before WS28xx were around, and it was worth the effort.
Oddly enough, I'm currently working on a project controlled with DMX, and 100 tiles each containing 384x WS2812 LEDs !   38400 RGB pixels!

All knowledge is good, unless we waste it.
Don't ask a question if you aren't willing to listen to the answer.
 
The following users thanked this post: AnasMalas

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #15 on: December 21, 2015, 06:16:21 pm »
i want the LEDS to indevidually and randomly fade
See vid above.
If you just want to copy what someone else has done, ask.
if you want to know how to approach it, you're well on the way.
The code is not simple, beginner stuff, but is straightforward.
The biggest challenge on a minimal, low-end CPU is keeping the timing tight for smooth fades and animation.

I am sorry if i am not being clear enough, or if i am not getting all of what you are saying. I am still new to this stuff and when i read some of the stuff you all write i sort of get the direction, then the text seems to oppose itself and i get confused...

Lets leave learning code aside for now. i was thinking and i got to the following conclusions. tell me if i got anything wrong.
-I dont think using shift registers for my particular project is a good idea if all i need is PCM, as it will just add complexity in code (forgot where i read this) and would need me to print my own PCBs because i could not find a single through hole shift register. Living in the UAE i can not get PCB printing anywhere if i want reasonable prices, and shipping from anywhere to here is 15$ for the first half kilo...
-I just thought about how would i program the thing. so i did some research and got that i need a programmer, one that isnt too cheap or readily available in UAE, thus using an ATmega328P with arduino bootloader and programming the chip using my arduino uno would be cheaper and easier.
-Then using the bare chip with a crystal or a resonator and all the other needed passives programmed with PCM i can control my 15 LEDs

I want to start working asap as i have a small holiday to go back to study, and the next holiday i have to give the gifts to all my friends.
I am really sorry if i am making you cringe, but please understand that i am not only a new comer to micros, but also electronics in general. i only started knowing what the heck a transistor was last year when i turned 15, i always had a passion for electronics, but due to where i live i never had access to any books, magazines, or even components themselves. Even salvaging wasnt possible because of my father's 20 watt mains soldering iron that he used to file and "clean it" by dipping the tip in 30 cent flux.....
« Last Edit: December 21, 2015, 06:18:20 pm by AnasMalas »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #16 on: December 21, 2015, 06:48:39 pm »
Quote
i want the LEDS to indevidually and randomly fade

Those same words can mean different things to different people under different context.

It is rare to have a mcu that offers that many "independent" pwm channels - typically up to 4 pwm channels on low-end chips and more on those 32-bit ARMs. So if you want to implement truly independent fading, you will need to drive your leds in groups and implement a bus protocol.

Again, what you mean by "i want the LEDS to indevidually and randomly fade" determines your approach.
================================
https://dannyelectronics.wordpress.com/
 
The following users thanked this post: AnasMalas

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: pl
  • Troll Cave Electronics!
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #17 on: December 21, 2015, 07:05:19 pm »
You can use 8/16 channel led drivers which are driven by serial interface compatible with SPI. With an advanced chip you don't need much else be sides almost any micro to generate the serial data. Other than that there are I2C PWM drivers made by NXP or TI,  i forgot which and there are normal shift register like 74HC595.

Sent from my HTC One M8s using Tapatalk.

I love the smell of FR4 in the morning!
 
The following users thanked this post: AnasMalas

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12807
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #18 on: December 21, 2015, 07:17:36 pm »
There is no need for hardware PWM or dedicated LED controllers to individually dim/fade even quite a large number of LEDs.  Simply use one of the more efficient alternative modulation schemes instead of software PWM.  e.g. I know of one project that implemented a 16x16 RGB matrix using a 20MHZ PIC16 (about half the processing power of an ATmega328 Arduino)  and a string of 74HC595 shift registers to get enough output lines.  It scanned 16 rows, and for each row did BAM (a.k.a BPM) to dim each individual LED. That was 768 LEDs + a serial interface for PC control, and stretched the RAM capacity and processing speed of the PIC to its absolute limits.

For the O.P.'s simple project, given the constrains on component availability and programming tools mentioned, either an Arduino, used for the bootloader and as an ATmega328 development board, or a bare ATmega328P on some sort of protoboard would be entirely sufficient.    The current limiting series resistors could be soldered directly to the LED pins and covered in insulating sleeving if an Arduino board is being used without a protoshield.

Its then just a matter of software - start with a few LEDs in a solderless breadboard, all on the same I/O port and work up from there.
 
The following users thanked this post: AnasMalas

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #19 on: December 21, 2015, 10:03:42 pm »
+1
understand the techniques and terminology before you try to fly.
PCM is not PWM (similar idea, but for a completely different purpose)
As you are starting from the ground level, probably an Arduino (almost any one), and a string of 'neopixel' RGB LEDs will push you along a lot further than any introductory chat on this forum.

Those parts will do exactly what you want, but you'll still have plenty of beginner software to write.
Once the LEDs are blinking, fading and chasing - you can explore 'how that's done' inside the LED modules themselves if necessary.
Don't ask a question if you aren't willing to listen to the answer.
 
The following users thanked this post: AnasMalas

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #20 on: December 21, 2015, 10:12:40 pm »
I'll just point out that if you start talking about WS2812 smart LEDs, or even some of the semi-intelligent external LED controller chips, you might start to get more expensive than, say, multiple ATmega168 processors (each with 6x hardware PWMs.)  Not really RELEVANTLY "more expensive" (maybe $20 for a complete unit instead of $10), but still something to think about.

If you're more interested in playing with the artistic possibilities of 15 controllable LEDs than you are in optimizing PWM software, then an Arduino (pro mini clone: <$5), plus Adafruit NeoPixel library, plus some neopixels is definitely a strong contender, even if you didn't need RGB capabilities.  It's a very nice library; abstract and easy to use; patterning ideas become reality REALLY quickly.
 
The following users thanked this post: AnasMalas

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #21 on: December 21, 2015, 10:41:35 pm »
I did a quick experiment: atmega328@8Mhz, 16-bit output under software pwm - see attached below. pwm period of 8ms, 250 shades. 1kb flash used.

The routines used about 92% of CPU processing power (~7MIPS), no optimization. Better results possible with pcm and more efficient coding/optimization.

================================
https://dannyelectronics.wordpress.com/
 
The following users thanked this post: AnasMalas

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #22 on: December 22, 2015, 04:28:17 am »
Alright, thanks everyone. Ive settled my mind on ATmega328P. just a question: Are EBAY listings fake? or are they truly OEM? Here is an example:
http://www.ebay.com/itm/NEW-ATmega328P-PU-for-Arduino-UNO-bootloader-ATMEL-2014-/181388552457?_trksid=p2141725.m3641.l6368

BTW, i do not have an oscilloscope and i dont have the money for one, is it necessary? also i am using a very cheap (1.5$ with shipping) power bank to power the project. the output seems awful, with a no load voltage of 3.18v, and then depending on the load, it goes from 5.018v (with the smallest load) to 5.180v (with the biggest load). it also has a USB max amperage of 8.2 A!!!!!!!  :scared:
will it be sufficient? or should i buy some sort of linear board/regulator that regulates the voltage (say to 3.3 volts)?
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #23 on: December 22, 2015, 05:58:55 am »
Quote
pwm period of 8ms
125 Hz, which I'd rate as "marginal."  OTOH, you said it probably had optimizations that could be applied, so it might be safe (and you can always do 6 outputs in HW.)   OTTH, a beginner might write significantly worse code.

 
Quote
i do not have an oscilloscope and i dont have the money for one, is it necessary?
Not necessary.

Quote
i am using a very cheap power bank... it goes from 5.018v to 5.180v  ...  will it be sufficient?
It should be fine.

Quote
it also has a USB max amperage of 8.2 A!
Don't short it out;  A fuse or polyfuse might be a good idea.   8.2A is in "burn your finger, melt small wires, start fires, and maybe damage the battery into a dangerous state" territory.

 
The following users thanked this post: AnasMalas

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #24 on: December 22, 2015, 07:46:57 am »
Quote
i do not have an oscilloscope and i dont have the money for one, is it necessary?
Not necessary.

Quote
i am using a very cheap power bank... it goes from 5.018v to 5.180v  ...  will it be sufficient?
It should be fine.


 i asked about the ocilloscope because i think the output power of the powerbank is not clean. dont MCUs hate unclean power? i am worried about some sort of electrical noise or something similar since all these are only seen by oscilloscopes..
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf