我使用STM32 nucleo开发板,使用tiM3 CH4输出PWM方波,发现波形变形,整个工程只有这个PWM输出的功能,其他外设都没开启。工程使用的是标准库。请大神支个招。
void TIM_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_BDTRInitTypeDef TIM_BDTRInitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//GPIO_Mode_AF GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, GPIO_InitStructure); GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_10); RCC_APB1PeriphClockCmd(RCC_APB1ENR_TIM3EN,ENABLE); TIM_TimeBaseInitStructure.TIM_Prescaler = 71; TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStructure.TIM_Period = 499; TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0x00; TIM_TimeBaseInit(TIM3, TIM_TimeBaseInitStructure); TIM_OCStructInit( TIM_OCInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; TIM_OCInitStructure.TIM_Pulse =250; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OC4Init(TIM3, TIM_OCInitStructure); TIM_Cmd(TIM3,ENABLE); TIM_CtrlPWMOutputs(TIM3,ENABLE);}
|