Pages: [1]   Go Down
Author Topic: SoftPWM Library  (Read 11224 times)
0 Members and 1 Guest are viewing this topic.
Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I created a new software PWM output library.  It was made for controlling LEDs.

A few features of this library:
  • Arbitrary output pins.
  • Up to 16 different channels can be created.
  • True zero level, i.e. off = off
  • Separate fade rates for on and off.

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

Quick demos here:

[media]http://www.youtube.com/watch?v=2slHEADOJ8g&feature=player_embedded[/media]

[media]http://www.youtube.com/watch?v=jE7Zw1zNL6c&feature=player_embedded[/media]

b
« Last Edit: March 17, 2010, 01:13:04 am by bhagman » Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Where's the Kaboom?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's neat - I was just writing some code to manage the fade up & down when switching the LEDs too - but using the built in PMW so was limited to the 6 lines. Yours is much better!
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One question about the library. I tried to use it with a project that used already the 6 PWM ports, and it didn't work (there was no activity at the sofpwm port, or the hardware pwm ports)

I tried to disable the analogPWM hardware signals, pin outputs and then the leds controlled by softpwm worked.

So, if I use this library I have to control all pins with this library?

In any case, many thanks for this library!
« Last Edit: July 09, 2010, 12:52:02 pm by Valygar » Logged

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The SoftPWM Library only uses Timer2.  So, unless there is something I'm missing, you just won't be able to use the two hardware PWM output pins for that timer (pins 3 and 11).  The others should work (hardware PWM on pins 5, 6, 9 and 10).

b
Logged


Hamburg, ger
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So, do i understand it right, that this Library makes me able to use the digital out pins on my duenmilanove (Or also the mini) as PWM Pins?
Logged

Coventry UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all the hard work bhagman.

I have installed it and will have a play with it later.

Martyn.
Logged

Nowhere
Offline Offline
God Member
*****
Karma: 3
Posts: 852
|-\ |\|\
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there any relatively simple way to make the library use a different timer?

Or, another question to solve the issue I have:
If I start the softwarePWM library before I begin() some objects on the Tone library, will the Tones automatically take the next available timer?  I know they do this when there are multiple tone objects, but how about other libraries?
Logged

Soundcloud page: http://soundcloud.com/beefinator-2
Youtube channel: http://www.youtube.com/user/beefinator14
Old soundcloud page (ran out o

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@zonkie: Yes.  That's exactly what the library is for.  Just a reminder though, that it is not intended for use with things like servos - although it will work, it is not recommended.  The reason being is that the SoftPWM range of values is over the entire pulse width, whereas a servo expects a pulse over a tight range (0.5 mS to 2.5 mS and repeated every 20 mS).  Hence, the range of usable values for a servo or such would be something like 40 to 50 resulting in big jumps in the servo position.

@sciguy: All the objects that use the hardware timers suffer from the problem of being tied to a specific timer.  I was thinking that the best solution (i.e. kludge) to this would be to make a library named for each timer, and thus you can pick which timer you want to use.  Would that make sense? e.g. SoftPWM1 for timer 1, SoftPWM2 for timer2, etc.

b
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello.
i'm getting this when i try to compile a sketch that uses your library.

Code:
C:\Program Files (x86)\Arduino\arduino-0018\libraries\SoftPWM\SoftPWM.cpp: In function 'void SoftPWMBegin()':

C:\Program Files (x86)\Arduino\arduino-0018\libraries\SoftPWM\SoftPWM.cpp:123: error: 'TIFR2' was not declared in this scope

C:\Program Files (x86)\Arduino\arduino-0018\libraries\SoftPWM\SoftPWM.cpp:124: error: 'TCCR2B' was not declared in this scope

C:\Program Files (x86)\Arduino\arduino-0018\libraries\SoftPWM\SoftPWM.cpp:125: error: 'TCCR2A' was not declared in this scope

C:\Program Files (x86)\Arduino\arduino-0018\libraries\SoftPWM\SoftPWM.cpp:126: error: 'OCR2A' was not declared in this scope

C:\Program Files (x86)\Arduino\arduino-0018\libraries\SoftPWM\SoftPWM.cpp:127: error: 'TIMSK2' was not declared in this scope

C:\Program Files (x86)\Arduino\arduino-0018\libraries\SoftPWM\SoftPWM.cpp:127: error: 'OCIE2A' was not declared in this scope

i just tried to include the headers for the library.i get the same error when i am trying to compile one of the examples.
the chip is an atmega8, for 328 works fine.
help?
Logged

Pages: [1]   Go Up
Jump to: