高中生
最后登录1970-1-1
在线时间 小时
注册时间2014-5-8
|
完全模仿库开发指南的例子,奇怪的是就PWM1、5、8这几个定时器不能输出PWM波形,使用的是软件仿真。求指导,以下定时器5的输出通道1的程序,对应引脚PA.0
GPIO_InitTypeDef GPIO_InitStructure ;
/*GPIOê±Öó*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_8;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
TIM_TimeBaseInitTypeDef TIM_TimebaseInitStructure ;
TIM_OCInitTypeDef TIM_OCInitStructure ;
/*TIM ê±Öó¿aÆô*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);
/*TIM»ù±¾3õê¼»ˉ*/
TIM_TimebaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up ;
TIM_TimebaseInitStructure.TIM_Prescaler = 0 ;
TIM_TimebaseInitStructure.TIM_Period = 999 ;
TIM_TimebaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
TIM_TimeBaseInit(TIM5,&TIM_TimebaseInitStructure);
/*TIMêä3ö3õê¼»ˉ*/
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2 ;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High ;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable ;
TIM_OCInitStructure.TIM_Pulse = 250 ;
TIM_OC1Init(TIM5,&TIM_OCInitStructure);
/*ÖØÔؼÆêy*/
TIM_OC1PreloadConfig(TIM5,TIM_OCPreload_Enable) ;
TIM_ARRPreloadConfig(TIM5,ENABLE);
/*ê1Äü¶¨ê±Æ÷*/
TIM_Cmd(TIM5,ENABLE);
|
|