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

0 Members and 1 Guest are viewing this topic.

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Which micro to use for fading 15 LEDs and cutom presets?
« on: December 20, 2015, 08:33:41 am »
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?
 

Offline owiecc

  • Frequent Contributor
  • **
  • Posts: 292
  • 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.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
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: 292
  • 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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 8143
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.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 1927
  • 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
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5549
  • 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


 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
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: 8143
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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • 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/
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2103
  • 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.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
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: 2103
  • 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.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 1927
  • Country: us
The easiest person to fool is yourself. -- Richard Feynman
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2103
  • 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.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
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: 8229
  • 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/
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1548
  • 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!
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 8143
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.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2103
  • 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.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3099
  • 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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • 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/
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
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: 3099
  • 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.

 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
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..
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #25 on: December 23, 2015, 06:00:38 am »
No one replied about the ebay sellers... but i also have another question: where to find an example for code of PCM that is really reliable, optimized, and fully working? i want to start trying to understand this topic deeply, reverse engineering an example would benefit me i think...

also, what is better for PCM; higher or lower clock rates? would higher clock rates damage the MCU somehow?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 8143
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #26 on: December 23, 2015, 08:03:40 am »
I dont know where you will find a good ATmega example for PCM.  Many Arduino examples are over-complex or badly written.   Faster is better for the MCU clock speed, as long as you stay under its maximum rated speed.   A faster clock speed does however make the MCU use a bit more power - but that would be negligible compared to the dissipation in the LEDs.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3099
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #27 on: December 23, 2015, 10:40:13 am »
You keep saying "PCM", but I don't think that's what you want, or even what you mean.

Here's a trivial software PWM for 5 leds and 127 levels.  Easily expandable to more leds.  Whether it runs "fast enough" is an interesting question.
This code ran acceptably on a pic12f675 using the internal 4MHz clock, which is about 16x slower than a 16MHz AVR.

Code: [Select]
   while (1) {  // forever
      getbright();
      for (level_delay = 50; level_delay != 0; level_delay--) {
         pwm1 = bright1;
         pwm2 = bright2;
         pwm3 = bright3;
     pwm4 = bright4;
     pwm5 = bright5;
     led_all_on();
         for (pwm_delay = 128; pwm_delay !=0; pwm_delay--) {
         /*
          * We have a random number in each PWM between 1 and 128
          * and we're going to have 128 cycles of delay.  So each
          * decremented output can only cross zero once, at which
          * time we toggle the output state.
          */
             if (--pwm1 == 0) {
             led1_off;
         }
             if (--pwm2 == 0) {
                 led2_off;
             }
             if (--pwm3 == 0) {
                 led3_off;
             }
             if (--pwm4 == 0) {
                 led4_off;
             }
             if (--pwm5 == 0) {
                 led5_off;
             }
         } /* time for new PWM cycle */
      } /* time for new brightness */
   } /* while forever */
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 6589
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #28 on: December 23, 2015, 11:17:14 am »
I was going to suggest an 8051. Some of them do have 16-channel PWM.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #29 on: December 23, 2015, 07:21:03 pm »
You keep saying "PCM", but I don't think that's what you want, or even what you mean.

Here's a trivial software PWM for 5 leds and 127 levels.  Easily expandable to more leds.  Whether it runs "fast enough" is an interesting question.
This code ran acceptably on a pic12f675 using the internal 4MHz clock, which is about 16x slower than a 16MHz AVR.

Code: [Select]
   while (1) {  // forever
      getbright();
      for (level_delay = 50; level_delay != 0; level_delay--) {
         pwm1 = bright1;
         pwm2 = bright2;
         pwm3 = bright3;
     pwm4 = bright4;
     pwm5 = bright5;
     led_all_on();
         for (pwm_delay = 128; pwm_delay !=0; pwm_delay--) {
         /*
          * We have a random number in each PWM between 1 and 128
          * and we're going to have 128 cycles of delay.  So each
          * decremented output can only cross zero once, at which
          * time we toggle the output state.
          */
             if (--pwm1 == 0) {
             led1_off;
         }
             if (--pwm2 == 0) {
                 led2_off;
             }
             if (--pwm3 == 0) {
                 led3_off;
             }
             if (--pwm4 == 0) {
                 led4_off;
             }
             if (--pwm5 == 0) {
                 led5_off;
             }
         } /* time for new PWM cycle */
      } /* time for new brightness */
   } /* while forever */

The very first reply to this topic was talking about PCM(Pulse Code Modulation) which is where i got the idea from. The MCU i want to use has only 6 PWM pins while i need to run 15 LEDs, also a shift register is out of consideration because i cant seem to find any through hole...
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2103
  • 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 #30 on: December 23, 2015, 09:21:35 pm »
 @AnasMalas - I think you need to go back to page 1 of this thread, re-read (and understand) what each poster has said.

Virtually all the answers you want are already there.

If you'd like me to design and build the project for you send a PM, but you won't learn anything if I do it.
Or better still - find a hacker/maker space near your home, and someone there will help you out.

