}
}
case 5: if((huoer1==1)&&(huoer3==0)) PWM1_VAL=500; else PWM1_VAL=900; if((huoer1==0)&&(huoer2==1)) PWM2_VAL=500; else PWM2_VAL=900; if((huoer2==0)&&(huoer3==1)) PWM3_VAL=500; else PWM3_VAL=900; if((huoer1==0)&&(huoer3==1)) PWM4_VAL=500; else PWM4_VAL=900; if((huoer1==1)&&(huoer2==0)) PWM5_VAL=500; else PWM5_VAL=900; if((huoer2==1)&&(huoer3==0)) PWM6_VAL=500; else PWM6_VAL=900; break; case 6: if((huoer1==1)&&(huoer3==0)) PWM1_VAL=550; else PWM1_VAL=900; if((huoer1==0)&&(huoer2==1)) PWM2_VAL=550; else PWM2_VAL=900; if((huoer2==0)&&(huoer3==1)) PWM3_VAL=550; else PWM3_VAL=900; if((huoer1==0)&&(huoer3==1)) PWM4_VAL=550; else PWM4_VAL=900; if((huoer1==1)&&(huoer2==0)) PWM5_VAL=550; else PWM5_VAL=900; if((huoer2==1)&&(huoer3==0)) PWM6_VAL=550; else PWM6_VAL=900; break;
case 7: if((huoer1==1)&&(huoer3==0)) PWM1_VAL=600; else PWM1_VAL=900; if((huoer1==0)&&(huoer2==1)) PWM2_VAL=600; else PWM2_VAL=900; if((huoer2==0)&&(huoer3==1)) PWM3_VAL=600; else PWM3_VAL=900; if((huoer1==0)&&(huoer3==1)) PWM4_VAL=600; else PWM4_VAL=900; if((huoer1==1)&&(huoer2==0)) PWM5_VAL=600; else PWM5_VAL=900; if((huoer2==1)&&(huoer3==0)) PWM6_VAL=600; else PWM6_VAL=900; break; }
4. 系统软件仿真
根据已知条件,利用keil4进行软件仿真,这里前提是假设霍尔传感器的三个值huoer1,huoer2,huoer3为别为0、1、0,然后分别假设flag的值为1 和7 ,仿真可以得到GPIOA6的PWM波形如下,这样,可以看出程序PWM脉宽进行了调整,但是,在实际的过程中,应根据电动车的速度,适当的设置系统的频率等参数。