求助:在论坛上参考了好像是战舰版的示例程序,可以用定时器输入捕获的方式计算方波的高电平时间,于是在那个程序的基础上做了些修改,想要套用在计算正弦波的周期上,但是计算出的周期不正确,下面贴出来部分程序:请大家帮忙分析分析问题,谢谢
void TIM3_Cap_Init(u16 arr,u16 psc)
{
TIM_ICInitTypeDef TIM3_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_7);
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler =psc;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM3_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM3_ICInitStructure.TIM_ICFilter = 0x00;
TIM_ICInit(TIM3, &TIM3_ICInitStructure);
TIM_ITConfig(TIM3,TIM_IT_Update|TIM_IT_CC2,ENABLE);
TIM_Cmd(TIM3,ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_IRQHandler(void)
{
TIM3CH2_CAPTURE_VAL=TIM_GetCapture2(TIM3);
TIM_ClearITPendingBit(TIM3, TIM_IT_CC2|TIM_IT_Update);
TIM3CH2_CAPTURE_VAL = 0;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
可他只管周期,没什么特别的
一周热门 更多>