SetPWMPrescale/developers

From Wiring

Jump to: navigation, search
This page is intended as a reference for core developers only, and the content is only changed after a consensus has been reached through discussion of any such changes. Please use the Discussion page to talk about any changes or issues you have with the current implementation.
setPWMPrescale()
Classification PWM Function
Suggested location WPWM.h
C++ required No
Timing constraints None
Version introduced 1.0 (0100)
Framework dependencies None
Prototype(s)
void setPWMPrescale(uint8_t pin, uint8_t prescalar)
Required? Yes
Issues None


Contents

Description

The setPWMPrescale() method sets the PWM output frequency of a PWM output pin.

Black Box Input

The pin number and desired frequency of either 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) or CLOCK_PRESCALE_1024 (F_CPU/1024) are provided.

Black Box Output

No output.

Overloading

None. Single signature only.

Notes

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

Proposed Changes

For Wiring 1.1

According to Issue 9, setPWMResolution() will be defined as:

uint8_t setPWMResolution(pin_t pin, uint8_t bitResolution);

See Issue 9 for more details.

Personal tools