翻转模式差生PWM,为何进入不了NVIC中断,因为产生的频率和占空比没变化

2019-07-21 06:44发布


翻转模式差生PWM,为何进入不了NVIC中断,因为产生的频率和占空比没变化,我设置的占空比是不一样的。

static void OCToggle_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;// | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//¶¨Ê±Æ÷¸÷ͨµÀÒý½ÅÅäÖóɸ´ÓÃÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*************************************************************
Function : OCToggle_TIM3_Init
Description: Êä³ö±È½Ï·­×ªÄ£Ê½¶¨Ê±Æ÷2³õʼ»¯
Input : none
return : none
*************************************************************/
static void OCToggle_TIM3_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//TIM3ʱÖÓʹÄÜ

TIM_TimeBaseStructure.TIM_Period = 65535;//¶¨Ê±Æ÷¼ÆÊýÖÜÆÚ
TIM_TimeBaseStructure.TIM_Prescaler = 47;//Ô¤·ÖƵ
TIM_TimeBaseStructure.TIM_ClockDivision = 1 - 1;//ʱÖÓ²»·ÖƵ
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//ÏòÉϼÆÊý
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);//³õʼ»¯¶¨Ê±Æ÷

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;//Êä³ö±È½ÏÖ÷¶¯Ä£Ê½
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;//ÓÐЧµçƽΪ¸ßµçƽ

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//Êä³öʹÄÜ
TIM_OCInitStructure.TIM_Pulse = 200;//ÉèÖñȽÏÖµ£¨Ìø±äÖµ£©
TIM_OC1Init(TIM3, &TIM_OCInitStructure);//³õʼ»¯Êä³ö±È½Ï¼Ä´æÆ÷
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);//¹Ø±ÕԤװÔØ


TIM_Cmd(TIM3, ENABLE);//´ò¿ª¶¨Ê±Æ÷2
TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);//Çå³ýÖжϱêÖ¾

}
/*************************************************************
Function : OCToggle_Int_Init
Description: Êä³ö±È½Ï·­×ªÄ£Ê½Öжϳõʼ»¯
Input : none
return : none
*************************************************************/
static void OCToggle_Int_Init(void)
{
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*************************************************************
Function : OCToggle_Init
Description: Êä³ö±È½Ï·­×ªÄ£Ê½³õʼ»¯
Input : none
return : none
*************************************************************/
void OCToggle_Init(void)
{
OCToggle_GPIO_Init();
OCToggle_TIM2_Init();
OCToggle_Int_Init();
}
/*************************************************************
Function : TIM2_IRQHandler
Description: ¶¨Ê±Æ÷2ÖжϷþÎñ³ÌÐò
Input : none
return : none
*************************************************************/
void TIM3_IRQHandler(void)
{
static u8 oc1_sig = 0 ;
u16 capture = 0;
if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)//??1???????
{
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);//?????
if (oc1_sig)
{
capture = TIM_GetCapture1(TIM3);
TIM_SetCompare1(TIM3, capture + 200);//???????
  oc1_sig = 0;
}
else
{
capture = TIM_GetCapture1(TIM3);
TIM_SetCompare1(TIM3, capture + 800);//???????
  oc1_sig = 1;
}
}
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。