//初始化 GPIO_Structinit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//GPIO_OType_OD;//GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//GPIO_PuPd_UP;//GPIO_PuPd_NOPULL
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_2);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_2); Period = 3199; //2014-8-27 PWM 频率 15K
MotorA.PWM_Freq = BLDC_PWM_Freq;
MotorA.TimerPeriod = Period;
Pluse = 0; //默认占空比30% // TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);//?????????????????????????
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;//TIM_CounterMode_CenterAligned1????????????????????????????
TIM_TimeBaseStructure.TIM_Period = Period;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;//0;//TIM_CKD_DIV2????????????????????????
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;//0; //REP_RATE???????????????????????????????
TIM_TimeBaseInit(BLDC_TIMER_NUM, &TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructure);
/* Channel 1, 2,3 and 4 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;//TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = Pluse; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //上桥使能状态
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;//下桥使能状态
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;//上桥引脚空闲状态
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;//下桥引脚空闲状态
TIM_OC1Init(BLDC_TIMER_NUM, &TIM_OCInitStructure);
TIM_OC2Init(BLDC_TIMER_NUM, &TIM_OCInitStructure);
TIM_OC3Init(BLDC_TIMER_NUM, &TIM_OCInitStructure);
//输出 TIM1->CCER = 0x18C9; // 0x18C9
TIM1->CCR2 = Period;//同时全部开启是为了换向补偿
TIM1->CCR1 = hTimePhA;//占空比
-
圈里面是输出的波形不是正常方波
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>