/* \brief This is an example that shows how to do the following: * - start a high frequency clock * - switch the main clock to that high frequency clock * - set-up a generic clock with a high frequency clock as a source * - output a generic clock to GCLK_0_1(EVK1100) / GCLK_2_1 / GCLK_2(EVK1101) / * GCLK_1_0(EVK1104) / GCLK_0_2(UC3C_EK) / GCLK_1_0(STK600_RCUC3L0 & AT32UC3L-EK) * */ int main(void) { /* Start a high frequency clock and switch the main clock to that high frequency clock */ local_start_highfreq_clock(); /* Set-up a generic clock from a high frequency clock and output it to a gpio pin. */ local_start_gc(); /* Now toggle LED0 using a GPIO */ while(1) { gpio_tgl_gpio_pin(LED0_GPIO); software_delay(); } }
/*! \brief Main function. Execution starts here. * * \return 0 on success */ int main(void) { pwm_opt_t pwm_opt; // PWM option config. avr32_pwm_channel_t pwm_channel = {{0}, // cmr {0}, // cdty {0}, // cdtyupd {0}, // cprd {0}, // cprdupd {0}, // ccnt {0}, // dt {0}};// dtupd ; One channel config. unsigned int channel_id; // Start Main Clock On external 16MHz Oscillator // Start PLL for PWM local_start_highfreq_clock(); // Start Enable Generic Clock with PLL as source clock pwm_start_gc(); channel_id = EXAMPLE_PWM_CHANNEL_ID; gpio_enable_module_pin(EXAMPLE_PWM_L_PIN, EXAMPLE_PWM_L_FUNCTION); gpio_enable_module_pin(EXAMPLE_PWM_H_PIN, EXAMPLE_PWM_H_FUNCTION); // PWM controller configuration. pwm_opt.diva = AVR32_PWM_DIVA_CLK_OFF; pwm_opt.divb = AVR32_PWM_DIVB_CLK_OFF; pwm_opt.prea = AVR32_PWM_PREA_CCK; pwm_opt.preb = AVR32_PWM_PREB_CCK; pwm_opt.fault_detection_activated = false; pwm_opt.sync_channel_activated = true; pwm_opt.sync_update_channel_mode = PWM_SYNC_UPDATE_MANUAL_WRITE_MANUAL_UPDATE; pwm_opt.sync_channel_select[0] = true; pwm_opt.sync_channel_select[1] = true; pwm_opt.sync_channel_select[2] = false; pwm_opt.sync_channel_select[3] = false; pwm_opt.cksel = PWM_CKSEL_GCLK; pwm_init(&pwm_opt); // Update the period pwm_update_period_value(10); // Channel configuration pwm_channel.CMR.dte = 1; // Enable Deadtime for complementary Mode pwm_channel.CMR.dthi = 1; // Deadtime Inverted on PWMH pwm_channel.CMR.dtli = 0; // Deadtime Not Inverted on PWML pwm_channel.CMR.ces = 0; // 0/1 Channel Event at the End of PWM Period pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; // Channel mode. pwm_channel.CMR.cpol = PWM_POLARITY_LOW; // Channel polarity. pwm_channel.CMR.cpre = AVR32_PWM_CPRE_CCK; // Channel prescaler. pwm_channel.cdty = 10; // Channel duty cycle, should be < CPRD. pwm_channel.cprd = 20; // Channel period. // With these settings, the output waveform period will be : // (56MHz)/20 == 2.8MHz == (MCK/prescaler)/period, with MCK == 56MHz, // prescaler == 1, period == 20. pwm_channel_init(channel_id, &pwm_channel); // Set channel configuration to channel 0 pwm_start_channels((1 << channel_id)); // Start channel 0 & 1. while(1); }