How can I independently change PWM channel settings in ASF4?

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

Atmel Start has a driver for PWM that allows you to control up to 4 PWM channels. The configuration lets you set the initial period and duty cycle for the PWM channels.  I can now set the PWM duty cycle for all channels to the same value. But I want to control each channel independently.

 

The ASF4 API Reference manual has the pwm_set_parameters() function to change the pwm duty cycle and period during program operation.  However, this function changes all PWM channels with the same value. It does not let you pass in a channel number to set a specific PWM channel.   Atmel Start lets you set the initial values for each channel. 

 

How do I change each PWM channel independently at run time?

This topic has a solution.
Last Edited: Fri. Oct 2, 2020 - 09:59 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok. I think I found the solution. The ASF Driver does not appear to have a command that lets you control the PWMs independently. But I wrote this simple function that lets you specify the channel that you want to change, so that you can do them independently.

 

void MyPwmSetParameters(struct _pwm_device *const device, uint8_t ui8Channel, uint32_t ui32Period, uint32_t ui32DutyCycle)
{
    hri_pwm_write_CDTYUPD_reg(device->hw, ui8Channel, ui32DutyCycle);
    hri_pwm_write_CPRDUPD_reg(device->hw, ui8Channel, ui32Period);
}