Pages: [1]   Go Down
Author Topic: SoftPWM messes with Hardware PWM  (Read 598 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 23, 2013, 07:09:04 am by Andy_Cool » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 619
Posts: 33961
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: January 23, 2013, 10:57:01 am by tack » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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


Pages: [1]   Go Up
Jump to: