Can't change SAMC21E18A PWM Duty cycle

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

Hi,

 

I have created a simple project with  https://start.atmel.com/ for the SAMC21E18A (I have only init the PWM). Sadly, no matter what parameter I set with "pwm_set_parameters", the duty cycle stay at 99%.

 

Did I miss something for the initialization ?

 

struct pwm_descriptor PWM_0;

void PWM_1_PORT_init(void)
{

    gpio_set_pin_function(PA22, PINMUX_PA22E_TC0_WO0);
}

void PWM_1_CLOCK_init(void)
{
    hri_mclk_set_APBCMASK_TC0_bit(MCLK);
    hri_gclk_write_PCHCTRL_reg(GCLK, TC0_GCLK_ID, CONF_GCLK_TC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
}

void PWM_1_init(void)
{
    PWM_1_CLOCK_init();
    PWM_1_PORT_init();
    pwm_init(&PWM_1, TC0, _tc_get_pwm());

}

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();

    pwm_set_parameters(&PWM_1, 10000, 5000);
    
    pwm_enable(&PWM_1);

    /* Replace with your application code */
    while (1) {
    }
}

 

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

Probably the pwm is implemented with the mode that uses compare channel 0 for the period and channel 1 for duty cycle. The useful output in this case is on WO1 not WO0.

/Lars

 

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

Thank you for your answer Lars.

Is there a way to use WO1 with the pin PA22? On the "Atmel start", you can only choose PA15, PA19, PA23 and PA25 when you click on the component signal WO/1.

Is there any datasheet about the different WO? I don't really understand the difference between the options available.

Last Edited: Wed. Dec 18, 2019 - 02:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WO1 can't be PA22 no, check the datasheet section "I/O Multiplexing and Considerations" for what is possible.

/Lars

 

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

So it's impossible to generate a PWM waveform with the PA22 pin, is that correct?

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

No not impossible, you can try the Lite:TC:PWM driver and 8-bit mode for example (or don't use atmel start at all). In any case you will probably have to read about the TC in the datasheet.

/Lars

 

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

Thank you for your answer. I was able to make it works with the Lite:TC:PWM driver and 8-bit mode.

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

Antoine

Would you be willing to share the code you used to do that, or suggest any resources on how to do it? I'm trying to achieve something very similar to you, and while 'm familiar with using the AtmelStart generated code and HAL-based programming, but I'm struggling to create this PWM driver myself using just the SamC21 datasheet as a guide.