/*******************************************************
* 定时器产生2路互补的PWM波
* channel1 ,channel2 -->A.8, A.9
channel1N,channel2N-->B.13, B.14 (互补)
* TimerPeriod --> ×Ô¶ˉÖØ×°ÔØÖüÆúÖμ
* ChannelxPulse --> Õ¼¿ÕÖüÆúÖμ
******************************************************/
void TIM1_PWM_Init(u16 pfreq ,u16 psc) //pfreqÎa2»·ÖÆμê±μÄ
WMÆμÂ꣬pscÎaÔ¤·ÖÆμÖμ
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure; //êä3öí¨μàÅäÖÃ
TIM_BDTRInitTypeDef TIM_BDTRInitStructure; //ËàÇøoíé23μÅäÖÃ
TimerPeriod = (SystemCoreClock / pfreq) - 1; //×Ô¶ˉÖØ×°ÔØÖüÆúÖμ
/* ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100 */
Channel1Pulse = (u16)((u32)(50 * (TimerPeriod - 1)) / 100 ); //Õ¼¿Õ±è50%
Channel2Pulse = (u16)((u32)(50 * (TimerPeriod - 1)) / 100 ); //Õ¼¿Õ±è50%
/* ê1ÄüTIM1£¬GPIOA£¬GPIOB£¬GPIOE */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE, ENABLE);
/*channel1 ,channel2 -->A.8,A.9*
*channel1N,channel2N-->B.13,B.14*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* 3õê¼»ˉTIM1 */
TIM_TimeBaseStructure.TIM_Period = TimerPeriod; //éèÖÃÖØ×°ÔØÖüÆúÖμ
TIM_TimeBaseStructure.TIM_Prescaler = psc; //éèÖÃÔ¤·ÖÆμÖμ
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //ê±Öó·ÖÆμòò×󣬽öóëêäèë2¶»ñóD1Ø£¨¶¨ê±Æ÷óëÂË2¨Æ÷μÄÆμÂê±è£©
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//TIMÏòéϼÆêyÄ£ê½
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; //Öظ′òç3öÖD¶Ï
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //3õê¼»ˉ¶¨ê±Æ÷»ù±¾ÅäÖÃ
/* Channel_1 TIM_OCMode_PWM1Ä£ê½ */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÔúÏòéϼÆêyê±£¬ò»μ©TIMx_CNT<TIMx_CCR1ê±í¨μà1ÎaóDD§μçƽ
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±è½Ïêä3öê1Äü
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //PWM»¥21êä3öê1Äü
TIM_OCInitStructure.TIM_Pulse = Channel1Pulse; //Õ¼¿Õ±è = TIM_Pulse/TIM_Period;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //óDD§μçƽÎa¸ßμçƽ
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //»¥21PWM¼«DÔ
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; //êä3ö¿ÕÏD×′ì¬
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset; //PWM»¥21êä3ö¿ÕÏD×′ì¬
TIM_OC1Init(TIM1, &TIM_OCInitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèTIM1 OC1
/* Channel_2 TIM_OCMode_PWM1Ä£ê½ */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÔúÏòéϼÆêyê±£¬ò»μ©TIMx_CNT>TIMx_CCR1ê±í¨μà1ÎaóDD§μçƽ
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±è½Ïêä3öê1Äü
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //PWM»¥21êä3öê1Äü
TIM_OCInitStructure.TIM_Pulse = Channel2Pulse; //Õ¼¿Õ±è = TIM_Pulse/TIM_Period;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //óDD§μçƽÎa¸ßμçƽ
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //»¥21PWM¼«DÔ
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; //êä3ö¿ÕÏD×′ì¬
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset; //PWM»¥21êä3ö¿ÕÏD×′ì¬
TIM_OC2Init(TIM1, &TIM_OCInitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèTIM1 OC2
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); //ê1ÄüTIM3ÔúCCR1éÏμÄԤװÔؼÄ′æÆ÷
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable); //ê1ÄüTIM3ÔúCCR2éÏμÄԤװÔؼÄ′æÆ÷
/*ËàÇøoíé23μ1|ÄüÅäÖÃ*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM_BDTRInitStructure.TIM_DeadTime = 0x2F; //éèÖÃTIM1_BDTRμÄDTG[7:0]
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_Cmd(TIM1, ENABLE); //ê1ÄüTIM1
TIM_CtrlPWMOutputs(TIM1,ENABLE); //PWMêä3öê1Äü
}
求解哦,以上程序的意思是不是A8和A9输出相同信号,而B13和B14也输出相同信号?(不知道为什么后面的注释成乱码了)
另外,图下部分的IR2110驱动,求解是不是HLN端入口的信号进去由HO端口输出?从图上来说就是A8控制Q1,A9控制Q3?
麻烦各位大佬了!!
一周热门 更多>