Through hole shift registers -- 74xx595 and others
Through hole LED drivers -- many
Processors -- many (Start with an Arduino for lots of simple online help).
Progress further once you know what you're aiming at, and the basics of cpding for hardware or software PWM.
The code example by westfw is a simple starting point for software PWM (maybe you can get it working, then tune it to use pwm[X] instead of separate (pwmX) counter variables).

For the time being forget you have ever heard about PCM - or look it up on Wikipedia.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2103
  • 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 #31 on: December 23, 2015, 09:27:16 pm »
Sorry - a bit of help once you figure out what you're doing...
This uses 595 Shift registers to drive up to 24) RGB outputs (72 'pins') from a 16MHz PIC
It uses software PWM - the (single) hardware PWM output can be ignored, as it is a 'master' fade - not needed for your project.

The main() loop simply steps through a number of effects.  You can call the individual functions however you want.   This is the exact code running in the video clip that I posted earlier.
« Last Edit: December 23, 2015, 10:05:32 pm by SL4P »
Don't ask a question if you aren't willing to listen to the answer.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #32 on: December 23, 2015, 10:03:18 pm »
Quote
The routines used about 92% of CPU processing power (~7MIPS), no optimization. Better results possible with pcm and more efficient coding/optimization.

for comparison, the software pcm routines used about 4% of the CPU processing power (<0.5MIPS), everything else the same.
================================
https://dannyelectronics.wordpress.com/
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1303
  • Country: no
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #33 on: December 23, 2015, 10:42:35 pm »
Quote
The routines used about 92% of CPU processing power (~7MIPS), no optimization. Better results possible with pcm and more efficient coding/optimization.

for comparison, the software pcm routines used about 4% of the CPU processing power (<0.5MIPS), everything else the same.

How to you monitor cpu processing power?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #34 on: December 23, 2015, 11:36:38 pm »
I used the mcu to flip a pin and counted the pin flips over a period of time. Compared the count when the pwm/pcm routines are running vs. the count when the pwm/pcm routines are not running.
================================
https://dannyelectronics.wordpress.com/
 

Offline ElectricGuy

  • Regular Contributor
  • *
  • Posts: 238
  • Country: pt
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #35 on: December 24, 2015, 12:05:32 am »
You can also search for Bit Angle Modulation BAM. It is other technic no fade leds.
Thank you!
Regards
ElectricGuy
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2103
  • 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 #36 on: December 24, 2015, 03:08:51 am »
You can also search for Bit Angle Modulation BAM. It is other technic no fade leds.
I'd never heard of bit-angle modulation (BAM)....  went over to Wikipedia and others, and it just looks like software PWM...?  And yes - you can do fading etc in software PWM.

Perhaps the name originates from AC waveform switching wrt AC dimming against the phase angle - but in that case is almost completely irrelevant to this conversation.  Enlighten me!
Don't ask a question if you aren't willing to listen to the answer.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3099
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #37 on: December 24, 2015, 03:46:15 am »
It looks to me like the PCM-like functions and the simpler counter-based PWM will end up requiring similar cpu performance (in order to handle the LSBs), but the PCM scheme would free up MUCH more CPU time to do other things (during the MSBs.)
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 8143
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #38 on: December 24, 2015, 07:08:50 am »
That's for sure + there are a couple of tricks to further reduce or redistribute the CPU load in the ISR, like 'pivoting' the brightness levels into bit column order in the main program, not the ISR, so all the ISR has to do is spit out a word per port and increment the index to point to the next bit's line in the BAM table.  Also you can cache the data to output for the next bit in fixed locations, and in the LSB, defer updating the cache till the next interrupt (for the MSB).  On a MCU without hardware auto-increment indirect addressing modes, that can shorten the ISR for the LSB enough to let you significantly increase the refresh rate.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #39 on: December 24, 2015, 08:46:59 am »
Ive heard about BAM before, thought it was the exact same as software PWM, which is what is thought PCM is (When i read the PDF article that owiecc posted.)
I know PCM is mainly a method of Audio decompression that was later discovered to work as software PCM...

now i am even more confused, i also took amyk's suggestion and found some chips that have 15+ PWM outputs. and while at it i had another go with the complicated parameter search and found even more chips...

Now that i have the option if having PWM channels or do "software PWM", what do you recommend? What would be easier to code? 
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 8143
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #40 on: December 24, 2015, 09:21:27 am »
PCM, BAM/BCM and PWM are rather different.  All can be used to control the average power for a load, or low pass filtered to get an analog voltage, but if you need to control other things than a simple resistive or lighting load, they are no longer directly equivalent.

Choosing to use hardware PWM depends on what library functions are available for the PWM modules (and remember that MCU vendor supplied libraries usually *SUCK*).   Without good library support you will have to learn how to set up the PWM modules and the timer(s) that drives them by direct register access, which will mean a lot of time spent studying the datasheet.   Without an oscilloscope, or logic analyser it will also be quite difficult to debug.

OTOH,  if you use one of the multi-channel software modulation methods, if you have a JTAG or similar in-circuit debugger for your chosen MCU you can step through one line of code at a time, checking the outputs with a logic probe, multimeter or LED.  That's a lot easier for anyone with previous C programming experience to get going than having to fully understand the hardware, as outputting a word to a port is remarkably similar for most of the MCU families on the market.   Even if you use a timer driven interrupt to maintain the modulation output in the background, that's only one, not excessively complex, hardware peripheral to learn. 

