F407调用库函数,是不是不能用同一个定时器输出两路周期相同,占空比相同,相位相差180°的PWM

2019-07-20 01:03发布

STM32F407调用库函数,是不是不能用同一个定时器输出两路周期相同,占空比相同,相位相差180°的PWM.下面是我的程序,我的比较直不同,但是只能输出相同的两路PWM,请问各位大佬这什么情况。


#include"pwm.h"
#include"stm32f4xx.h"
void PWM_Init(u16 arr,u16 psc){
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//NVIC_InitTypeDef NVIC_InitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //ʹÄ&UumlAʱÖÓ
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);  //ʹÄÜTIM3ʱÖÓ

GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_TIM5);//PA2¸´ÓÃΪTIM5
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_TIM5);//PA3¸´ÓÃΪTIM5

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;//PA2£¬3,
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_PinSource2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);


TIM_TimeBaseStructure.TIM_Period=arr;     //ԤװÔØÖµ
TIM_TimeBaseStructure.TIM_Prescaler=psc;   //·ÖƵϵÊý
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_CenterAligned3;     //ÖÐÑë¶ÔÆë¼ÆÊý

TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
TIM_ITConfig(TIM5,TIM_IT_Update,ENABLE);


  

TIM_OCInitStruct.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OCNPolarity=TIM_OCPolarity_Low;
TIM_OCInitStruct.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_Pulse=470;

TIM_OCInitStruct.TIM_OCMode=TIM_OCMode_PWM2; //&Ecirc;&auml;&sup3;&ouml;&Auml;&pound;&Ecirc;&frac12;&pound;&ordmWM1&Auml;&pound;&Ecirc;&frac12;&pound;&ordm;CNT<CC&Ecirc;±&pound;&not;&Oacute;&ETH;&ETH;§
TIM_OCInitStruct.TIM_OCNPolarity=TIM_OCPolarity_Low;       //&frac14;&laquo;&ETH;&Ocirc;
TIM_OCInitStruct.TIM_OutputState=TIM_OutputState_Enable;        //&Ecirc;&auml;&sup3;&ouml;&Ecirc;&sup1;&Auml;&Uuml;
TIM_OCInitStruct.TIM_Pulse=1210;        //±&Egrave;&frac12;&Iuml;&micro;&Auml;&Ouml;&micro;CC

TIM_OC2Init(TIM5,&TIM_OCInitStruct);
TIM_OC3Init(TIM5,&TIM_OCInitStruct);

TIM_OC2PreloadConfig(TIM5,TIM_OCPreload_Enable);//&Ecirc;&sup1;&Auml;&Uuml;CCR2&Eacute;&Iuml;&micro;&Auml;&Ocirc;¤×°&Ocirc;&Oslash;
TIM_OC3PreloadConfig(TIM5,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM5,ENABLE);//arr&micro;&Auml;&Ocirc;¤×°&Ocirc;&Oslash;&Ecirc;&sup1;&Auml;&Uuml;
TIM_Cmd(TIM5,ENABLE);       //&Ecirc;&sup1;&Auml;&Uuml;&para;¨&Ecirc;±&AElig;÷5
}


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