Go Down

Topic: SoftPWM messes with Hardware PWM (Read 685 times) previous topic - next topic

Andy_Cool

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.

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.

Grumpy_Mike

Quote
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.

tack

#2
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?

Andy_Cool

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

cyclegadget


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
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

Go Up