用定时器3来捕获一路PWM信号上升沿进入中断,将两次相邻上升沿中断的计数值除以常数45后,作为定时器4的的计数周期,因为PWM频率是变化的,所以定时器4的计数周期一段时间后也会改变,求教思路,目前只会这些
void TIM3_Configuration(void)//定时器3用来捕获上升沿进入中断
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 7199;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
void TIM4_Configuration(void)//定时器4计数中断
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_DeInit(TIM4);
TIM_TimeBaseInitStructure.TIM_Period =arr; //arr由定时器3捕获的PWM相邻上升沿的计数值除以45确定
TIM_TimeBaseInitStructure.TIM_Prescaler=7199;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseInitStructure);//3õê¼»ˉTIM4
TIM_ARRPreloadConfig(TIM4, ENABLE);
//TIM_ClearFlag(TIM4, TIM_FLAG_Update);
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM4,ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我是想把定时器4的计数周期TIM_TimeBaseInitStructure.TIM_Period =arr由定时器3的捕获的PWM的相邻两个上升沿之间的计数值决定,看的基本例程Period都是设置成常数了
一周热门 更多>