Here's that BAM/BCM link again: http://www.batsocks.co.uk/readme/p_art_bcm.htm
Its got C source for an ATmega8 MCU, which, with a bit of work could be ported to an ATmega328P.

Also, if you don't either stick to Atmel's range (that you can program with an Arduino with a programmer sketch loaded), or to chips with a built-in bootloader, you will need a programmer or debugger for whatever MCU you select.

 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #41 on: December 24, 2015, 02:43:42 pm »
Code: [Select]
// Timer interrupt handler - called once per bit position.
ISR( TIMER2_COMP_vect )
{
g_bitpos ++ ;
g_bitpos &= 7;
PORTD = g_timeslice[ g_bitpos ] ;
// now set the delay...
TCNT2 = 0;
OCR2 <<= 1 ;
if (g_bitpos == 0) OCR2 = 1 ; // reset the compare match value.
if (g_bitpos == 7) g_tick = 1 ; // give the main loop a kick.
}

A more generic implementation may be like this:

Code: [Select]
ISR():
  static mask = PCM_MASK; //initialize mask
  if (mask & spcm[0]) IO_SET(SPCM0); else IO_CLR(SPCM0); //set / clear spcm0
  //insert more channels here 
  //update mask
  mask = mask >> 1; //start with msb
  if (mask==0) mask = PCM_MASK; //reste mask
  TCNTx+=-(mask+1); //update timer/counter

All it takes is a timer/counter, with a prescaler.
 
================================
https://dannyelectronics.wordpress.com/
 

Offline donotdespisethesnake

  • Frequent Contributor
  • **
  • Posts: 935
  • Country: gb
  • Embedded stuff
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #42 on: December 24, 2015, 06:12:47 pm »
now i am even more confused, i also took amyk's suggestion and found some chips that have 15+ PWM outputs. and while at it i had another go with the complicated parameter search and found even more chips...

Now that i have the option if having PWM channels or do "software PWM", what do you recommend? What would be easier to code?

"Easy to code" is highly subjective. Clearly if you've got 16 PWM channels then it is probably easier to code, as long as the datasheet and/or library code (if any) is not too cryptic. However a software solution that uses a timer and GPIO is easy to implement on any micro. You also have to factor the support around the chip, ATmega for example has lots of cheap dev boards and software tools, because they are used in Arduino. If you pick an 8bitter sold into industrial markets it might have expensive/hard to obtain dev boards, and only expensive compiler tools.

