Description
Describe the bug
analogWriteResolution(uint8_t res)
will cycle through the three (or four) PWM peripherals, and set each PWM peripheral's maximum value by calling PWM::setMaxValue()
to reflect this maximum resolution.
analogWrite(uint32_t pin, uint32_t value)
adds the pin to the first unused PWM channel. It will cycle through the three (or four) PWM peripherals, each of which has four channels, until it finds a free channel.
Servo::attach(int pin, int min, int max)
also adds the pin to the first unused PWM channel, and also cycles through the three (or four) PWM peripherals, each of which has four channels, until it finds a free channel. It then unconditionally calls both PWM::setClockDiv(7)
and PWM::setMaxValue(2500)
(for 20ms / 50Hz freq) for the PWM peripheral that had the free channel.
Set up (please complete the following information)
Discovered via code review while investigating #447.
Based on code review, it appears that a call to analogWrite()
on a first pin, followed by a call to Servo::attach()
on a second pin, will result in both pins being controlled by a single PWM peripheral. In addition, the call to Servo::attach()
will disrupt the PWM output from the first pin, because the maximum value and clock divisor will be changed.
Expected behavior
analogWrite()
and Servo::attach()
do not interact with each other.