在线时间1 小时
UID273821
ST金币0
蝴蝶豆0
注册时间2011-3-30
新手上路
- 最后登录
- 2019-8-30
|
a0a.1 0b0c
用TIM4输出的PWM波形不能自动修改周期,仿真看到TIM4_ARR的值已经修改,但是PWM周期仍然是原来初始化时的值,请教是怎么回事?程序如下:
void pwm_tim_configuration (void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); //在开启时钟里一定要打开TIM2的时钟
TIM_TimeBaseStructure.TIM_Period = 200; //设定的最大计数值7199,最大计数值是0xffff
TIM_TimeBaseStructure.TIM_Prescaler = 11; //分频9999
TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 时钟分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //计数方向向上计数
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
}
void pwm_configuration (void)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 75;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC3Init (TIM4,&TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM4,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM4,ENABLE);
TIM_Cmd(TIM4,ENABLE);
}
主程序修改频率程序:
TIM_SetAutoreload(TIM4,50*Rx_Idx);
TIM_SetCompare3(TIM4,50);
程序中没有使用中断,也没有判断更新标志,主程序有2MS时钟控制循环执行,每2MS执行一次修改占空比和周期的值, |
|