大家好!本人在调试TIM5-CH4;TIM8-CH2N两个通道产生PWM波的实验。但是TIM5-CH4可以输出正常,TIM3-CH3N的不行。下面是代码,希望大家看看,路过帮顶。是什么问题导致的呢? KEIL5.14 stm32F205标准库开发 64引脚 void Time3_Time5_Configuration(void) //TIM3,TIM5ûÓÐÓõ½ÖÐ¶Ï { uint16_t PrescalerValue = 0; GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; // TIM_BDTRInitTypeDef TIM_BDTRInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); //TIM8 CH3N RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //TIM_InternalClockConfig(TIM5); /* TIM8 CH2N */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 ; //motor2-EN PB14 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_TIM8); /* TIM5 CH3 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //motor1-en PA2 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM5); TIM_DeInit(TIM8); TIM_DeInit(TIM5); /* Time base configuration//133.333uS */ TIM_TimeBaseStructure.TIM_Period = 4000; TIM_TimeBaseStructure.TIM_Prescaler = 0; //Ô¤·ÖƵÊýÎÞ TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //ʱÖÓ²»·ÖƵ TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊý TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure); TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure); /* PWM1 Mode configuration:TIM3 Channel4 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //PWM1ΪÕý³£Õ¼¿Õ±Èģʽ¡£ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //ʹÄÜÊä³ö TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //ʹÄÜÊä³ö TIM_OCInitStructure.TIM_Pulse = 2000; //Õ¼¿Õ±ÈÉèÖà TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC2Init(TIM8, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM8, TIM_OCPreload_Enable); //CCR×Ô¶¯×°ÔØ¹Ø±Õ TIM_ARRPreloadConfig(TIM8, ENABLE);//ARRÖØÔØʹÄÜ /* PWM1 Mode configuration:TIM5 Channel3 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;//PWM1ΪÕý³£Õ¼¿Õ±Èģʽ¡£ // TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 2000; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OC3Init(TIM5, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM5, TIM_OCPreload_Enable); //CCR×Ô¶¯×°ÔØ¹Ø±Õ TIM_ARRPreloadConfig(TIM5, ENABLE);//ARRÖØÔØʹÄÜ TIM_Cmd(TIM8, ENABLE); TIM_CtrlPWMOutputs(TIM8, ENABLE); TIM_Cmd(TIM5, ENABLE); TIM_CtrlPWMOutputs(TIM5, ENABLE); 结果是TIM5有波形,Tim8的引脚上没有波形。不知道问题在哪里啊!搞了一天啦。哎 |
楼主你到底用的是TIM8还是TIM3呢? |
可以自己用STM32CubeMX进行配置,参考STM32CubeMX的配置进行更改。 |