|Shopping Cart Checkout Shipping Cost Download Website|
|Home||MP3 Player||8051 Tools||All Projects||PJRC Store||Site Map|
|You are here: Teensy Teensyduino Libraries SoftPWM|
SoftPWM LibrarySoftPWM, written by Brett Hagman, can create additional PWM outputs on any pin. The signal frequency is relatively slow (default 30 Hz), which is mostly useful for controlling the brightness of LEDs.
Hardware RequirementsSoftPWM can control up to 20 pins. Any digital pin may be used.
SoftPWM is compatible with Teensy 2.0, Teensy 3.0, and Teensy++ 1.0 & 2.0. Teensy 1.0 is not supported.
Begin using SoftPWM. This function must be called first. The input can be SOFTPWM_NORMAL or SOFTPWM_INVERTED.SoftPWMSet(pin, value);
Write the PWM on a pin. The value may be between 0 to 255. If fade times have been defined, the PWM will change gradually.SoftPWMSetFadeTime(pin, fadeUpTime, fadeDownTime);
Set speed a PWM pin changes. fadeUpTime and fadeDownTime may be between 0 to 4000 milliseconds.SoftPWMSet(pin, polarity);
Change the polarity on a single pin.
Example ProgramSoftPWM comes with several examples. Open the from File > Examples > SoftPWM.
CPU Usage & Interrupt LatencySoftPWM uses a timer and interrupt routine, which consumes considerable CPU time.
TODO: actually measure CPU usage (maybe try changing the number of channels...)
Latency sensitive libraries, like Servo and NewSoftSerial, will likely be disrupted by SoftPWM.
More DetailsPlease refer to the official SoftPWM documentation for more details.