本帖最后由 houyawei 于 2024-1-24 17:32 编辑
使用6个PWM口,6个IO口驱动三个步进电机
第一步是初始化快速归零
第二步是慢慢反向旋转
- u16 motor_pwm1[48] = {354,374,394,400,410,400,394,374,
- 354,286,220,184,148,112,82,36,
- 512,476,430,400,364,328,292,226,
- 158,138,118,112,102,112,118,138,
- 158,226,292,328,364,400,430,476,
- 2,36,82,112,148,184,220,288,};
- unsigned char code motor_pwm2[48]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
-
- unsigned char code motor_pwm3[48]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
-
- u16 motor_pwm4[48] = {
- 354,286,220,184,148,112,82,36,//1
- 512,476,430,400,364,328,292,226,//2
- 158,138,118,112,102,112,118,138,//3
- 158,226,292,328,364,400,430,476,//4
- 2,36,82,112,148,184,220,288,//5
- 354,374,394,400,410,400,394,374,//6
- };
复制代码
- PWMA_CCR1H = (u8)(motor_pwm1[count] >> 8);//设置占空比时间
- PWMA_CCR1L = (u8)(motor_pwm1[count]);
- fule_m2=(bit)motor_pwm2[count];
- fule_m2=(bit)motor_pwm3[count];
- PWMA_CCR2H = (u8)(motor_pwm4[count] >> 8);//设置占空比时间
- PWMA_CCR2L = (u8)(motor_pwm4[count]);
-
- PWMA_CCR3H = (u8)(motor_pwm1[count] >> 8);//设置占空比时间
- PWMA_CCR3L = (u8)(motor_pwm1[count]);
- zs_m2=(bit)motor_pwm2[count];
- zs_m3=(bit)motor_pwm3[count];
- PWMA_CCR4H = (u8)(motor_pwm4[count] >> 8);//设置占空比时间
- PWMA_CCR4L = (u8)(motor_pwm4[count]);
-
- PWMB_CCR5H = (u8)(motor_pwm1[a] >> 8);//设置占空比时间
- PWMB_CCR5L = (u8)(motor_pwm1[a]);
- water_m2=(bit)motor_pwm2[a];
- water_m3=(bit)motor_pwm3[a];
- PWMB_CCR6H = (u8)(motor_pwm4[a] >> 8);//设置占空比时间
- PWMB_CCR6L = (u8)(motor_pwm4[a]);
复制代码
|