TA的每日心情 | 难过 2018-6-11 16:37 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
|
在stm32高级定时器互补输出时,只能输出channel3的互补PWM,而channel1和channel2的互补输出波形与channel3N一样,为什么会这样呢?
/******PA8 ——TIM1_CH1 PB13 ——TIM1_CH1N
PA9 ——TIM1_CH2 PB14 ——TIM1_CH2N
PA10——TIM1_CH3 PB15 ——TIM1_CH3N *****/
static void TIM1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
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_Pin_15;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
static void TIM1_Mode_Config(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM1_BDTRInitStructure;
//void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
TIM_DeInit(TIM1); // TIM1_DeInit();
TIM_TimeBaseStructure.TIM_Period = arr-1;
TIM_TimeBaseStructure.TIM_Prescaler = psc;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1; // TIM_CounterMode_Up
// TIM_TimeBaseStructure.TIM_RepetitionCounter = TIM_RepetitionCounter_Reset_Mask;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
//void TIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 2400 ;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState =TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_OC2Init(TIM1,&TIM_OCInitStructure); //与OC1、2、3的排放顺序无关
TIM_OC3Init(TIM1,&TIM_OCInitStructure); //只有3通道有互补输出,1、2通道的互补输出就是3通道的互补输出,为什么会这样???
TIM_CtrlPWMOutputs(TIM1,ENABLE);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
//void TIM_BDTRConfig(TIM_TypeDef* TIMx, TIM_BDTRInitTypeDef *TIM_BDTRInitStruct)
TIM_BDTRStructInit(&TIM1_BDTRInitStructure); //缺省值(一般为0)必须要有,为了保证寄存器的值不是上电随机数
TIM1_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM1_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM1_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM1_BDTRInitStructure.TIM_DeadTime = 0x14;
TIM1_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
TIM1_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
TIM_BDTRConfig(TIM1,&TIM1_BDTRInitStructure);
// TIM1->CCER |= 0X00000555;
// TIM_CCPreloadControl(TIM1,ENABLE);
// TIM_Cmd(TIM1,ENABLE);
// TIM_CtrlPWMOutputs(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE); //主输出使能,开启OC和OCN输出!!
TIM_ARRPreloadConfig(TIM1, ENABLE); //使能TIMx在ARR上的重装载寄存器
TIM_Cmd(TIM1, ENABLE);
// TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable) ;
}
/****************************************************************************/
void TIM1_PWM_Init(void)
{
// SectionN(290,168,133); // int16_t U_alpha,int16_t U_beta,uint16_t Ts
TIM1_GPIO_Config() ;
TIM1_Mode_Config(1799,0); //u16 arr,u16 psc 72M/(7199+1)=10KHz, (1/10K)*(499+1)=50ms
}
|
-
|