想产生两对带死区互补对称的PWM控制逆变全桥的四个管子,TIM1_CH1(PA8)和TIM1_CH1N(PB13),TIM1_CH2(PA9)和TIM1_CH2N(PB14),请问初始化设置用库的结构体定义一个变量还是两个变量呢?
例如:
1、 GPIO_InitTypeDef GPIO_InitStructure,GPIO_InitStructure1;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure,TIM_TimeBaseStructure1;
TIM_OCInitTypeDef TIM_OCInitStructure,TIM_OCInitStructure1;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure,TIM_BDTRInitStructure1;其中 GPIO_InitStructure、 TIM_TimeBaseStructure、TIM_OCInitStructure、TIM_BDTRInitStructure用于设置第一对PWM(TIM1_CH1(PA8)和TIM1_CH1N(PB13),)
GPIO_InitStructure1、 TIM_TimeBaseStructure1、TIM_OCInitStructure1、TIM_BDTRInitStructure1用于设置第二对PWM(TIM1_CH2(PA9)和TIM1_CH2N(PB14),)
2、 GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
其中GPIO_InitStructure、 TIM_TimeBaseStructure、TIM_OCInitStructure、TIM_BDTRInitStructure用于设置两对PWM;如果这样那就不能各自设置其占空比了?
请高手帮忙解答,是按那种方式进行定义设置呢?谢谢!
此帖出自
小平头技术问答
谢谢你的回复,明白了一些,我修改下自己的设置程序,可否帮我看看是否正确?谢谢
//PWM1 for inverter (PA8---TIM1_CH1(pin29),PB13---TIM1_CH1N(pin26))
//PWM2 for inverter (PA9---TIM1_CH2(pin30),PB14---TIM1_CH2N(pin27))
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure,TIM_OCInitStructure1;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure,TIM_BDTRInitStructure1;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; //PA.8 and PA.9 for TM1_CH1 and TM1_CH2 pin config
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14; //PB.13 and PB.14 for TIM1_CH1N and TIM1_CH2N pin config
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
//TIM base config
TIM_DeInit(TIM1); //¸´Î»TIM1¶¨Ê±Æ÷
TIM_TimeBaseStructure.TIM_Period=1200-1; //×Ô¶¯ÖØ×°ÔؼĴæÆ÷µÄÖµ 72M/1200 = 60k(ƵÂÊ)
TIM_TimeBaseStructure.TIM_Prescaler = 0; //ʱÖÓÔ¤·ÖƵÊý 72M/(0+1) = 72M
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //²ÉÑù·ÖƵ
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòÉϼÆÊý
TIM_TimeBaseStructure.TIM_RepetitionCounter=0; //Öظ´¼Ä´æÆ÷£¬ÓÃÓÚ×Ô¶¯¸üÐÂPWMÕ¼¿Õ±È
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
//PWM1输出配置
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÉèÖÃΪpwm1Êä³öģʽ
// TIM_OCInitStructure.TIM_Pulse = 3000-1; //ÉèÖÃÕ¼¿Õ±Èʱ¼ä (¸ù¾ÝµçÁ÷ÄÚ»·¼ÆËãµÄÕ¼¿Õ±È½øÐи³Öµ)
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High; //ÉèÖÃÊä³ö¼«ÐÔ
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable; //ʹÄܸÃͨµÀÊä³ö
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //ÉèÖû¥²¹¶ËÊä³ö¼«ÐÔ
TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;//ʹÄÜ»¥²¹Êä³ö
TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Reset; //ËÀÇøºóÊä³ö״̬
TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCNIdleState_Reset; //ËÀÇøºó»¥²¹¶ËÊä³ö״̬
TIM_OC1Init(TIM1,&TIM_OCInitStructure); //°´ÕÕÖ¸¶¨²ÎÊý³õʼ»¯
TIM_BDTRInitStructure.TIM_DeadTime = 0x24; //ÉèÖÃËÀÇøʱ¼ä1us
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;//
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
//PWM2输出配置
TIM_OCInitStructure1.TIM_OCMode = TIM_OCMode_PWM1; //ÉèÖÃΪpwm1Êä³öģʽ
// TIM_OCInitStructure1.TIM_Pulse = 3000-1; //ÉèÖÃÕ¼¿Õ±Èʱ¼ä (¸ù¾ÝµçÁ÷ÄÚ»·¼ÆËãµÄÕ¼¿Õ±È½øÐи³Öµ)
TIM_OCInitStructure1.TIM_OCPolarity=TIM_OCPolarity_High; //ÉèÖÃÊä³ö¼«ÐÔ
TIM_OCInitStructure1.TIM_OutputState=TIM_OutputState_Enable; //ʹÄܸÃͨµÀÊä³ö
TIM_OCInitStructure1.TIM_OCNPolarity = TIM_OCNPolarity_High; //ÉèÖû¥²¹¶ËÊä³ö¼«ÐÔ
TIM_OCInitStructure1.TIM_OutputNState=TIM_OutputNState_Enable;//ʹÄÜ»¥²¹Êä³ö
TIM_OCInitStructure1.TIM_OCIdleState=TIM_OCIdleState_Reset; //ËÀÇøºóÊä³ö״̬
TIM_OCInitStructure1.TIM_OCNIdleState=TIM_OCNIdleState_Reset; //ËÀÇøºó»¥²¹¶ËÊä³ö״̬
TIM_OC1Init(TIM1,&TIM_OCInitStructure1); //°´ÕÕÖ¸¶¨²ÎÊý³õʼ»¯
TIM_BDTRInitStructure1.TIM_DeadTime = 0x24; //ÉèÖÃËÀÇøʱ¼ä1us
TIM_BDTRInitStructure1.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;//
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure1);
TIM_Cmd(TIM1,ENABLE); //´ò¿ªTIM1
TIM_CtrlPWMOutputs(TIM1, ENABLE); //PWMÊä³öʹÄÜ
好的,谢谢你的指导,等实验后再告诉你结果。
一周热门 更多>