I think you have to approach it as a learning exercise, start off with something simple and easy to use and see how far you get. e.g. Arduino Uno would probably do the job with about 30 minutes work. (example of what you can do look at http://jimmieprodgers.com/kits/lolshield/ 126 LEDs with no extra hardware). If you find you're running out of MIPS, consider the more advanced software solution or a faster chip. If you have too many MIPS, you can downsize.
Bob
"All you said is just a bunch of opinions."
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1548
  • Country: pl
  • Troll Cave Electronics!
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #43 on: December 24, 2015, 06:26:54 pm »
Aside from the fact that with this number of LEDa pretty much any microcontroller will do,  if wanted to really go to town on this you could use a PSoC and synthesize PWM generators from programmable logic.

Sent from my HTC One M8s using Tapatalk.

I love the smell of FR4 in the morning!
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #44 on: December 24, 2015, 06:48:22 pm »
Quote
example of what you can do look at http://jimmieprodgers.com/kits/lolshield/ 126 LEDs with no extra hardware

Doesn't it allow independent fading of those LEDs? It is fairly simply to turn on / off 126 LEDs with no extra hardware; It is much harder to independently fade 126 LEDs with no extra hardware.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #45 on: December 24, 2015, 08:17:17 pm »
Another approach worth considering is those pwm generators meant to drive leds or even motors. NXP and TI for example have quite a few of them that can drive 16 or 24 channels. They go for a few dollars each.

You can then free up the mcu to do other fancy stuff.
================================
https://dannyelectronics.wordpress.com/
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5549
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #46 on: December 24, 2015, 08:47:33 pm »
Aside from the fact that with this number of LEDa pretty much any microcontroller will do,  if wanted to really go to town on this you could use a PSoC and synthesize PWM generators from programmable logic.

Sent from my HTC One M8s using Tapatalk.

Yeah, just google "PSoC Christmas Lights" and your's see a lot of links.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #47 on: December 25, 2015, 04:53:08 am »
I did look up PSoC and i liked the concept but according to the parameter search of their website (cypress) they only produce 6 PDIP package micros, non with PWM... It will not be worth it for me to print 15 10$ 2x1" PCBs for a simple gift. Thanks anyway, these will benefit me in future projects!
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 1927
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #48 on: December 25, 2015, 06:31:30 am »
I did look up PSoC and i liked the concept but according to the parameter search of their website (cypress) they only produce 6 PDIP package micros, non with PWM... It will not be worth it for me to print 15 10$ 2x1" PCBs for a simple gift. Thanks anyway, these will benefit me in future projects!

So what kind of price point were you looking for, to be able to use a microcontroller to fade 15 LEDs with custom presets?

You cannot make a silk purse out of a sow's ear.

This place will make you 10 PCBs, 5cmx5cm, 2 layers, for 14 dollars US, worldwide shipping included.
http://dirtypcbs.com/

An Attiny costs around a dollar and a half each.  The addressable RGB LEDs are $4.50 for a ten-pack from DigiKey, or $40.50 for a hundred.

Add another couple of dollars per unit for header pins, wire, power supply (battery, holder, connector, capacitor) and pushbutton. So figure about 12-15 dollars per unit, not including the box.

How are you planning on doing what you want for less money than this?


« Last Edit: December 25, 2015, 06:50:34 am by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #49 on: December 25, 2015, 01:16:14 pm »
I did look up PSoC and i liked the concept but according to the parameter search of their website (cypress) they only produce 6 PDIP package micros, non with PWM... It will not be worth it for me to print 15 10$ 2x1" PCBs for a simple gift. Thanks anyway, these will benefit me in future projects!

So what kind of price point were you looking for, to be able to use a microcontroller to fade 15 LEDs with custom presets?

You cannot make a silk purse out of a sow's ear.

This place will make you 10 PCBs, 5cmx5cm, 2 layers, for 14 dollars US, worldwide shipping included.
http://dirtypcbs.com/

An Attiny costs around a dollar and a half each.  The addressable RGB LEDs are $4.50 for a ten-pack from DigiKey, or $40.50 for a hundred.

Add another couple of dollars per unit for header pins, wire, power supply (battery, holder, connector, capacitor) and pushbutton. So figure about 12-15 dollars per unit, not including the box.

How are you planning on doing what you want for less money than this?

I am looking for a micro that could have 15 PWM channels for 3$ a piece, or a small micro with a DIP package shift register that total costs 5$, not including the box which i will make myself from wood and paint...

I do not want to use RGB leds, neither do i want to use addressable ones. i want to use normal fixed color LEDs that my friends could swap out easily.

I also do not want to print a circuit board because i have no way of soldering on packages that are SMD, Buying the extra hardware, the PCBs themselves, shipping them, would just add to the cost.
please understand that i am just 16 and i do not have any source of income other than my pocket money. It is not possible to do all the work others that are in my age do as there are no lawns here in UAE while i am living at the 30th floor... neither does any place agree to let me work due to law...



All that aside, here is a question for everyone: is the Ti TLC5940 a good chip for my purpose. The DIP package is discontinued but i could source it on ebay (WHICH NO ONE IS TELLING ME IF EBAY SELLERS ARE LEGIT  :-BROKE) So my question is: does ti have good programmers and libraries that wont cost me a fortune? if i will buy a programmer i prefer one that i could use for the register, the MCU, and any other future chips with the same package from the same company.....
 

Offline drojf

  • Contributor
  • Posts: 9
  • Country: au
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #50 on: December 25, 2015, 02:19:52 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.

Hopefully I've understood OP correctly. Dannyf seems to have the right idea. If you want to do this "on the cheap", my advice would be to buy an Arduino Pro Mini off Ebay (< $4 USD) and a FTDI serial module to program it(<$4 USD). Even though the Pro Mini only has 4 available channels (technically 6), you can multiplex them between the 16 LEDS (4 banks of 4 PWM channels). You can use one of the following configurations to drive the LEDS (see attachment).

Try and make sure the FTDI module is legit and not the CH340 type, otherwise you may have to do some searching for the CH340 drivers (and incompatibility issues with later versions of windows). You can use the FTDI serial module to program any subsequent pro mini's that you might buy.

If the LEDs don't need to be extremely bright you can omit any external components except resistors (Config A). You can use a transistor (Config B) or sink to multiple pins (Config C) for slightly more current. This configuration is fairly simple to code, you just allocate 1/4 of the time to each bank of four LEDs (there are other ways, but I think this is the simplest which uses the PWM units). I would get a hold of the LEDs you want to use first, so that you can figure out how much current is required to make them glow nicely (you'll need a multimeter and a variety of resistors to test that).

The information for max current per pin etc. is in the datasheet, but Sparkfun has an easier to read version:
https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMini16MHzv1.pdf




Technically you could buy a STM32 Nucleo board for about $10USD (excluding shipping), complete with programmer, and lots of pins, but I wouldn't recommend it for starting out (the mbed libraries are fairly easy to use though). Arduino/AVR wins for amount of tutorials/support / ease of use for simple tasks
« Last Edit: December 25, 2015, 03:06:05 pm by drojf »
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #51 on: December 25, 2015, 02:35:28 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.

Hopefully I've understood OP correctly. Dannyf seems to have the right idea. If you want to do this "on the cheap", my advice would be to buy an Arduino Pro Mini off Ebay (< $4 USD) and a FTDI serial module to program it(<$4 USD). Even though the Pro Mini only has 4 available channels (technically 6), you can multiplex them between the 16 LEDS (4 banks of 4 PWM channels). You can use one of the following configurations to drive the LEDS (see attachment).

