STM32定时器 TIM3之PWM输出

Posted beiyhs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32定时器 TIM3之PWM输出相关的知识,希望对你有一定的参考价值。

void GPIO_TimPWM(void)

 GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
GPIO_Init(GPIOA, &GPIO_InitStructure);


void Timer3_Configuration(void)

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 TIM_OCInitTypeDef TIM_OCInitStructure;
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
 TIM_TimeBaseStructure.TIM_Period = 1000-1;
 TIM_TimeBaseStructure.TIM_Prescaler =48-1;
 TIM_TimeBaseStructure.TIM_ClockDivision = 0x00;
 TIM_TimeBaseStructure.TIM_CounterMode =  TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM3, DISABLE);
 TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
 TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
 TIM_OCInitStructure.TIM_OutputState =   TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 500-1;
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
 TIM_OC2Init(TIM3, &TIM_OCInitStructure);
 TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
 TIM_CtrlPWMOutputs(TIM3,ENABLE);
 TIM_Cmd(TIM3, ENABLE);


以上是关于STM32定时器 TIM3之PWM输出的主要内容,如果未能解决你的问题,请参考以下文章

STM32 通用定时输出PWM

STM32 PWM设定输出

STM32之呼吸灯实验

STM32F103ZET6 用定时器级联方式输出特定数目的PWM(转载)

STM32通用定时器PWM输出

STM32F103ZET6 PWM输出