void TIM_Configuration(void)//TIM初始化函数 { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;//定时器初始化结构 TIM_OCInitTypeDef TIM_OCInitStructure;//通道输出初始化结构
//TIM3初始化 TIM_DeInit(TIM2); TIM_TimeBaseStructure.TIM_Period = 719; //周期719 TIM_TimeBaseStructure.TIM_Prescaler = 999; //时钟分频 TIM_TimeBaseStructure.TIM_ClockDivision = 0; //时钟分割 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//模式 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //基本初始化 // TIM_ITConfig(TIM2, TIM_IT_CC4, ENABLE);//打开中断,中断需要这行代码 //TIM3通道初始化 TIM_OCStructInit(& TIM_OCInitStructure); //默认参数 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //工作状态,;//配置为PWM1模式 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //设定为输出,需要PWM输出才需要这行代码 TIM_OCInitStructure.TIM_Pulse = 800; //占空长度 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //高电平 TIM_OC4Init(TIM2, &TIM_OCInitStructure); //使用通道4 TIM_Cmd(TIM2, ENABLE); //启动TIM2 }
PA3输出的信号周期为5ms,单个周期内高电平持续时间为0.7ms
这时初始化部分,我想知道的是:使用哪条C语句(或者改变哪个已有的参数)可以改变PWM的占空比
谢谢!
|