Try and make sure the FTDI module is legit and not the CH340 type, otherwise you may have to do some searching for the CH340 drivers (and incompatibility issues with later versions of windows). You can use the FTDI serial module to program any subsequent pro mini's that you might buy.

If the LEDs don't need to be extremely bright you can omit any external components except resistors (Config A). You can use a transistor (Config B) or sink to multiple pins (Config C) for slightly more current. This configuration is fairly simple to code, you just allocate 1/4 of the time to each bank of four LEDs (there are other ways, but I think this is the simplest which uses the PWM units). I would get a hold of the LEDs you want to use first, so that you can figure out how much current is required to make them glow nicely (you'll need a multimeter and a variety of resistors to test that).

The information for max current per pin etc. is in the datasheet, but Sparkfun has an easier to read version:
https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMini16MHzv1.pdf



Technically you could buy a STM32 Nucleo board for about $10USD (excluding shipping), complete with programmer, and lots of pins, but I wouldn't recommend it for starting out (the mbed libraries are fairly easy to use though). Arduino/AVR wins for amount of tutorials/support / ease of use for simple tasks

I didnt really think that multiplexing would even work with PWM... but what if i want to fade in both LED no. 4 and 5? wouldent no. 1 also fade in then? 
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 8143
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #52 on: December 25, 2015, 02:50:42 pm »
Multiplexing will work with PWM, if its synchronised to the PWM timebase, but it should be avoided for a low cost project, as you need brighter better quality LEDs + driver transistors or chips to get an acceptable brightness for daytime use as the average current in any of the LEDs is divided by the proportion of the total multiplexing sequence its enabled for.  e.g. with 4:1 multiplexing and a MCU that can source/sink 10mA per I/O pin, the maximum average current you can get per LED will be 2.5mA (and that's before you dim it with PWM).   The increased circuit complexity will rapidly eat into your budget, as will the need for a PCB or at least protoboard to mount the extra components on.

 

Offline drojf

  • Contributor
  • Posts: 9
  • Country: au
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #53 on: December 25, 2015, 03:05:02 pm »
Sorry, I missed your comment. I agree - using plain software should be fast enough.....using BCM as you mentioned before, or using a "simpler" method but 100% of the CPU. For some reason I thought there was a requirement to use the PWM units.

16 LEDs * 10mA = 160mA which is less than the 200mA limit. But you'll need some sort of driver IC if you want to make the LEDs any brighter than that.

« Last Edit: December 25, 2015, 03:20:17 pm by drojf »
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 1927
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #54 on: December 25, 2015, 03:14:33 pm »
@AnasMalas

I'd love to see how you plan to connect up a many-pin MCU, a many-pin shift register, 15 LEDs, a power supply and control switches, without using a printed circuit board or a breadboard.

I agree that using a ProMini might be a good solution since you don't want RGB addressable LEDs (which are also available in through-hole leaded packages of course, for a bit higher cost), but you will still have to do some programming and soldering. You'll have to have one FTDI programming module in order to program the ProMinis. You'll have to learn how to multiplex the PWM outputs to be able to control all your LEDs, and you will likely have to use external transistors to drive the multiplexed LEDs to acceptable brightness. The ProMini will still require a power supply and control switches. The LEDs will still require some kind of mounting arrangement, and if your friends want to "swap them out" for some reason you'll need to provide some means for doing that. Will they be soldering them?  To what?
 
And will a <$4.00 Chinese clone ProMini actually work properly? I use ProMinis in my own projects but I've never tried one of the cheap clones, so I can't speak as to their reliability. (I do have two projects with genuine ProMinis that are running constantly in my lab (a color organ with 12 LEDs and a multicolor flasher with 1 RGB LED) and have run for several years continuously without problems. I also have that NeoPixel demonstration box, now using a single ProMini that is controlling 2 NeoPixel rings, one 24-LED unit and one 16-LED unit, for a total of 40 RGB LEDs, with color and brightness controlled by software.)

Please understand that I am trying to help you figure out the easiest, least expensive way to get to your final product as you've described it.



« Last Edit: December 25, 2015, 03:21:00 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #55 on: December 25, 2015, 03:35:59 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.
I thought my project was quite big with 80 ws2812 leds. But these were Pl9823 through hole LEDs which I hand solder wires to. It took a couple of hours.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #56 on: December 25, 2015, 04:24:54 pm »
@AnasMalas

I'd love to see how you plan to connect up a many-pin MCU, a many-pin shift register, 15 LEDs, a power supply and control switches, without using a printed circuit board or a breadboard.

I may have confused you, but what i meant is with using the "soldered" protoboard 


for 2$ and some "dremmeling" i can make all 15 boards  :P

Quote
Please understand that I am trying to help you figure out the easiest, least expensive way to get to your final product as you've described it.

Thank you, I am really sorry if i am being a pain but i an just a newb... hopefully after i can do this one project i would help others here because i am learning so much stuff...
 

Offline Robartes_m

  • Contributor
  • Posts: 21
  • Country: be
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #57 on: December 25, 2015, 04:40:26 pm »
Quote
All that aside, here is a question for everyone: is the Ti TLC5940 a good chip for my purpose. The DIP package is discontinued but i could source it on ebay (WHICH NO ONE IS TELLING ME IF EBAY SELLERS ARE LEGIT  :-BROKE) So my question is: does ti have good programmers and libraries that wont cost me a fortune? if i will buy a programmer i prefer one that i could use for the register, the MCU, and any other future chips with the same package from the same company.....

I like the TLC5940 and have used it successfully a few times. You do not need a programmer for it as it is not a microcontroller. Basically, you provide it with a data clock and data signal to tell it the PWM levels of each of its outputs (with 12-bit resolution), as well as a faster clock signal which will drive the PWM. Additionally, there's a few enable and blanking signals. All of these signals can easily be generated with a microcontroller of any kind (I've used an Atmel ATTiny84 for this).

