程序想实现这样的功能:是在TIM4捕获中断中先关闭TIM2定时中断,处理几个语句之后再打开TIM2定时中断
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
ADC_Value_Channel2[ADC_Value_Number] = ADC_Converted_Channel[1];
if(ADC_Value_Channel2_Max < ADC_Value_Channel2[ADC_Value_Number])
{
ADC_Value_Channel2_Max = ADC_Value_Channel2[ADC_Value_Number];
ADC_Value_Max_Number = ADC_Value_Number;
}
ADC_Value_Number++;
}
}
/***********************************************************
* Function Name : TIM4_IRQHandler
* Description : This function handles TIM4 global interrupt request.
* Input : None
* Output : None
* Return : None
*****************************************************/
void TIM4_IRQHandler(void)
{
if (TIM_GetITStatus(TIM4, TIM_IT_CC4) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC4);
/*Disable the TIM2 global Interrupt*/
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
NVIC_Init(&NVIC_InitStructure);
Angle_Channel1_2 = ADC_Value_Max_Number*2*314/ADC_Value_Number;
ADC_Value_Max_Number_test = ADC_Value_Max_Number;
ADC_Value_Number_test = ADC_Value_Number;
ADC_Value_Number = 0;
ADC_Value_Channel2_Max = 0;
ADC_Value_Max_Number = 0;
/*Enable the TIM2 global Interrupt*/
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
}
请帮我看看,以上程序哪里有错误啊。
TIM4捕获的是25赫兹的方波的上升沿。
TIM2的定时频率为2500赫兹,读取ADC的采样值(ADC采样的是25赫兹的正弦波)。
所以在一个TIM4的两次捕获之间,应该有100次进入TIM2中断,所以每次进入TIM4中断时ADC_Value_Number的值应该为100,ADC_Value_Max_Number 的值应该为正弦波峰值多对应的采样个数。
但是现在的结果却是:每次进入TIM4中断,ADC_Value_Number和ADC_Value_Max_Number 每次都会变化,而且是随机的变化,变化幅度也很大。 |