On Sun, 14 Sep 2003, David Euans wrote: > I am trying to use an 18F448 to light a RGB LED such that the > intensities of each LED can be varied independently. This needs to > occur in the background. The ultimate use is to have the LED change > color in response to changes in a digital rotary encoder. Using PIC > Basic Pro, I was trying to use the HPWM command to send differing duty > cycle PWM outputs to channels 1, 2 and 3 of the PIC. This has not > worked for me and may be due to not properly initializing the PWM > ECCP1CON or other registers. However, looking at the data sheet, I get > the impression that only two pins as most can be modulated at one time. > (Perhaps I'm reading it wrong). At any rate, has anyone been successful > in having this chip provide more than two PWM outputs running in the > background. David, I agree with Olin (and others who've made similar suggestions), for three or more PWM outputs you'll have to use software and bit bang it. A few others have given you examples in a high level language. However, without inhibiting interrupts, I don't see how it's possible that these routines run at a constant rate. In my opinion you're going to have to write a PWM routine that runs in the context of a timer interrupt. I have no idea how one does that in BASIC, but if you have the capability of inline-ing assembly then you may wish to consider this routine for 8 outputs: http://www.dattalo.com/technical/software/pic/pwm8.asm Each PWM output has 8-bits of dynamic range. It takes 23 cycles to update all 8 outputs, or 256*23 = 5888 cycles for one PWM period. If you prune this down to just three outputs, then the total cycles are only 13. You don't mention at what frequency your F448 is running, but if it's 40MHz, then the over head is 1 instruction / 0.1 uS or roughly 600 uS for the fastest PWM carrier period which is about 15 times faster than you need. E.g., let's say you wish the pwm frequency to be about 100Hz (just fast enough so that there's no visible flickering). To use the routine I reference, you'd set up one of your timers to interrupt every (1/100/256) seconds, or about 39 uS. In this interrupt routine, you call the software PWM routine. It'll take about 2.3 uS to run through 8 PWM outputs or about 1.3 uS to run through just three. The total system burden is then about 2.3/39 = 6%. By the time you take into account the interrupt overhead, this number may creep up to 10%. Also, 256 levels are probably way more than needed. If you backed this off to something like 32 or 64, then it's possible to either reduce the system burden or run at a slower oscillator frequency. Scott -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics