I'm trying to generate a PWM signal on PB27 / Arduino Due pin 13, which corresponds to TIOB0 on the SAM3X8E (used on the Arduino Due).
However, the output pin just goes HIGH and stays there — no PWM signal appears on the scope. Interrupts are not an option, so I’m trying to use the Timer Counter peripheral directly.
Here’s my minimal code:
// === PB27 / Arduino Pin 13 = TIOB0 ===
pmc_set_writeprotect(false);
pmc_enable_periph_clk(ID_TC0);
PIOB->PIO_PDR = PIO_PB27; // Disable GPIO
PIOB->PIO_ABSR &= ~PIO_PB27; // Peripheral A für TIOB0
TC_Configure(TC0, 0,
TC_CMR_WAVE | // Waveform mode
TC_CMR_WAVSEL_UP_RC | // Count up to RC
TC_CMR_ACPA_CLEAR | // Clear on RA
TC_CMR_ACPC_SET | // Set on RC
TC_CMR_TCCLKS_TIMER_CLOCK4);
TC_SetRA(TC0, 0, rc / 2);
TC_SetRC(TC0, 0, rc);
TC_Start(TC0, 0);
delay(duration);
TC_Stop(TC0, 0);
PIOB->PIO_PER = PIO_PB27; // Enable GPIO
PIOB->PIO_OER = PIO_PB27; // Output enable
PIOB->PIO_CODR = PIO_PB27; // Set LOW
return true;
I’ve verified that rc has a valid value, and the peripheral clock is enabled for ID_TC0. Still, PB27 remains stuck HIGH — no PWM transitions occur.
I’m not using any interrupts or Arduino libraries (just direct register access). What am I missing in the Timer Counter configuration to actually get a waveform on TIOB0?
Environment:
- Arduino Due (Atmel SAM3X8E)
- VS Code/ PlatformIO/ direct register access
- No interrupts used
PIO_Configure(PIOB, PIO_PERIPH_B, PIO_PB27B_TIOB0, PIO_DEFAULT);