|
SoftPWMLibraryDocumentation
Arduino/Wiring SoftPWM Library.
Arduino/Wiring SoftPWM LibraryDownloadSoftPWM Library - Latest Version InstallationSee: InstallingArduinoLibraries DescriptionAn Arduino and Wiring Library to produce PWM signals on any arbitrary pin. It was originally designed for use controlling the brightness of LEDs, but could be modified to control servos and other low frequency PWM controlled devices as well. It uses a single hardware timer (Timer 2) on the microcontroller to generate up to 16 PWM channels. Features
Notes: This library hasn't been tested with servos, so beware that it may not work as you may expect if used to control servos. Usage Example#include <SoftPWM.h>
void setup()
{
// Initialize
SoftPWMBegin();
// Create and set pin 13 to 0 (off)
SoftPWMSet(13, 0);
// Set fade time for pin 13 to 100 ms fade-up time, and 500 ms fade-down time
SoftPWMSetFadeTime(13, 100, 500);
}
void loop()
{
// Turn on - set to 100%
SoftPWMSetPercent(13, 100);
// Wait for LED to turn on - you could do other tasks here
delay(100);
// Turn off - set to 0%
SoftPWMSetPercent(13, 0);
// Wait for LED to turn off
delay(500);
}Function DescriptionsSoftPWMBegin()
SoftPWMSet(pin, value)
SoftPWMSetPercent(pin, percent)
SoftPWMSetFadeTime(pin, fadeUpTime, fadeDownTime)
Notes
DemonstrationsArduino Duemilanove LED Blink example - available as library example:
rDuino LEDHead Bounce example - available as library example:
More demos: http://www.youtube.com/view_play_list?p=33BB5D2E20609C52 | |
I tried and read your code: Seems you can optimize the ISR for speed a lot by using pointers and not using arrays: Arrays use a multiplication in the indexing slowing down the search An efficiency is achievd by doing:
etc another idea would be a pointer to the beginning of the array for (softPWMChannel currchannel = &softpwm_channels0?; and even having a pointer to the base saved somewhere...
Danny
I downloaded and installed the library. When I verify the code it says "softpwmbegin () not declared in this scope" using an arduino duemil.
Make sure you use SoftPWMBegin() instead of softpwmbegin()
Great Library! I used this one to control some LEDs mounted on my staircase. Unfortunately, digital pin 0 can not be accessed although I used the fixed r116 version of the library. SoftPWMSet(ALL, 0); just sets any other pin to zero, but pin 0 is still in a high state. Is there any quick fix available for this issue? I would really like to use every digital pin ;)
More than likely, you'll need to do Serial.end(); in setup(). This will remove the hardware control on pin 0 and 1.
Try it, and let us know how it goes.
Why can you only go up to 16 channels?
No direct reason - it was chosen arbitrarily. You could do some math to figure out what the limit would be. It's just a calculation for the main interrupt loop - as you add more loops, the more time is taken in the interrupt routine, leaving less time in the main application.
@ 16 channels, approximately 20% of CPU cycles are spent in the interrupt routine. I'd have to spend some time looking at the routine in detail to get the exact figures, but that's a decent rough estimate.
Brett:
I don't know if you're still supporting this library, but if you are, could you look at my posting at Arduino.cc?
http://arduino.cc/forum/index.php/topic,66941.0.html
Thanks.
\dmc
Hello Brett,
Have you plans to port this Library ChipKIT, I've tried and it doesn't work.
Best regards,
Joao Quaresma.
Probably not - Besides Rogue, Wiring is where I am putting all of my efforts these days. Wiring will eventually (within a year) have support for PIC, and hopefully others. The latest Wiring API hasn't been adopted by Arduino, and hence ChipKIT, so the current version of SoftPWM will require some work to get it functioning on ChipKIT.
For more information about where we are going with Wiring, check out http://wiring.org.co/
Hi, Im working on an RGB LED cube, with an Atmega644 with ArduinoBootloader?, I need 25 PWM channels, how can I get them with your library? will using 2 timers help? thanks!
I just tried to use this with an attiny85 chip -- with a bunch of compile errors. Oh well, it was worth a shot :)
Any chance you'll be releasing one that is attiny85 compatible?
We are working on the Atmel ATtiny core series in Wiring. No ETA on the release yet.
C:\Users\Ivan\Documents\Arduino\libraries\SoftPWM\SoftPWM.cpp: In function 'void SoftPWMBegin()': C:\Users\Ivan\Documents\Arduino\libraries\SoftPWM\SoftPWM.cpp:123: error: 'TIFR2' was not declared in this scope C:\Users\Ivan\Documents\Arduino\libraries\SoftPWM\SoftPWM.cpp:124: error: 'TCCR2B' was not declared in this scope C:\Users\Ivan\Documents\Arduino\libraries\SoftPWM\SoftPWM.cpp:125: error: 'TCCR2A' was not declared in this scope C:\Users\Ivan\Documents\Arduino\libraries\SoftPWM\SoftPWM.cpp:126: error: 'OCR2A' was not declared in this scope C:\Users\Ivan\Documents\Arduino\libraries\SoftPWM\SoftPWM.cpp:127: error: 'TIMSK2' was not declared in this scope C:\Users\Ivan\Documents\Arduino\libraries\SoftPWM\SoftPWM.cpp:127: error: 'OCIE2A' was not declared in this scope Why? Arduino IDE 0022. Code copypasted from the example.
well done! and thank you
I am having the same problem with pin number 0. I can see in the SoftPWM.cpp file that it is a bug. On line 158 the code find the pins for pin<0 and then for pin>0 (it is missing the pin=0 case).
I am new to open source stuff so I will have a quick look to see if I can fix it myself but I dunno if I will be able to figure it out, so someone else may like to fix it or submit it as a bug report or whatever.
I submitted it under "Issues". Will have to just change my copy for now.
Hey, nice library!
It works really fine, but if I connect a xbee module on the Pins 0 and 1 the arduino crash every few seconds. Is there any chance to use this pins and the SoftPWM library?
Best Regards, Ronald Dlapka