SAMD51 PWM

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using ATsmart interface I configure PWM0 TCC3 W0/0 PB16 expecting a 50% duty cycle square wave. Nothing comes out the pin even though datasheet pace 34 PB16 says TCC3, TCC0, and TC6 can be used. The only config that generates any kind of signal is TC6. But that pwm is a 98% high duty cycle. If I do the same with PB17 all PWMs for that pin work as expected. It is almost as if PB16 can't be used by WM even though datasheet says otherwise. BTW, PB18 acts the same as PB16.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The following code outputs a square wave on PB16 using the TCC3 timer

 

#include "sam.h"

#define PWM_PORT             1
#define PWM_PIN              16          /* PB16 */

#define PWM_DUTY_CYCLE       1000
#define PWM_PERIOD           2000

int main(void)
{
    GCLK->PCHCTRL[29].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(0);        /* Connect GenClk0 to TCC3 */
    while (GCLK->SYNCBUSY.reg & GCLK_SYNCBUSY_GENCTRL_GCLK0);               /* Wait for Sync */

    MCLK->APBCMASK.reg |= MCLK_APBCMASK_TCC3;					           /* Enable TCC3 Peripheral access */

    TCC3->CTRLA.reg = TCC_CTRLA_SWRST;                                      /* reset the timer */
    while(TCC3->SYNCBUSY.reg & TCC_SYNCBUSY_SWRST);                         /* wait for reset to complete */
    TCC3->CTRLA.reg = TCC_CTRLA_PRESCALER_DIV4;                             /* set to 1:4 prescaler */
    TCC3->WAVE.reg = TCC_WAVE_WAVEGEN_NPWM;                                 /* set waveform to normal PWM */
    TCC3->PER.reg = PWM_PERIOD;                                             /* set the PWM period */
    TCC3->CC[0].reg = PWM_DUTY_CYCLE;                                       /* set the PWM duty cycle */

    PORT->Group[PWM_PORT].PINCFG[PWM_PIN].reg = PORT_PINCFG_PMUXEN;         /* enable Port mux on PC27 */
    PORT->Group[PWM_PORT].PMUX[PWM_PIN/2].reg |= PORT_PMUX_PMUXE(5);        /* PB16 function F = TCC3/WO[0] */

    TCC3->CTRLA.reg |= TCC_CTRLA_ENABLE;                                   /* reset the timer */
    while(TCC3->SYNCBUSY.reg & TCC_SYNCBUSY_ENABLE);                       /* wait for sync */

    while (1)
    {
    }
}

 

John Malaugh