Go Down

Topic: SoftPWM messes with Hardware PWM (Read 1 time) previous topic - next topic


Jan 23, 2013, 12:59 pm Last Edit: Jan 23, 2013, 01:09 pm by Andy_Cool Reason: 1
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.


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?


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.


Jan 23, 2013, 04:18 pm Last Edit: Jan 23, 2013, 04:57 pm by tack Reason: 1
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.

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. :)


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.
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131