Skip to content

Commit 126b167

Browse files
Fixed issue where pins were not being configured properly in analogWrite when multiple channels of the same TCC/TC module were being used to drive outputs.
1 parent 648812a commit 126b167

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

cores/arduino/wiring_analog.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,23 @@ void analogWrite(uint32_t pin, uint32_t value)
218218
uint8_t tcChannel = GetTCChannelNumber(pinDesc.ulPWMChannel);
219219
static bool tcEnabled[TCC_INST_NUM+TC_INST_NUM];
220220

221-
if (!tcEnabled[tcNum]) {
222-
tcEnabled[tcNum] = true;
223-
224-
if (attr & PIN_ATTR_TIMER) {
225-
#if !(ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10603)
226-
// Compatibility for cores based on SAMD core <=1.6.2
227-
if (pinDesc.ulPinType == PIO_TIMER_ALT) {
228-
pinPeripheral(pin, PIO_TIMER_ALT);
229-
} else
230-
#endif
231-
{
232-
pinPeripheral(pin, PIO_TIMER);
233-
}
234-
} else {
235-
// We suppose that attr has PIN_ATTR_TIMER_ALT bit set...
221+
if (attr & PIN_ATTR_TIMER) {
222+
#if !(ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10603)
223+
// Compatibility for cores based on SAMD core <=1.6.2
224+
if (pinDesc.ulPinType == PIO_TIMER_ALT) {
236225
pinPeripheral(pin, PIO_TIMER_ALT);
226+
} else
227+
#endif
228+
{
229+
pinPeripheral(pin, PIO_TIMER);
237230
}
231+
} else {
232+
// We suppose that attr has PIN_ATTR_TIMER_ALT bit set...
233+
pinPeripheral(pin, PIO_TIMER_ALT);
234+
}
235+
236+
if (!tcEnabled[tcNum]) {
237+
tcEnabled[tcNum] = true;
238238

239239
uint16_t GCLK_CLKCTRL_IDs[] = {
240240
GCLK_CLKCTRL_ID(GCM_TCC0_TCC1), // TCC0

0 commit comments

Comments
 (0)