If you want to use the TLC5940, no additional programming hardware on top of that needed for your microcontroller will be needed.

 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #58 on: December 25, 2015, 05:06:15 pm »
Quote
All that aside, here is a question for everyone: is the Ti TLC5940 a good chip for my purpose. The DIP package is discontinued but i could source it on ebay (WHICH NO ONE IS TELLING ME IF EBAY SELLERS ARE LEGIT  :-BROKE) So my question is: does ti have good programmers and libraries that wont cost me a fortune? if i will buy a programmer i prefer one that i could use for the register, the MCU, and any other future chips with the same package from the same company.....

I like the TLC5940 and have used it successfully a few times. You do not need a programmer for it as it is not a microcontroller. Basically, you provide it with a data clock and data signal to tell it the PWM levels of each of its outputs (with 12-bit resolution), as well as a faster clock signal which will drive the PWM. Additionally, there's a few enable and blanking signals. All of these signals can easily be generated with a microcontroller of any kind (I've used an Atmel ATTiny84 for this).

If you want to use the TLC5940, no additional programming hardware on top of that needed for your microcontroller will be needed.

THAT is so, so, so good to know! i am starting to think this is the best way to go!!
i was reviewing the data sheet for it and noticed that they shorted the "XERR,SCLK,XLAT,GSCLK,DCPRG,BLANK"
have a look: http://www.ti.com/product/TLC5940/datasheet/application_and_implementation#SLVS5159149

is that how you did it? including that component mess down there?
 

Offline Robartes_m

  • Contributor
  • Posts: 21
  • Country: be
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #59 on: December 25, 2015, 06:54:56 pm »
Quote
is that how you did it? including that component mess down there?

Here's the schematic of my Tiny84 / TLC5940 board. You can disregard the MAX641 part, that was just used because this particular circuit was running off a LiPo battery and I wanted VCC boosted to 5V.

For the TLC5940 I connected the SCLK (data clock), SI (data in), GSCLOCK (Grayscale clock, the PWM clock signal), XLAT (latch in new PWM data) and BLANK (what it says on the box :) ) to the microcontroller. The only additional pins (except for the output and power supply) connected on the TLC5940 were VPRG which needs to be low, and the resistor on IREF to set the LED current.

The transistor on the GND pin of the TLC5940 is only there to shut it off when the MCU goes to sleep to conserve battery power.

 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2103
  • 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 #60 on: December 26, 2015, 01:50:52 am »
and noticed that they shorted the "XERR,SCLK,XLAT,GSCLK,DCPRG,BLANK"

Those pins aren't shorted - they are bussed together to simplify the schematic.
Where each separate signal 'pops out' from the buss, it will be identified.

Robartes diagram is close to the minimum you need to do with separate components (any brand)...

Keeping in mind your preference to use through-hole discrete RGB LEDs - you create all this work for yourself, as well as taking space on the board.  Using any integrated RGB (WS28xx) LED will elimonate about 60% of the wiring - through hole or SMT.   

(If you are determined to use through-hole separate driver chip and LEDs - look at the WS2801... the drivers and examples are all over the place - and still 50% less point-to-point wiring.  https://www.adafruit.com/datasheets/WS2801.pdf
Don't ask a question if you aren't willing to listen to the answer.
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #61 on: December 26, 2015, 10:25:46 am »
Quote
is that how you did it? including that component mess down there?

Here's the schematic of my Tiny84 / TLC5940 board. You can disregard the MAX641 part, that was just used because this particular circuit was running off a LiPo battery and I wanted VCC boosted to 5V.

For the TLC5940 I connected the SCLK (data clock), SI (data in), GSCLOCK (Grayscale clock, the PWM clock signal), XLAT (latch in new PWM data) and BLANK (what it says on the box :) ) to the microcontroller. The only additional pins (except for the output and power supply) connected on the TLC5940 were VPRG which needs to be low, and the resistor on IREF to set the LED current.

The transistor on the GND pin of the TLC5940 is only there to shut it off when the MCU goes to sleep to conserve battery power.
Alright, thanks soo much for the valuable schematic! One last question: any reason for choosing the attiny 84?

Quote
Those pins aren't shorted - they are bussed together to simplify the schematic.
Where each separate signal 'pops out' from the buss, it will be identified.
It sure seemed odd, i just didnt want to assume anything so i asked...

Quote
... through-hole discrete RGB LEDs ...
actually i am using through hole discrete mono LEDs, 15 of them....
 

