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

0 Members and 1 Guest are viewing this topic.

Offline AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
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?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
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.
 
The following users thanked this post: AnasMalas

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • 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 */
 
The following users thanked this post: AnasMalas

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8270
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.
 
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 #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: 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 #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.
 
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 #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.
 
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 #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/
 
The following users thanked this post: AnasMalas

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • 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: 8221
  • 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: 240
  • 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
 
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 #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.
 
The following users thanked this post: AnasMalas

Offline westfw

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

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
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 AnasMalasTopic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: jo
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? 
 

Online Ian.M

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

 
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 #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/
 
The following users thanked this post: AnasMalas

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • 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."
 
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 #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!
 
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 #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/
 
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 #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/
 
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 #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.
 
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 #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: 2055
  • 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
 
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 #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.....
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf