Hi freaks,
I am struggling with ASF and it seems harder than I expected. After running a blink, I am trying to generate a PWM waveform on channel 0. This is my code:
#include#include pwm_channel_t pwm_channel_instance; #define MY_LED IOPORT_CREATE_PIN(PIOC, 22) int main (void) { board_init(); sysclk_init(); ioport_set_pin_dir(MY_LED, IOPORT_DIR_OUTPUT); ioport_set_pin_level(MY_LED, LOW); pwm_channel_t pwm_channel_instance; pmc_enable_periph_clk(ID_PWM); pwm_channel_disable(PWM, PWM_CHANNEL_0); pwm_clock_t clock_setting = { .ul_clka = 1000 * 100, .ul_clkb = 1000 * 100, .ul_mck = 84000000 }; pwm_init(PWM, &clock_setting); pwm_channel_instance.ul_prescaler = PWM_CMR_CPRE_CLKA; pwm_channel_instance.ul_period = 100; pwm_channel_instance.ul_duty = 20; pwm_channel_instance.channel = PWM_CHANNEL_0; pwm_channel_init(PWM, &pwm_channel_instance); pwm_channel_enable(PWM, PWM_CHANNEL_0); while(1){ delay_ms(1); ioport_set_pin_level(MY_LED, HIGH); delay_ms(1); ioport_set_pin_level(MY_LED, LOW); } }
I expect to get a PWM code on pin PWML0(PC2) but ge nothing. BTW, I read somewhere that LPCXpresso with codered IDE is way better with ready to use functions. Has anybody worked? I am wondering to move to LPC to save time digging in ASF.