0

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
2
  • The comment "Peripheral A for TIOB0" doesn't add up. It should be B - when I was doing proof of concept for dual QDEC, I used: PIO_Configure(PIOB, PIO_PERIPH_B, PIO_PB27B_TIOB0, PIO_DEFAULT); Commented Nov 5 at 17:14
  • According to this document 11.2.2 PIO Controller B Multiplexing Peripheral A is NSS3 fpr PB27, so it does make a sense it's HIGH Commented Nov 5 at 17:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.