On Fri, 2005-05-27 at 11:26 +0100, Alan B. Pearce wrote: >>Also, I will try Bob's idea of getting all the bits ready, >>and then moving them into the port. This should further >>help to get even fading. > > And if you do things this way, the load of the port register can be done > in > an interrupt routine, from a background (non-interrupt) prepared value. It was probably obvious to many people, but the 23-cycle, 8-PWM software routine I mentioned earlier has this feature of collecting all 8 states and writing them at once to the I/O port. In addition, the routine is really intended to be embedded in a Timer interrupt (otherwise, you'd have to design the rest of your system to be isochronous - and that's a bitch). If the 23-cycle routine is part of a timer interrupt routine, it'd probably make sense to set the interrupt period to something like ~50 cycles. Taking interrupt overhead into account, this leaves a little less than 50% of the CPU available for other things (like deciding the next PWM level). A 20MHz clocked PIC would update the PWM counters every 50 cycles * 0.2uS/cycle = 25 uS. The PWM period is 256 * 25uS ~ 6.4mS which translates into a PWM frequency of 1/6.4mS = 156Hz. Triggering the LED refresh at this frequency should be fast enough to remove perceivable flicker. Scott -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist