跪求高手指教..................
STM8L 获取脉冲周期
我把PD1设置为上升沿中断端口,来响应脉冲信号的上升沿,用TIM3计数,然后在中断处理函数里记录定时器计数值,为什么脉冲频率怎么变计数值差都在16、17之间徘徊
//TIM3初始化:
void TIM3_Init()
{
TIM3_DeInit();
TIM3_CounterModeConfig(TIM3_CounterMode_Up);
TIM3_TimeBaseInit(TIM3_Prescaler_16, TIM3_CounterMode_Up, 32767);
TIM3_PrescalerConfig(TIM3_Prescaler_16, TIM3_PSCReloadMode_Immediate);
TIM3_ARRPreloadConfig(ENABLE); //ENABLE or DISABLE
//TIM3_ITConfig(TIM2_IT_Update,ENABLE);
TIM3_Cmd(ENABLE);
}
void EXTI_Init()
{
EXTI_DeInit();
EXTI_SelectPort(EXTI_Port_D);
//EXTI_SetPortSensitivity(EXTI_Port_D,EXTI_Trigger_Falling);
EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Rising);
ITC_SetSoftwarePriority(EXTI1_IRQn, ITC_PriorityLevel_1); //设置中断优先级
GPIO_ExternalPullUpConfig(GPIOD, GPIO_Pin_1, ENABLE);
GPIO_Init(GPIOD, GPIO_Pin_1, GPIO_Mode_In_FL_IT);
}
//中断处理函数
INTERRUPT_HANDLER(EXTI1_IRQHandler,9)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
static int i = 0;
//TIM3_Cmd(ENABLE);
if(i!=10)
{
m[i] = TIM3_GetCounter();
i++;
}
else
{
GPIO_Init(GPIOD, GPIO_Pin_1, GPIO_Mode_In_FL_No_IT);
i = 0;
TIM3_Cmd(DISABLE);
}
} |