/** * \file * * \brief Empty user application template * */ /** * \mainpage User Application template doxygen documentation * * \par Empty user application template * * Bare minimum empty user application template * * \par Content * * -# Include the ASF header files (through asf.h) * -# "Insert system clock initialization code here" comment * -# Minimal main function that starts with a call to board_init() * -# "Insert application code here" comment * */ /* * Include header files for all drivers that have been imported from * Atmel Software Framework (ASF). */ /* * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> */ #include <asf.h> #define DUTY_CYCLE 1000 volatile avr32_pwm_t *pwm = &AVR32_PWM; __attribute__((__interrupt__)) void pwm_handler() { AVR32_PWM.isr; if (pwm->channel[0].cdty == 0) { pwm->channel[0].cdty+=1; pwm->channel[1].cdty+=1; pwm->channel[2].cdty+=1; pwm->channel[6].cdty+=1; } else if (pwm->channel[0].cdty == DUTY_CYCLE) { pwm->channel[0].cdty-=1; pwm->channel[1].cdty-=1; pwm->channel[2].cdty-=1; pwm->channel[6].cdty-=1; } else { pwm->channel[0].cdty+=1; pwm->channel[1].cdty+=1; pwm->channel[2].cdty+=1; pwm->channel[6].cdty+=1; } delay_ms(50); } int main (void) { /* Insert system clock initialization code here (sysclk_init()). */ sysclk_init(); delay_init(16000000); /* PWM controller configuration. */ pwm_opt_t pwm_opt = { .diva = AVR32_PWM_DIVA_CLK_OFF, .divb = AVR32_PWM_DIVB_CLK_OFF, .prea = AVR32_PWM_PREA_MCK, .preb = AVR32_PWM_PREB_MCK }; /* PWM channel configuration structure. */ avr32_pwm_channel_t pwm_channel = { .ccnt = 0 }; /* With these settings, the output waveform period will be: * (115200/256)/20 == 22.5Hz == (MCK/prescaler)/period, with * MCK == 115200Hz, prescaler == 256, period == 20. */ pwm_channel.cdty = 0; /* Channel duty cycle, should be < CPRD. */ pwm_channel.cprd = DUTY_CYCLE; /* Channel period. */ pwm_channel.cupd = 0; /* Channel update is not used here. */ pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; /* Channel mode. */ pwm_channel.CMR.cpol = PWM_POLARITY_LOW; /* Channel polarity. */ pwm_channel.CMR.cpd = PWM_UPDATE_DUTY; /* Not used the first time. */ pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_8; /* Channel prescaler. */ static const gpio_map_t PWM_GPIO_MAP = { {7, 0}, {8, 0}, {21,0}, {22,0} }; gpio_enable_module(PWM_GPIO_MAP, sizeof(PWM_GPIO_MAP)/sizeof(PWM_GPIO_MAP[0]) ); /* Initialize the PWM module. */ pwm_init(&pwm_opt); pwm_channel_init(0,&pwm_channel); pwm_channel_init(1,&pwm_channel); pwm_channel_init(2,&pwm_channel); pwm_channel_init(6,&pwm_channel); INTC_init_interrupts(); // Register the EIC interrupt handlers to the interrupt controller. INTC_register_interrupt(&pwm_handler, AVR32_PWM_IRQ, AVR32_INTC_INT1); pwm->ier = 0x47; //PA07,08,21,22 pwm_start_channels(0x47); /* Insert application code here, after the board has been initialized. */ while(1) { pwm->ier =0x47; } }
This doesn't produce the interrupt. I connect the four pins to 4 LEDs, it should shade but it's maintaining the brightness as cdty is 0...