SetPWMResolution/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.
setPWMResolution()
Classification PWM Function
Suggested location WPWM.h
C++ required No
Timing constraints None
Version introduced 1.0 (0100)
Framework dependencies None
Prototype(s)
void setPWMResolution(uint8_t pin, uint8_t bitResolution)
Required? Yes
Issues None


Contents

Description

setPWMResolution() sets the PWM output resolution of a PWM output pin.

Black Box Input

The pin number and desired resolution (in bits) are provided.

Black Box Output

No output. After a call to setPWMResolution(), PWM output on pin is set to bitResolution as a side effect.

For example, a call to setPWMResolution(0, 10); will allow subsequent calls to analogWrite() to use values between 0 and 1023 (i.e., 2^10 - 1).

Overloading

None. Single signature only.

Notes

PWM pins are frequently internally managed by timers; i.e., a single timer will handle PWM output on multiple pins. This implies that changing PWM-related settings (like timer resolution or prescalers) for one pin may affect other pins managed by that 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, as pins 29, 30 and 31 are controlled by the same timer.

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