本帖最后由 fw19876311 于 2023-8-16 19:53 编辑
void BSP_TMR1_Init(void){
GPIO_Config_T gpioConfig;
TMR1_EncoderConfig_T Tmr1_EncoderConfig;
TMR1_TimeBaseConfig_T timeBaseConfig;
TMR1_ICConfig_T icConfig;
RCM_EnableAPBPeriphClock(RCM_PERIPH_TMR1);
gpioConfig.pin = GPIO_PIN_6 | GPIO_PIN_7;
gpioConfig.mode = GPIO_MODE_IN_FLOATING;
GPIO_Config(GPIOC, &gpioConfig);
/** Up-counter */
timeBaseConfig.cntMode = TMR1_CNT_MODE_UP;
/** Set counter = 0xff */
timeBaseConfig.count = 0XFF;
/** Set divider = 47.So TMR1 clock freq ~= 48/(47 + 1) = 1MHZ */
timeBaseConfig.divider = 47;
/** Repetition counter = 0x0 */
timeBaseConfig.repetitionCount = 0X04;
TMR1_ConfigTimerBase(TMR1, &timeBaseConfig);
/* Input Capture */
icConfig.channel = TMR1_CHANNEL_1;
icConfig.polarity = TMR1_IC_POLARITY_RISING;
icConfig.selection = TMR1_IC_SELECT_INDIRECTTI;
icConfig.div = TMR1_IC_DIV_1;
icConfig.filter = 0;
TMR1_ConfigInputCapture(TMR1, &icConfig);
icConfig.channel = TMR1_CHANNEL_2;
TMR1_ConfigInputCapture(TMR1, &icConfig);
Tmr1_EncoderConfig.mode = TMR1_ENCODER_MODE_CH1INFP12;
Tmr1_EncoderConfig.polarityIC1 = TMR1_IC_POLARITY_RISING;
Tmr1_EncoderConfig.polarityIC2 = TMR1_IC_POLARITY_RISING;
TMR1_ConfigEncodeInterface(TMR1,&Tmr1_EncoderConfig);
TMR1_SetCounter(TMR1, 0x0004);
TMR1_ClearStatusFlag(TMR1, TMR1_FLAG_UPDATE);
TMR1_EnableInterrupt(TMR1, TMR1_INT_UPDATE);
NVIC_EnableIRQRequest(TMR1_UT_IRQn, 0);
/** Enable TMR1 */
TMR1_Enable(TMR1);
}
引脚的模式改了也不行
|