• AVR Freaks

Hot!SAML10 PWM in Harmony

Author
Eman2008
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2008/03/19 13:22:10
  • Location: 0
  • Status: offline
2021/01/20 18:08:09 (permalink)
0

SAML10 PWM in Harmony

Hi 
I am using the SAML10 Xplained pro kit to make a PWM output
 
I downloaded the compare project from Harmony projects.
 
it has 3 examples using the timers
 
I am trying to understand the configuration options and which one I should use but it is a little confusing
 
I want a 1KHz PWM output that I can change the duty cycle. I am thinking I should use the Normal PWM mode 
 
from the attached picture how do I adjust these compare 0 and compare 1 to get to what I need
 
Can someone please help?
 
Or should i be using some other setting?

Attached Image(s)

#1

2 Replies Related Threads

    malaugh
    Super Member
    • Total Posts : 425
    • Reward points : 0
    • Joined: 2011/03/31 14:04:42
    • Location: San Diego
    • Status: offline
    Re: SAML10 PWM in Harmony 2021/02/05 09:31:41 (permalink)
    0
    There are a few modes for the TC.  
     
    In 8 bit mode, with normal PWM, there are 3 registers controlling the output,  PER sets the period, when the count reaches this value, it resets to zero (assuming the TC is counting up).  The CC0 and CC1 registers give two separately controlled outputs.  For example if PER is set to 100, if CC0 is set to 50 you will get a 50% duty cycle
     
    In 16 bit mode, with normal PWM, the period cannot be controlled, it always resets at max count, but like the 8 bit case. the CC0 and CC1 registers give two separately controlled outputs.  If match PWM is selected, then the CC0 register controls the period, and the CC1 register gives the PWM output.
     
    The code below is for the backlight control if my LCD.
     
    Personally I do not use Harmony. 
     

     
        GCLK->PCHCTRL[23].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(0);        /* Connect GenClk0 to TC0 (4MHz CPU clock) */
        while ((GCLK->PCHCTRL[23].reg & GCLK_PCHCTRL_CHEN) == 0);               /* Wait for Sync */

        TC0->COUNT8.CTRLA.reg = TC_CTRLA_SWRST;                                 /* reset the timer */
        while(TC0->COUNT8.SYNCBUSY.reg & TC_SYNCBUSY_SWRST);                    /* wait for reset to complete */
        TC0->COUNT8.CTRLA.reg = TC_CTRLA_PRESCALER_DIV4 | TC_CTRLA_MODE_COUNT8; /* set to 1:4 prescaler and 8 bits */
        TC0->COUNT8.WAVE.reg = TC_WAVE_WAVEGEN_NPWM;                            /* set waveform to normal PWM */
        TC0->COUNT8.PER.reg = PWM_PERIOD;                                       /* set the PWM period */
        TC0->COUNT8.CC[0].reg = BRIGHT_TIMER_VALUE;                             /* set the PWM duty cycle */

        PORT->Group[BACKLIGHT_PORT].PINCFG[BACKLIGHT_PIN].reg = PORT_PINCFG_PMUXEN;     /* make port output for TC0 */
        PORT->Group[BACKLIGHT_PORT].PMUX[BACKLIGHT_PIN/2].reg |= PORT_PMUX_PMUXE(4);    /* PB08 = TC0/WO[0] */

        TC0->COUNT8.CTRLA.reg |= TC_CTRLA_ENABLE;                                /* Enable the timer */
        while(TC0->COUNT8.SYNCBUSY.reg & TC_SYNCBUSY_ENABLE);                   /* wait for sync */


     

     
     
    post edited by malaugh - 2021/02/05 09:33:06
    #2
    malaugh
    Super Member
    • Total Posts : 425
    • Reward points : 0
    • Joined: 2011/03/31 14:04:42
    • Location: San Diego
    • Status: offline
    Re: SAML10 PWM in Harmony 2021/02/05 10:12:14 (permalink)
    0
    A couple more comments
     
    The requirements is to have a 1KHz period with a variable duty cycle.
     
    According to your Harmony screen, the clock period is 2uS, so to get a 1Khz frequency (1000uS period) you should set the TC to 16 bit mode, select match PWM, and set CC0 to 500.  Then to vary the duty cycle, set CC1 to the initial duty cycle and change the duty cycle in your code by varying the CC1 value. Double buffering, which you have enabled, means the CC1 register with be updated when the CC0 count is reached. 
     
     
     
    #3
    Jump to:
    © 2021 APG vNext Commercial Version 4.5