大学生
最后登录1970-1-1
在线时间 小时
注册时间2017-7-24
|
最近在研究步进电机,想使用stm32的通用定时器输出四路占空比为37.5%,相邻两路的相位差为90度的四路pwm波来控制一个小的步进电机,用了火哥那个输出四路占空比不同的历程改了改,改后相位差可以相差90度了,但是占空比却只能是50%不能更改了。- void GENERAL_TIM_Mode_Config(void)
- {
- // 开启定时器时钟,即内部时钟CK_INT=72M
- GENERAL_TIM_APBxClock_FUN(GENERAL_TIM_CLK,ENABLE);
- /*--------------------时基结构体初始化-------------------------*/
- // 配置周期,这里配置为100K
-
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_TimeBaseStructure.TIM_Period=19;
- TIM_TimeBaseStructure.TIM_Prescaler= 71;
- TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
- TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
- TIM_TimeBaseInit(GENERAL_TIM, &TIM_TimeBaseStructure);
- // 相位的配置
- uint16_t CCR1_Val = 0;
- uint16_t CCR2_Val = 10;
- uint16_t CCR3_Val = 0;
- uint16_t CCR4_Val = 10;
-
- TIM_OCInitTypeDef TIM_OCInitStructure;
- // 配置为翻转模式
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- // 输出通道电平极性配置
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
-
- // 输出比较通道 1
- TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
- TIM_OC1Init(GENERAL_TIM, &TIM_OCInitStructure);
- TIM_OC1PreloadConfig(GENERAL_TIM, TIM_OCPreload_Enable);
-
- // 输出比较通道 2
- TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
- TIM_OC2Init(GENERAL_TIM, &TIM_OCInitStructure);
- TIM_OC2PreloadConfig(GENERAL_TIM, TIM_OCPreload_Enable);
-
- // 输出比较通道 3
- TIM_OCInitStructure.TIM_Pulse = CCR3_Val;
- TIM_OC3Init(GENERAL_TIM, &TIM_OCInitStructure);
- TIM_OC3PreloadConfig(GENERAL_TIM, TIM_OCPreload_Enable);
- //设置cc3p为1
- TIM_OC3PolarityConfig(GENERAL_TIM, TIM_OCPolarity_Low);
-
- // 输出比较通道 4
- TIM_OCInitStructure.TIM_Pulse = CCR4_Val;
- TIM_OC4Init(GENERAL_TIM, &TIM_OCInitStructure);
- TIM_OC4PreloadConfig(GENERAL_TIM, TIM_OCPreload_Enable);
- //设置cc4p为1
- TIM_OC4PolarityConfig(GENERAL_TIM, TIM_OCPolarity_Low);
-
- // 使能计数器
- TIM_Cmd(GENERAL_TIM, ENABLE);
- }
复制代码 请问各位使用这种方法更改相位差后,占空比怎么更改!
|
-
更改相位差是根据这个思路编写的!
|