Hi all,
I am new here and new to ASF. And to be quite honest - I have found it quite hard work. That being said, I feel I am making head way. I have pulled a number of examples from various sources, each seem to do things a little differently. I have tried all those I can find and modifed as necessary, but to no prevail. Just trying to get a basic PWM setup, that's all. I've spent time diving into the code and all is making sense, so I don't know what I am missing/doing wrong. If anyone has any suggestions... it would be most appreciated. Thanks in advance. This is an example I pulled from 'All About Circuits', project is attached.
#include <asf.h> //Create Pin PA1 #define PWM_Pin IOPORT_CREATE_PIN(PIOA, PIO_PA1_IDX) pwm_channel_t pwm_channel_instance; int main (void) { sysclk_init(); board_init(); //pio_set_peripheral(PWM,PIO_PERIPH_A, PIO_PA1A_PWMH1); I have also tried this instead of pio_configure_pin //connect peripheral A to pin PA1 pio_configure_pin(PWM_Pin, PIO_TYPE_PIO_PERIPH_A); //enable the peripheral clock for the PWM hardware pmc_enable_periph_clk(ID_PWM); //disable the channel until it is properly configured pwm_channel_disable(PWM, PWM_CHANNEL_0); //PWM clock configuration pwm_clock_t PWM_clock_config = { .ul_clka = 1000000, .ul_clkb = 0, .ul_mck = sysclk_get_cpu_hz() }; //apply the clock configuration pwm_init(PWM, &PWM_clock_config); //see the article for details pwm_channel_instance.channel = PWM_CHANNEL_0; pwm_channel_instance.ul_prescaler = PWM_CMR_CPRE_CLKA; pwm_channel_instance.polarity = PWM_HIGH; pwm_channel_instance.alignment = PWM_ALIGN_LEFT; pwm_channel_instance.ul_period = 100; pwm_channel_instance.ul_duty = 50; //apply the channel configuration pwm_channel_init(PWM, &pwm_channel_instance); //configuration is complete, so enable the channel pwm_channel_enable(PWM, PWM_CHANNEL_0); while(1); }