From 1a4ea70147216f586f1341d4f1981733ed2c203c Mon Sep 17 00:00:00 2001 From: tao_z <tzj0429@163.com> Date: Sat, 03 Jul 2021 21:41:30 +0800 Subject: [PATCH] 采用三个外部中断触发 --- USR/SRC/pwm.c | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-) diff --git a/USR/SRC/pwm.c b/USR/SRC/pwm.c index b30d6e5..13d33dc 100644 --- a/USR/SRC/pwm.c +++ b/USR/SRC/pwm.c @@ -48,7 +48,7 @@ *****************************************************************************************************/ static void Timer0Init(void) { - uint16_t Duty = PERIOD_CMP / 10; + uint16_t Duty = PERIOD_CMP / 2; timer_parameter_struct timercontralcfg; timer_oc_parameter_struct timeroutcfg[3]; timer_break_parameter_struct timer_breakpara; @@ -90,25 +90,25 @@ timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_1, Duty); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_2, Duty); - timer_channel_output_mode_config(TIMER0, TIMER_CH_0, TIMER_OC_MODE_PWM1); //set pwm1 mode first low then high - timer_channel_output_mode_config(TIMER0, TIMER_CH_1, TIMER_OC_MODE_PWM1); - timer_channel_output_mode_config(TIMER0, TIMER_CH_2, TIMER_OC_MODE_PWM1); + timer_channel_output_mode_config(TIMER0, TIMER_CH_0, TIMER_OC_MODE_PWM0); //set pwm1 mode first low then high + timer_channel_output_mode_config(TIMER0, TIMER_CH_1, TIMER_OC_MODE_PWM0); + timer_channel_output_mode_config(TIMER0, TIMER_CH_2, TIMER_OC_MODE_PWM0); timer_channel_output_shadow_config(TIMER0, TIMER_CH_0, TIMER_OC_SHADOW_ENABLE); //shadow ENable timer_channel_output_shadow_config(TIMER0, TIMER_CH_1, TIMER_OC_SHADOW_ENABLE); timer_channel_output_shadow_config(TIMER0, TIMER_CH_2, TIMER_OC_SHADOW_ENABLE); - /* configure TIMER break function */ - timer_break_struct_para_init(&timer_breakpara); - /* automatic output enable, break, dead time and lock configuration*/ - timer_breakpara.runoffstate = TIMER_ROS_STATE_DISABLE; - timer_breakpara.ideloffstate = TIMER_IOS_STATE_DISABLE; - timer_breakpara.deadtime = 255; - timer_breakpara.breakpolarity = TIMER_BREAK_POLARITY_LOW; - timer_breakpara.outputautostate = TIMER_OUTAUTO_ENABLE; - timer_breakpara.protectmode = TIMER_CCHP_PROT_0; - timer_breakpara.breakstate = TIMER_BREAK_ENABLE; - timer_break_config(TIMER0, &timer_breakpara); + // /* configure TIMER break function */ + // timer_break_struct_para_init(&timer_breakpara); + // /* automatic output enable, break, dead time and lock configuration*/ + // timer_breakpara.runoffstate = TIMER_ROS_STATE_DISABLE; + // timer_breakpara.ideloffstate = TIMER_IOS_STATE_DISABLE; + // timer_breakpara.deadtime = 32; + // timer_breakpara.breakpolarity = TIMER_BREAK_POLARITY_LOW; + // timer_breakpara.outputautostate = TIMER_OUTAUTO_ENABLE; + // timer_breakpara.protectmode = TIMER_CCHP_PROT_0; + // timer_breakpara.breakstate = TIMER_BREAK_DISABLE; + // timer_break_config(TIMER0, &timer_breakpara); timer_primary_output_config(TIMER0, ENABLE); timer_auto_reload_shadow_enable(TIMER0); @@ -125,7 +125,7 @@ void SetPwmDuty(uint16_t ch, uint32_t duty) { - uint32_t duty_temp = (PERIOD_CMP >= duty) ? (PERIOD_CMP - duty) : 0; + // uint32_t duty_temp = (PERIOD_CMP >= duty) ? (PERIOD_CMP - duty) : 0; timer_channel_output_pulse_value_config(TIMER0, ch, duty); } -- Gitblit v1.8.0