Offline Robartes_m

  • Contributor
  • Posts: 21
  • Country: be
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #62 on: December 26, 2015, 10:29:23 am »
Quote
Alright, thanks soo much for the valuable schematic! One last question: any reason for choosing the attiny 84?

I'm familiar with AVR's, and it's the smallest one with enough I/O pins to drive all the signals I needed. My 'go to' MCU for this sort of thing (LED blinky stuff) is an ATTiny85, but that only has 5 I/O pins available, which was not enough in this case.

 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #63 on: December 26, 2015, 05:50:01 pm »
Quote
  ATTiny85, but that only has 5 I/O pins available, which was not enough in this case.


how many IO pins do i need for the  TLC5940? are the XERR,SCLK,XLAT,GSCLK,DCPRG,BLANK all on IO pins or are there specific pins on the micro? also did you use the Ti library? how hard was it to code considering that ive never coded for a micro?
« Last Edit: December 27, 2015, 08:03:22 am by AnasMalas »
 

Offline Robartes_m

  • Contributor
  • Posts: 21
  • Country: be
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #64 on: December 26, 2015, 07:34:59 pm »
Quote
  ATTiny85, but that only has 5 I/O pins available, which was not enough in this case.
how many IO pins do i need for the  TLC5940? are the XERR,SCLK,XLAT,GSCLK,DCPRG,BLANK all on IO pins or are there specific pins on the micro? also did you use the Ti library? how hard was it to code considering that ive never coded for a micro?

All of the signals connected to the MCU were connected to normal I/O pins. I did not use the TI library but wrote my own code to drive the TLC5940. You will need a solid understanding of timers and interrupts on the microcontroller if you want to go this route yourself.

As this is your first microcontroller experience, I would actually recommend going the Arduino route - there's an Arduino library specifically for the TLC5940 IIRC. You can always transfer the microcontroller to a separate board after programming it in an Arduino Uno if you want.
 

Offline oPossum

  • Frequent Contributor
  • **
  • Posts: 888
  • Country: us
  • The other white meat
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #65 on: December 27, 2015, 03:32:18 am »
16 channel PWM using a single timer in the MSP430.  The ISR is very simple, so MCU overhead is low.

http://forum.43oh.com/topic/1723-16-channel-software-pwm-using-a-single-timer/


« Last Edit: December 27, 2015, 03:33:54 am by oPossum »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #66 on: December 27, 2015, 03:06:32 pm »
your isr:

Code: [Select]
__interrupt void Timer0_A1 (void)
{
volatile unsigned x = TAIV; // Clear interrupt flag
P1OUT &= ~pa->port_off; // Port pins off
P2OUT &= ~pa->port_off >> 8; //
P1OUT |= pa->port_on; // Port pins on
P2OUT |= pa->port_on >> 8; //
pa = pa->next; // Next entry in list
TACCR1 = pa->time; // Update timer compare time
}

It has the advantage a short pwm period. However, it has a few issues:

1) the pwm list must be time-monotonic, in that the compare time for the next entry on the list must be bigger than the compare time for the previous entry on the list. This is OK with a static list but if your pwm channels allow dynamic / changing compare time / duty cycle for each channel independently, maintaining that list can be prabamatic;
2) The difference between successive compare time has to be sufficiently large (larger than isr latency + isr execution time), or your pwm duty cycle may not be accurate -> more specifically, it may be longer than expected / specified by the list.

Also, from coding perspective, you want to update the compare time TACCR1 first, and then process the pins later, so you don't miss short compare time intervals: under the current code, your timer / counter could have advanced beyond the next compare time, because of executing the isr code first so that the compare isn't triggered until the timer has finished a full cycle.

The approach I took is to use each timer overflow as 1 tick for the (software pwm) time base. It avoids the problems above, but does slow down the CPU and cannot provide short pwm period.

The practical approach is to use pcm.
================================
https://dannyelectronics.wordpress.com/
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 1800
  • Country: fi
  • Embedded SW/HW.
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #67 on: December 27, 2015, 03:53:46 pm »
How about using a precomputed lookup-table containing the bits of wanted PWM-signal pattern. Let's assume that you want to have 32 different levels for each LED, so your lookup-table needs to be 32 entries long. Then you will have a timer running at 32kHz generating interrupts giving 1kHz update rate, thus there shouldn't be any flicker. At each interrupt you just read the lookup-entry and write it to the output port and increment the table index using modulo arithmetic (index = (index + 1) & (32-1)). Pretty simple and light on ISR. When you need to adjust the brightness for one or more LEDs, just compute and update the table.

If you need more that 32 levels, say 64 or 128 levels, you need to increase the table size and adjust the timer interrupt rate.
« Last Edit: December 27, 2015, 04:24:41 pm by Kalvin »
 

Offline AnasMalas

  • Contributor
  • Posts: 18
  • Country: ae
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #68 on: December 27, 2015, 07:17:57 pm »
All those bits of code hit me like a truck...... I aint ready for all of this... Me programming code that wont bug out isnt looking too positive...
just a small question before i venture into this world (ill start taking some online classes), do diffrent MCUs REQUIRE different code to operate? or is there some sort of compatibility between say 8 bit and 8 bit, or 8051 based and 8051 based?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #69 on: December 27, 2015, 09:09:04 pm »
Quote
At each interrupt you just read the lookup-entry and write it to the output port and increment the table index using modulo arithmetic (index = (index + 1) & (32-1)).

