Go Down

Topic: max7313 more than 3 pwm (Read 482 times) previous topic - next topic


I'm trying to achieve what seems to be a fairly common problem.  I'm trying to have 9 pwm controlled leds (3 separate reds greens and blues).  The specs of the max7313 looks promising if I could get some help interfacing with it, but I'm not sure if it would be easier just to use 3 ATmega8s.  Believe me I've read through all the back posts, but none of them seem to adequatlely address the problem. Any help would be appreciated.  Thanx.


Dec 26, 2006, 10:40 pm Last Edit: Dec 26, 2006, 10:43 pm by CosineKitty Reason: 1
You could try software PWM.  I was able to do this with two so-called tricolor LEDs (both red and green in a single package, yellow if both turned on).  This code fades colors so that one LED starts out all red and the other green, then they gradually swap colors back and forth.  Even though I'm using only 4 pins, I can see no reason you couldn't expand this to as many output pins as you have available in your design.

Warning:  I copied and mangled this code from inside a much more complex sketch.  My code had extra stuff for detecting when to quit based on an input pin changing state.  The code snippet here will keep looping forever, so no doubt you will need to do something about that!

Code: [Select]

const int    pin_LED_ga     =  7;       // phyiscal pin 13 (ga = green a : tri-color on right)
const int    pin_LED_ra     =  6;       // physical pin 12 (ra = red   a : tri-color on right)

const int    pin_LED_gb     =  5;       // phyiscal pin 11 (gb = green a : tri-color on left)
const int    pin_LED_rb     = 12;       // physical pin 12 (rb = red   a : tri-color on left)

void ColorFade()
   int     duty;

   while (true) {
       for (duty=0; duty<100; ++duty) {
           ColorDutyCycle (50, duty, 99-duty, 99-duty, duty);

       for (; duty>=0; --duty) {
           ColorDutyCycle (50, duty, 99-duty, 99-duty, duty);

void ColorDutyCycle (
   int delay_us,
   int duty_ra, int duty_ga,
   int duty_rb, int duty_gb )
   for (char count=0; count < 100; ++count) {
       delayMicroseconds (delay_us);
       digitalWrite (pin_LED_ra, (count < duty_ra) ? HIGH : LOW);
       digitalWrite (pin_LED_ga, (count < duty_ga) ? HIGH : LOW);
       digitalWrite (pin_LED_rb, (count < duty_rb) ? HIGH : LOW);
       digitalWrite (pin_LED_gb, (count < duty_gb) ? HIGH : LOW);

Go Up