void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == htim3.Instance)
{
overload_Cnt++;
}
else overload_Cnt=0;
}
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == htim3.Instance)
{
switch(capture_Cnt)
{
case 0:
capture_Buf[0] = HAL_TIM_ReadCapturedValue(&htim3,TIM_CHANNEL_1); //Get capture value now
__HAL_TIM_SET_CAPTUREPOLARITY(&htim3,TIM_CHANNEL_1,TIM_ICPOLARITY_RISING); //Set to falling edge capture
capture_Cnt++;break;
case 1:
capture_Buf[1] = HAL_TIM_ReadCapturedValue(&htim3,TIM_CHANNEL_1); //Get capture value now
HAL_TIM_IC_Stop_IT(&htim3,TIM_CHANNEL_1); //Stop input capture OR: __HAL_TIM_DISABLE(&htim5);
Period = capture_Buf[1] - capture_Buf[0] + overload_Cnt * 0xFFFF;
capture_Cnt = 0; //Clear the flag
overload_Cnt = 0; //Clear the overload flag
printf ("CNT:%d\r\n",Period);
OLED_Clear();
process(Period);
HAL_Delay(1000);
__HAL_TIM_SET_CAPTUREPOLARITY(&htim3, TIM_CHANNEL_1, TIM_INPUTCHANNELPOLARITY_RISING);
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1); //Start input capture OR: __HAL_TIM_ENABLE(&htim5);
break; }
}
} |