初级会员
- 积分
- 116
- 金钱
- 116
- 注册时间
- 2022-9-29
- 在线时间
- 27 小时
|
5金钱
这里是我定时器配置和定时器中断的代码,在仿真中可以做到按照设定好的挨个进中断,各个通道挨个输出波形,但烧录到板子上之后中断就进不去了,求助各位大佬,可能是什么问题哇。
void TIM3_IRQHandler(void) //TIM3ÖD¶Ï
{
static uint32_t i = 0;
static uint16_t j = 0;
static int index = 0;
if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //¼ì2éÖ¸¶¨μÄTIMÖD¶Ï·¢éúóë·ñ:TIM ÖD¶ÏÔ′
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //Çå3yTIMxμÄÖD¶Ï′y′|àíλ:TIM ÖD¶ÏÔ′
i++;
if(i == (1600-1))
{
i = 0;
j ++;
}
if(j == step[index])
{
j = 0;
switch (index)
{
case 0:
TIM_CCxCmd(TIM3,TIM_Channel_1 ,DISABLE);
TIM_CCxCmd(TIM3,TIM_Channel_4 ,ENABLE);
MOTOR1_STOP
MOTOR_SWAP_RUN
break;
case 1:
MOTOR_SWAP_STOP
TIM_CCxCmd(TIM3,TIM_Channel_4 ,DISABLE);
MOTOR_WASH_DIR_DOWN
MOTOR_WASH_RUN
TIM_CCxCmd(TIM3,TIM_Channel_3 ,ENABLE);
break;
case 2:
TIM_CCxCmd(TIM3,TIM_Channel_3 ,DISABLE);
WASH_ON
MOTOR_WASH_STOP
break;
case 3:
WASH_OFF
MOTOR_WASH_DIR_UP
TIM_CCxCmd(TIM3,TIM_Channel_3 ,ENABLE);
MOTOR_WASH_RUN
break;
case 4:
MOTOR_WASH_STOP
TIM_CCxCmd(TIM3,TIM_Channel_3 ,DISABLE);
MOTOR1_RUN
TIM_CCxCmd(TIM3,TIM_Channel_1 ,ENABLE);
break;
default :
TIM_Cmd(TIM3, DISABLE); //ê1ÄüTIM3
}
index ++;
}
}
}
void Motor_Swap_Nvic_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); //ê1ÄüÖ¸¶¨μÄTIM3ÖD¶Ï,ÔêDí¸üDÂÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÏèÕ¼óÅÏ輶0¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //′óóÅÏ輶3¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
}
static void Timer_Init(uint32_t arr1)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
Motor_Swap_Nvic_Init();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 |RCC_APB1Periph_TIM2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
TIM_TimeBaseStructure.TIM_Period = arr1; //éèÖÃÔúÏÂò»¸ö¸üDÂê¼t×°èë»î¶ˉμÄ×Ô¶ˉÖØ×°ÔؼÄ′æÆ÷ÖüÆúμÄÖμ
TIM_TimeBaseStructure.TIM_Prescaler =7; //éèÖÃóÃà′×÷ÎaTIMxê±ÖóÆμÂê3yêyμÄÔ¤·ÖÆμÖμ
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //Ñ¡Ôñ¶¨ê±Æ÷Ä£ê½:TIMÂö3å¿í¶èμ÷ÖÆÄ£ê½2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±è½Ïêä3öê1Äü
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //êä3ö¼«DÔ:TIMêä3ö±è½Ï¼«DÔ¸ß
TIM_OC1Init(TIM3, &TIM_OCInitStructure); //¸ù¾YTÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèTIM3 OC2
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); //ê1ÄüTIM3ÔúCCR2éÏμÄԤװÔؼÄ′æÆ÷
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); //ê1ÄüTIM3ÔúCCR2éÏμÄԤװÔؼÄ′æÆ÷
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_SetCompare1(TIM3,1000);
TIM_SetCompare2(TIM3,1000);
TIM_SetCompare3(TIM3,1000);
TIM_SetCompare4(TIM3,1000);
TIM_CCxCmd(TIM3,TIM_Channel_2 ,DISABLE);
TIM_CCxCmd(TIM3,TIM_Channel_3 ,DISABLE);
TIM_CCxCmd(TIM3,TIM_Channel_4 ,DISABLE);
TIM_Cmd(TIM3, ENABLE); //ê1ÄüTIM3
}
|
|