SoftPWM messes with Hardware PWM

Hi All,

I have connected 2 RGB leds to the 6 PWM pins. I needed a few more PWM pins
& hence I tried the SoftPWM library.

http://code.google.com/p/rogue-code/wiki/SoftPWMLibraryDocumentation

The library in itself works fine and fades-up & down several LEDs. So I decided to use it
in my aforementioned 2-RGB project. I added 2-single-color LEDs that would be connected
to unused normal digital pins. The SoftPWM woks fine on these two. However, it messes with
the working of one of the 2-RGBs that are on hardware PWMs. (One of the 2 RGB's behaves
as if it was receiving digital input in form of 0 & 1 while the other one works fine having
smooth fades & then the previous one behaves erratically while the other behaves as it should.)

If, I comment out SoftPWMBegin(); everything works fine.

Is there a way out?
Thanks.

Is there a way out?

Not that I know of, the software PWM wants to use the same timer as two of the hardware PWM pins do. I would just add an extra shift register and use that to drive the other LEDs.

EDIT: Sorry, was getting mixed up with SoftPWM and ShiftPWM.

SoftPWM uses Timer2, which I think is what Pins 3 and 11 use for hardware PWM, so that would disable PWM on those.

I/ve not used SoftPWM, but doesn't it allow you to use up to 20 PWM channels, so if you only have 2 RGB LED's then you should have quite a few pins free that could be used through Soft PWM?

Thanks for the reply Grumpy_Mike.

@tack
Yes, thank you. I am trying along those lines. So far the test code seems to work
fine eliminating the need to use hardware PWM altogether. I will try re-writing
the project code & see how SoftPWM responds...would also use 2 more RGB LEDs
instead of 2 single-color LEDs if all goes well.
Thanks for the response. :slight_smile:

I fought a similar problem using my Uno with both SoftPWM and Hardware PWM. To make a long story short, the sketch would run a loop or two then, it would hang with the LED blinking in a strange manner.

The solution was to only use SoftPWM and not Hardware PWM. The sketch worked perfectly after that.