大家好!Pwm_out.c文件[code=cpp]static void TIM1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* TIM3 clock enable */
//PCLK1经过2倍频后作为TIM3的时钟源等于72MHz
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* GPIOA and GPIOB clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // | RCC_APB2Periph_AFIO
/*GPIOA Configuration: TIM3 channel 1 and 2 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;//GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // 复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
static void TIM1_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/*PWM信号电平跳变值*/
u16 CCR1_Val=1250;
u16 CCR2_Val=1250;
u16 CCR3_Val=1250;
u16 CCR4_Val=125;
/*Time base cofiguration*/
//当定时器从0计数到999,即为1000次,为一个定时周期
TIM_TimeBaseStructure.TIM_Period=0x4e1f; //1799
//是指预分频:不预分频,即为36MHz
TIM_TimeBaseStructure.TIM_Prescaler=0x47; //0x0320
// TIM_TimeBaseStructure.TIM_Prescaler = 0; //设置预分频:不预分频,即为72MHz
TIM_TimeBaseStructure.TIM_ClockDivision=0;//设置时钟分频系数:不分频 TIM_CKD_DIV4
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//向上技术模式
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
/*PWM1 Mode configuration:Channel1*/
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;//配置为PWM模式1
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
// TIM_OCInitStructure.TIM_OutputState=TIM_OutputNState_Enable;
//设置跳变值,当计数器计到这个值时,电平发生跳变
TIM_OCInitStructure.TIM_Pulse=CCR1_Val;
//当定时器计数值小于CCR1_Val时为高电平
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
// TIM_OCInitStructure.TIM_OCPolarity=TIM_OCNPolarity_High;
TIM_OC1Init(TIM1,&TIM_OCInitStructure);//使能通道1
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
/*PWM2 Mode configuration:Channel2*/
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
//设置通道2的电平跳变值,输出另外一个占空比的PWM
TIM_OCInitStructure.TIM_Pulse=CCR2_Val;
TIM_OC2Init(TIM1,&TIM_OCInitStructure);//使能通道2
TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
/*PWM3 Mode configuration:Channel3*/
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
//设置通道3的电平跳变值,输出另外一个占空比的PWM
TIM_OCInitStructure.TIM_Pulse=CCR3_Val;
TIM_OC3Init(TIM1,&TIM_OCInitStructure);//使能通道3
TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);
/*PWM4 Mode configuration:Channel4*/
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
//设置通道4的电平跳变值,输出另外一个占空比的PWM
TIM_OCInitStructure.TIM_Pulse=CCR4_Val;
TIM_OC4Init(TIM1,&TIM_OCInitStructure);//使能通道4
TIM_OC4PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1,ENABLE);
//TIM2 enable counter
TIM_Cmd(TIM1,ENABLE);//使能定时器3
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}[/code]就是这样配置的,用软件仿真完全可以,但是用示波器就只能测出PA11 引脚的波形,调了老长时间了,求高手指点啊 |