码迷,mamicode.com
首页 > 其他好文 > 详细

STM32定时器 TIM3之PWM输出

时间:2019-08-25 01:32:14      阅读:637      评论:0      收藏:0      [点我收藏+]

标签:scale   polar   gdi   pre   bit   ocp   定时   map   gpio   

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输出

标签:scale   polar   gdi   pre   bit   ocp   定时   map   gpio   

原文地址:https://www.cnblogs.com/beiyhs/p/11406535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!