On Sat, 14 Sep 2002, Magnus von Rosen wrote: >In other words, I can't use the PWM? That only works on one pin at a >time, right? You can use bit banged pwm. Each channel must be implemented in software. You need to decide if you will be using interrupts or bit banged. With bit banged you will have a state machine that will do this for each period of the pwm: uchar i = 0; // state counter inside pwm frame (also table pointer) do { uchar j; // repeat counter jumped: j = table[ i ]; // repeat count // Uncomment following lines to implement looping/jumping etc // if(j == 0) { // magic marker // i = table[ i + 1 ]; // get address // goto jumped; // } Tred = table[ i+1 ] Twhite = table[ i+2 ]; Tyellow = table[ i+3 ]; do { char t = 0; // pwm frame timer if(Tred) red = ON; if(Twhite) white = ON; if(Tyellow) yellow = ON; do { delay(Tpwm/M - overhead); if(Tred < t) red = off; if(Tyellow < t) yellow = off; if(Twhite < t) white = off; } while(++t < M); } while(j--); // repeat till j = 0 } while((i += 4) < MAXTABLE); // repeat for each table entry The table stores 4 entries for each 'state'. If you want this to be smooth, you must make a lot of table entries. There are ways to save table entries by using interpolation. Each table entry has four bytes: a repeat count, and a Ton value for each LED. MAXTABLE is the size of the table in bytes (!). M is the pwm frame time and must be a low enough value to avoid flicker. 10msec/100Hz is a good start for non-moving displays. M is usually divided into 256 equal time slots (convenient on 8 bit machines) and Tons then refer to Ton/256 turn on times. The repeat count causes the same settings to be meintained for that many PWM frames. For example your sequence calls for 700msec fade, you would divide that into 10 table entries, giving seven table entries each with a count of 1 and with Ton coefficients that you get to calculate using a calculator (write a basic or perl program to compute the scaled logs you need). E.g. Brightness ~= log( Ton / M ) so Ton ~= int( M * 10 ^ (Brightness)) Where Brightness is in range 0.0 .. 1.0 You can make the whole program loop either by adding a jump around it or otherwise (f.ex. implement a magic count code that causes a jump or an assignment on i, the state counter). You can also implement 'subroutines' to reuse canned sequences, using other magic codes. I have used code like this before with success. Peter -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads