Framework (A-Z)

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Name

setPWMPrescale()

Examples
...

// sets the PWM output frequency prescale to
// 1/8th of the main clock frequency 
// for the analogWrite() command

setPWMPrescale(29, CLOCK_PRESCALE_8);   

...
Description The setPWMPrescale() method sets the PWM output frequency of a PWM output pin. On Wiring v1 boards the PWM capable pins are: 29, 30, 31, 35, 36 and 37. On Wiring S board the PWM capable pins are: 4, 5, 6, 7, 19 and 20. Possible frequency Prescale values are:
CLOCK_NO_PRESCALE (F_CPU),
CLOCK_PRESCALE_8 (F_CPU/8),
CLOCK_PRESCALE_32 (F_CPU/32),
CLOCK_PRESCALE_64 (F_CPU/64 default value),
CLOCK_PRESCALE_128 (F_CPU/128),
CLOCK_PRESCALE_256 (F_CPU/256),
CLOCK_PRESCALE_1024 (F_CPU/1024).
IMPORTANT Note: PWM pins are internally grouped/managed by timers, a single timer can handle 2 or 3 pins, which means that changing operation settings like resolution or prescale for one pin will change it as well for the pins sharing the same timer. For example setting PWM bit resolution to 10 bits for pin 29 on the Wiring v1 boards will automatically change it for pins 30 and 31 (29, 30 and 31 are controlled by the same timer). On Wiring v1 boards timer PWM pin groups are: [29, 30, 31] and [35, 36, 37]. On Wiring S board timer PWM pin groups are: [4,5] [6,7] and [19, 20].
Syntax
setPWMPrescale(pin, prescalar)
Parameters
pin int: The PWM output pin number
prescalar int: The frequency prescalar. Possible values are CLOCK_NO_PRESCALE (F_CPU), CLOCK_PRESCALE_8 (F_CPU/8), CLOCK_PRESCALE_32 (F_CPU/32), CLOCK_PRESCALE_64 (F_CPU/64 default value), CLOCK_PRESCALE_128 (F_CPU/128), CLOCK_PRESCALE_256 (F_CPU/256) and CLOCK_PRESCALE_1024 (F_CPU/1024).
Returns None
Usage Application
Related analogWrite()
noAnalogWrite()
setPWMResolution()
analogRead()
Updated on July 07, 2011 11:08:56pm PDT

Creative Commons License