void Timer0_PWM_Init(void)
{
timer_parameter_struct timer_initpara;
timer_oc_parameter_struct timer_ocintpara;
timer_break_parameter_struct timer_breakintpara;
timer_deinit(TIMER0);
/* TIMER0 configuration */
timer_initpara.period = PWMFreq_40K0/2;
timer_initpara.prescaler = 0;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE; //计数器的触发方式
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0,&timer_initpara);
timer_ocintpara.outputstate = TIMER_CCX_ENABLE; //配置比较输出状态使能
timer_ocintpara.outputnstate = TIMER_CCXN_ENABLE; //配置互补比较输出状态使能
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH; //有效电平极性高
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH; //互补有效电平高
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; //空闲状态定时器输出引脚状态低
timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; //空闲状态互补输出引脚状态低
timer_channel_output_config(TIMER0,TIMER_CH_0,&timer_ocintpara);
timer_channel_output_config(TIMER0,TIMER_CH_1,&timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_0,0);
timer_channel_output_mode_config(TIMER0,TIMER_CH_0,TIMER_OC_MODE_TOGGLE);
timer_channel_output_shadow_config(TIMER0,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_1,0);
timer_channel_output_mode_config(TIMER0,TIMER_CH_1,TIMER_OC_MODE_TOGGLE);
timer_channel_output_shadow_config(TIMER0,TIMER_CH_1,TIMER_OC_SHADOW_DISABLE);
timer_breakintpara.runoffstate = TIMER_ROS_STATE_DISABLE;
timer_breakintpara.ideloffstate = TIMER_IOS_STATE_DISABLE;
timer_breakintpara.protectmode = TIMER_CCHP_PROT_0;
timer_breakintpara.deadtime = DEAD_CYCLE;
timer_breakintpara.breakstate = TIMER_BREAK_DISABLE;
timer_breakintpara.breakpolarity = TIMER_BREAK_POLARITY_LOW;
timer_breakintpara.outputautostate = TIMER_OUTAUTO_ENABLE;
timer_break_config(TIMER0,&timer_breakintpara);
timer_primary_output_config(TIMER0,ENABLE);
timer_auto_reload_shadow_enable(TIMER0);
timer_enable(TIMER0);
}
以上为TIMER0的配置。
例如进行以下操作修改通道1的相位:
操作1:
timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_1,600);
操作2:
timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_1,0);
现象:
在修改相位为600时,会出现两种状态的波形
|
在每次修改捕获/比较寄存器的值后,当计数器的值与其相同时,会出现两种状态