这个PWM模块超方便,只要加入PWM模块即可。
pwm_init(&pwm_cfg, PWM_TCE0, PWM_CH_A, 500);
首先,利用结构体配置成500HZ的频率
然后再设点空比为50%
pwm_start(&pwm_config, 50);
就这么简单,由于使用了PWM_TCE0和通道PWM_CH_A,所以输出应在PortE,的第0脚
以下是波形:
以下是程序:
- #include <asf.h>
- int main (void)
- {
- /* Insert system clock initialization code here (sysclk_init()). */
- //sysclk_init();
- struct pwm_config pwm_cfg;
- sysclk_init();
- board_init();
-
- pwm_init(&pwm_cfg, PWM_TCE0, PWM_CH_A, 500);
-
- pwm_start(&pwm_cfg, 50);
- /* Insert application code here, after the board has been initialized. */
- }
|