SAMD21 PWM 8-bit(TC3 PWM NO OUTPUT)

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

#include "sam.h"

int main(void)
{
  
    SystemInit();
     PORT->Group[0].DIRSET.reg=PORT_PA18;
     PORT->Group[0].PINCFG[PORT_PA18].bit.PMUXEN=1;
     PORT->Group[0].PMUX[9].bit.PMUXE = 4;
     
         
     PM->APBCMASK.reg |= PM_APBCMASK_TC3;
     
     GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(TC3_GCLK_ID) | GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN(0);
     while (GCLK->STATUS.bit.SYNCBUSY);
    
     TC3->COUNT8.CTRLA.reg =TC_CTRLA_MODE(TC_CTRLA_MODE_COUNT8_Val)|TC_CTRLA_WAVEGEN(TC_CTRLA_WAVEGEN_NPWM_Val)|
     TC_CTRLA_PRESCALER(TC_CTRLA_PRESCALER_DIV1_Val)|TC_CTRLA_PRESCSYNC(TC_CTRLA_PRESCSYNC_PRESC_Val);
     while (TC3->COUNT8.STATUS.bit.SYNCBUSY);
     
     TC3->COUNT8.CTRLBCLR.bit.DIR=1;
     while (TC3->COUNT8.STATUS.bit.SYNCBUSY);
     
     TC3->COUNT8.CTRLC.bit.INVEN0=1;
    while (TC3->COUNT8.STATUS.bit.SYNCBUSY);
     
     TC3->COUNT8.COUNT.reg = 0;
    while (TC3->COUNT8.STATUS.bit.SYNCBUSY);
    
     TC3->COUNT8.PER.reg = 255;
     while (TC3->COUNT8.STATUS.bit.SYNCBUSY);
     
     TC3->COUNT8.CC[0].reg = 100;
     while (TC3->COUNT8.STATUS.bit.SYNCBUSY);
     
     TC3->COUNT8.CTRLA.bit.ENABLE=1;
    while (TC3->COUNT8.STATUS.bit.SYNCBUSY);

    while (1) 
    {
       
  
    }
}

China

Last Edited: Thu. Oct 15, 2015 - 11:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It looks like the index is not correct for setting the PMUXEN on pin 18.

 

This define for PORT_PA18 leads to 1<<18 which is not what you want.

 PORT->Group[0].PINCFG[PORT_PA18].bit.PMUXEN=1;

If you try 18 for the index this should work.

PORT->Group[0].PINCFG[18].bit.PMUXEN = 1;

Regards,

-Chris

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

Thank you very much!

PORT->Group[0].PINCFG[PIN_PA18].bit.PMUXEN=1;

China

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

I need help in same area, trying to port my AVR code to SAMD21 . in AVR I have 8 pwm channels with fixed frequency and I generate varying duty cycles by putting different values in the OCR* registers.

I know in SAMD21 I can use the  three registers with the corresponding pins  for PWM but I don't know how to initialize them , can you please help?

I want any fixed frequency between 100Hz to 1Khz with 0-100% duty cycle.

 

TCCO:   PA14, PA15, PA20, PA21

TCC1:   PA8, PA9

TCC2:  PA16, PA17

 

thanks

 

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

Hi,

 

why are you writing PORT->Group[0].PMUX[9].bit.PMUXE = 4 instead of  PORT->Group[0].PMUX[18].bit.PMUXE = 4 ??? You are using Pin18 !

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

How about having a look at the PMUX register in the datasheet? Each PMUX register has a setting for two pins, PMUXE and PMUXO so PMUX[9] has the even setting for pin 18 and the odd for pin 19. 

/Lars