That's basically what I do:

Code: [Select]
void spwm_act(void) {
static uint8_t mask = PWM_MASK; //initialize pwm duty cycle
mask = mask - 1; //decrement mask
if (mask == 0) {
mask = PWM_MASK; //initialize mask
IO_CLR(PWM0_PORT, PWM0); //clear pwm pins
IO_CLR(PWM1_PORT, PWM1);
}
//process pwm0
if (mask == spwm_dc[0]) IO_SET(PWM0_PORT, 1<<0);
if (mask == spwm_dc[1]) IO_SET(PWM0_PORT, 1<<1);
if (mask == spwm_dc[2]) IO_SET(PWM0_PORT, 1<<2);
if (mask == spwm_dc[3]) IO_SET(PWM0_PORT, 1<<3);
if (mask == spwm_dc[4]) IO_SET(PWM0_PORT, 1<<4);
if (mask == spwm_dc[5]) IO_SET(PWM0_PORT, 1<<5);
if (mask == spwm_dc[6]) IO_SET(PWM0_PORT, 1<<6);
if (mask == spwm_dc[7]) IO_SET(PWM0_PORT, 1<<7);

//process pwm1
if (mask == spwm_dc[8]) IO_SET(PWM1_PORT, 1<<0);
if (mask == spwm_dc[9]) IO_SET(PWM1_PORT, 1<<1);
if (mask == spwm_dc[10]) IO_SET(PWM1_PORT, 1<<2);
if (mask == spwm_dc[11]) IO_SET(PWM1_PORT, 1<<3);
if (mask == spwm_dc[12]) IO_SET(PWM1_PORT, 1<<4);
if (mask == spwm_dc[13]) IO_SET(PWM1_PORT, 1<<5);
if (mask == spwm_dc[14]) IO_SET(PWM1_PORT, 1<<6);
if (mask == spwm_dc[15]) IO_SET(PWM1_PORT, 1<<7);

}

spwm_act() is called in the timer overflow isr.

Implementing pcm is quite easy as well: rather than "mask = mask - 1;", you do "mask = mask >> 1;" and make corresponding adjustments to the counter (or prescaler, depending on your implementation / hardware).

Fundamentally, with software pwm, you process 256 interrupts / 16x port operations per pwm period; and with software pcm, you process 8 interrupts / 16x port operations.
================================
https://dannyelectronics.wordpress.com/
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6004
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #70 on: December 27, 2015, 09:22:59 pm »
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's a neat idea.
Drain the swamp.
 

Offline josh38

  • Newbie
  • Posts: 1
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #71 on: March 08, 2016, 03:12:47 am »
I have a problem with flickering WS2812B leds. I'm using a setup of 5 strips 8xWS2812 5050 leds. I've connected these to a 5v power supply (USB charger) and an Arduino Uno. I've noticed that the leds also flicker when the leds are on and the datapin is disconnected. The flickering is subtle, but annoying. I've also tried an alternative power supply. For this I used a adjustable lab power supply. But the same problem persists.Any thoughts?
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #72 on: March 08, 2016, 09:37:49 pm »
I have a problem with flickering WS2812B leds. I'm using a setup of 5 strips 8xWS2812 5050 leds. I've connected these to a 5v power supply (USB charger) and an Arduino Uno. I've noticed that the leds also flicker when the leds are on and the datapin is disconnected. The flickering is subtle, but annoying. I've also tried an alternative power supply. For this I used a adjustable lab power supply. But the same problem persists.Any thoughts?
DECOUPLING CAPACITORS. i had this problem with a 64 long through hole ws2812 string i turned it on and they were all flickering so i put 64 0.1uf caps on and now it works.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 3734
  • Country: us
Re: Which micro to use for fading 15 LEDs and cutom presets?
« Reply #73 on: March 11, 2016, 01:46:33 am »
Quote
The approach I took is to use each timer overflow as 1 tick for the (software pwm) time base. It avoids the problems above, but does slow down the CPU and cannot provide short pwm period.
+1. This is how my PCM has also evolved. A single timer interrupt with a fixed (and relatively short) period can do almost anything you could ever need to do using multiple timers. It just takes a little bit of code in the ISR. This is a very flexible way to use a timer interrupt, IMO. It's rather like sharing time with a second CPU, for things which are timing sensitive (or rather must remain timing-consistent) but which can be executed very quickly.

Even pre/post scaling is simply a luxury. You can post-post scale to your heart's content in your ISR with cost of a few extra instruction executions and a few spaces of memory. And the bonus is that the extra instructions that pile up on every overflow and/or when ISR's collide, they don't matter, so much. Each period is the same length, so long as you keep the max length of your ISR (if there were to all fire at once) shorter than the period. A particular ISR might execute with a slight delay every blue moon if it's down on the priority list, but only as long a delay as the total max length of higher priority interrupt routines. There's no cumulative effect to account for.
« Last Edit: March 11, 2016, 02:06:42 am by KL27x »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf