硬件初始化:
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_TIMER2);
rcu_periph_clock_enable(RCU_AF);
gpio_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_8);
gpio_pin_remap_config(GPIO_TIMER2_FULL_REMAP, ENABLE);//PC8 FULL Remap
timer_deinit(TIMER2);
/* initialize TIMER init parameter struct */
timer_struct_para_init(&timer_initpara);
/* TIMER2 configuration */
timer_initpara.prescaler = 0;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 65535;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2, &timer_initpara);
/* TIMER2 configuration */
/* TIMER2 CH2 PWM input capture configuration */
timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING;
timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;
timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
timer_icinitpara.icfilter = 0;
//timer_input_pwm_capture_config(TIMER2, TIMER_CH_2, &timer_icinitpara);
timer_input_capture_config(TIMER2, TIMER_CH_2, &timer_icinitpara);
/* slave mode selection: TIMER2 */
timer_input_trigger_source_select(TIMER2, TIMER_SMCFG_TRGSEL_CI1FE1);
timer_slave_mode_select(TIMER2, TIMER_SLAVE_MODE_RESTART);
/* select the master slave mode */
timer_master_slave_mode_config(TIMER2, TIMER_MASTER_SLAVE_MODE_ENABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER2);
/* clear channel 2 interrupt bit */
timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_CH2);
/* channel 2 interrupt enable */
timer_interrupt_enable(TIMER2, TIMER_INT_CH2);
/* TIMER2 counter enable */
timer_enable(TIMER2);
中断函数:
void TIMER2_IRQHandler(void)
{
if(SET == timer_interrupt_flag_get(TIMER2, TIMER_INT_FLAG_CH2))
{
/* clear channel 1 interrupt bit */
timer_interrupt_flag_clear(TIMER2, TIMER_INT_FLAG_CH2);
/* read channel 1 capture value */
ic1valueW[0] = timer_channel_capture_value_register_read(TIMER2, TIMER_CH_2) + 1;
if(0 != ic1valueW[0])
{
/* read channel 1 capture value */
ic2valueW[0] = timer_channel_capture_value_register_read(TIMER2, TIMER_CH_2)+1;
/* calculate the duty cycle value */
dutycycleW[0] = (ic2valueW[0] * 100) / ic1valueW[0];
/* calculate the frequency value */
frequencyW[0] = 1000000 / ic1valueW[0];
}
else
{
dutycycleW[0] = 0;
frequencyW[0] = 0;
}
}
硬件没有问题,MCU的IO口有真实的PWM波形,但是中断没有触发
各路大神,跪求指点找出问题在哪里
|