PWM issue in TC6 in SAMDA1E

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
I have been trying to develop PWM in SAMDA1E on TC6 and on IO PA28. I'm able to see the timer part working(Could see the timer count change) but no Waveform output on the pin. Below is the code. I deeply appreciate any help.

void HAL_GPIO_Pin_PmuxEn(uint8_t port, uint8_t pin, uint8_t mux)
{
    PORT->Group[port].PINCFG[pin].reg |= PORT_PINCFG_PMUXEN;
    if ((pin & 0x01) == 0x01)
    {
        PORT->Group[port].PMUX[pin>>1].bit.PMUXO = mux;        
    }
    else                            
    {
        PORT->Group[port].PMUX[pin>>1].bit.PMUXE = mux;
    }
}

void Timer6_Init(void)
{
    HAL_GPIO_Pin_PmuxEn(GPIO_PORTA, PIN_PA28, TC_PMUX);        /* PORT - assign the pin to timer */
    
    PM->APBCMASK.reg |= PM_APBCMASK_TC6;
    GCLK->CLKCTRL.reg = (uint16_t)(GCLK_CLKCTRL_ID(TC6_GCLK_ID) |
                                GCLK_CLKCTRL_CLKEN |
                                GCLK_CLKCTRL_GEN(0U));

    /* Disable TC before configuring the timer */
    TC6->COUNT16.CTRLA.reg = (uint16_t)(TC_CTRLA_SWRST);
    /* Wait for sync */
    while ((TC6->COUNT16.STATUS.reg & TC_STATUS_SYNCBUSY) == TC_STATUS_SYNCBUSY) {};
    
    /* Setup CTRLA register
    - Mode     : 16_BIT
    - Wavegen  : Match PWM
    - Prescaler: DIV1
    - PreSync  : GCLK (Reload or reset the counter on next generic clock)
    */
    TC6->COUNT16.CTRLA.reg |= (uint16_t)(TC_CTRLA_PRESCALER_DIV1 |
                              TC_CTRLA_MODE_COUNT16 |
                              TC_CTRLA_WAVEGEN_MPWM |
                              TC_CTRLA_PRESCSYNC_GCLK);
    
    TC6->COUNT16.CTRLBCLR.reg |= (uint16_t)TC_CTRLBCLR_DIR; 
   
    /* Wait for sync */
    while ((TC6->COUNT16.STATUS.reg & TC_STATUS_SYNCBUSY) == TC_STATUS_SYNCBUSY) {};

     
    /* Setup CTRLBCLR register
    - Clear all commands
    */

    TC6->COUNT16.CC[0].reg = 16000;
    TC6->COUNT16.CC[1].reg = 200;
    TC6->COUNT16.COUNT.reg = 0x0000;
    
    TC6->COUNT16.DBGCTRL.bit.DBGRUN = 0x1; /* Debug Control Enabled */
   
    /* Wait for sync */
    while ((TC6->COUNT16.STATUS.reg & TC_STATUS_SYNCBUSY) == TC_STATUS_SYNCBUSY) {};
    
    
    /* Enable the timer */
    TC6->COUNT16.CTRLA.reg |= (uint16_t)(TC_CTRLA_ENABLE);   
    /* Wait for sync */
    while ((TC6->COUNT16.STATUS.reg & TC_STATUS_SYNCBUSY) == TC_STATUS_SYNCBUSY) {};
}

 

This topic has a solution.

Jayanth

Last Edited: Thu. Nov 30, 2017 - 04:35 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found out the problem. Its the error in Datasheet. PA28 is not associated with the TC6.

 

Old Datasheet - http://www.atmel.com/images/Atmel-9349-SMART-ARM-based-MCUs-SAM-DA1_Datasheet.pdf and it has error in datasheet

 

New Datasheet corrected available at http://ww1.microchip.com/downloads/en/DeviceDoc/40001895A.pdf

Jayanth