汇集网友智慧,解决技术难题
赞0
看了芯片手册,把通道换到CH3也不行。复制void b_timer_config(uint16_t __pres, uint16_t __period, uint16_t __pulse) { timer_parameter_struct timer_initpara; // timer_oc_parameter_struct timer_ocinitpara; // timer_break_parameter_struct timer_breakpara; rcu_periph_clock_enable(RCU_TIMER0); timer_deinit(TIMER0); timer_struct_para_init(&timer_initpara); timer_initpara.prescaler = __pres; timer_initpara.alignedmode = TIMER_COUNTER_EDGE; timer_initpara.counterdirection = TIMER_COUNTER_UP; timer_initpara.period = __period; // 10KHz timer_initpara.clockdivision = TIMER_CKDIV_DIV1; timer_initpara.repetitioncounter = 0; timer_init(TIMER0, &timer_initpara); // timer_channel_output_struct_para_init(&timer_ocinitpara); // timer_ocinitpara.outputstate = TIMER_CCX_DISABLE; // timer_ocinitpara.outputnstate = TIMER_CCXN_DISABLE; // timer_ocinitpara.ocpolarity = TIMER_OC_POLARITY_HIGH; // timer_ocinitpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH; // timer_ocinitpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; // timer_ocinitpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; // timer_channel_output_config(TIMER14, TIMER_CH_0, &timer_ocinitpara); // timer_break_struct_para_init(&timer_breakpara); // timer_breakpara.runoffstate = TIMER_ROS_STATE_ENABLE; // timer_breakpara.ideloffstate = TIMER_IOS_STATE_ENABLE; // timer_breakpara.deadtime = 164; // timer_breakpara.breakpolarity = TIMER_BREAK_POLARITY_LOW; // timer_breakpara.outputautostate = TIMER_OUTAUTO_ENABLE; // timer_breakpara.protectmode = TIMER_CCHP_PROT_OFF; // timer_breakpara.breakstate = TIMER_BREAK_ENABLE; // timer_break_config(TIMER0, &timer_breakpara); // timer_channel_output_shadow_config(TIMER0, TIMER_CH_3, TIMER_OC_SHADOW_ENABLE); timer_channel_output_mode_config(TIMER0, TIMER_CH_3, TIMER_OC_MODE_TIMING); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, __pulse); nvic_irq_enable(TIMER0_Channel_IRQn, 1); timer_interrupt_enable(TIMER0, TIMER_INT_CH3); timer_auto_reload_shadow_enable(TIMER0); timer_enable(TIMER0); } void TIMER0_IRQHandler(void) { static uint8_t status = 0; if (SET == timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH3)) { status++; switch (status % 3){ case 0: printf("a\n"); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, tim[B].idle); timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, 0); break; case 1: printf("b\n"); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, tim[B].t_off); timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, 0); break; case 2: printf("c\n"); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, tim[B].t_on); timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, pwm_ch[B].pulse); break; default: break; } timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH3); } } 评论 2021-04-08 分享 没有帮助 举报
void b_timer_config(uint16_t __pres, uint16_t __period, uint16_t __pulse) { timer_parameter_struct timer_initpara; // timer_oc_parameter_struct timer_ocinitpara; // timer_break_parameter_struct timer_breakpara; rcu_periph_clock_enable(RCU_TIMER0); timer_deinit(TIMER0); timer_struct_para_init(&timer_initpara); timer_initpara.prescaler = __pres; timer_initpara.alignedmode = TIMER_COUNTER_EDGE; timer_initpara.counterdirection = TIMER_COUNTER_UP; timer_initpara.period = __period; // 10KHz timer_initpara.clockdivision = TIMER_CKDIV_DIV1; timer_initpara.repetitioncounter = 0; timer_init(TIMER0, &timer_initpara); // timer_channel_output_struct_para_init(&timer_ocinitpara); // timer_ocinitpara.outputstate = TIMER_CCX_DISABLE; // timer_ocinitpara.outputnstate = TIMER_CCXN_DISABLE; // timer_ocinitpara.ocpolarity = TIMER_OC_POLARITY_HIGH; // timer_ocinitpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH; // timer_ocinitpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; // timer_ocinitpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; // timer_channel_output_config(TIMER14, TIMER_CH_0, &timer_ocinitpara); // timer_break_struct_para_init(&timer_breakpara); // timer_breakpara.runoffstate = TIMER_ROS_STATE_ENABLE; // timer_breakpara.ideloffstate = TIMER_IOS_STATE_ENABLE; // timer_breakpara.deadtime = 164; // timer_breakpara.breakpolarity = TIMER_BREAK_POLARITY_LOW; // timer_breakpara.outputautostate = TIMER_OUTAUTO_ENABLE; // timer_breakpara.protectmode = TIMER_CCHP_PROT_OFF; // timer_breakpara.breakstate = TIMER_BREAK_ENABLE; // timer_break_config(TIMER0, &timer_breakpara); // timer_channel_output_shadow_config(TIMER0, TIMER_CH_3, TIMER_OC_SHADOW_ENABLE); timer_channel_output_mode_config(TIMER0, TIMER_CH_3, TIMER_OC_MODE_TIMING); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, __pulse); nvic_irq_enable(TIMER0_Channel_IRQn, 1); timer_interrupt_enable(TIMER0, TIMER_INT_CH3); timer_auto_reload_shadow_enable(TIMER0); timer_enable(TIMER0); } void TIMER0_IRQHandler(void) { static uint8_t status = 0; if (SET == timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH3)) { status++; switch (status % 3){ case 0: printf("a\n"); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, tim[B].idle); timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, 0); break; case 1: printf("b\n"); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, tim[B].t_off); timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, 0); break; case 2: printf("c\n"); timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, tim[B].t_on); timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, pwm_ch[B].pulse); break; default: break; } timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH3); } }
评论
2021-04-08
点击图片添加到编辑器内容中
点击文件名将附件添加到文章中
提交
tyw
319个答案
天意无罪
287个答案
xch
238个答案
jjjyufan
209个答案
coody
202个答案
LcwSwust
172个答案
chunyang
135个答案
地瓜patch
128个答案
赞0
您需要登录后才可以回复 登录 | 注册
本周活跃用户
问答专家
tyw
319个答案
天意无罪
287个答案
xch
238个答案
jjjyufan
209个答案
coody
202个答案
LcwSwust
172个答案
chunyang
135个答案
地瓜patch
128个答案