最近还做了个小实验,无刷电机驱动,这个电机的的驱动方法还真的比较复杂,不想直流电机 步进电机,给电平就能转,既要驱动电路保护驱动,还要程序上的事实电平转换驱动,结合起来还是不容易的。只是一直比较懒每次都是弄一半一半的, 这回终于把小实验做了。但还是开环的驱动程序。
为了做准确的做PWM 输出,PWM 端口控制必须要在程序中断中做出,而且要及时,指令过多 或判断过多都会影响pwm 的准确控制,
贴出51 做的一部分代码,虽然pwm 的输出效果还是比较不错的,占空比都能很好的控制准确,但示波器看出换相还是 存在很大的问题,看来也需要做入中断或另一种控制方式
void isr_t1(void) interrupt 1 using 1 { bit PWM_STATE; EA=0; TH0=0xFF; TL0=0xD2; IT_Count++; Conne_Count++; if(IT_Count<=Freq/10*Dutyfactor) PWM_STATE=L; else PWM_STATE=H; if(IT_Count>=Freq) {IT_Count=0;} /*------------------------------------------------- Control undown arm of the mosfet --------------------------------------------------*/ switch(PWM_Count & 0xE0) { case PWM_OUTA: PWM_A=PWM_STATE; PWM_B=L; PWM_C=L; _nop_();_nop_(); if(PWM_Count & MOSD_B) {PWM_D_A=L;PWM_D_B=H;PWM_D_C=L;} else if(PWM_Count & MOSD_C) {PWM_D_A=L;PWM_D_B=L;PWM_D_C=H;} else {PWM_D_A=L;PWM_D_B=L;PWM_D_C=L;} break; /*-------------------------------------------------*/ case PWM_OUTB: PWM_A=L; PWM_B=PWM_STATE; PWM_C=L; _nop_();_nop_(); if(PWM_Count & MOSD_C) {PWM_D_A=L;PWM_D_B=L;PWM_D_C=H;} else if(PWM_Count & MOSD_A) {PWM_D_A=H;PWM_D_B=L;PWM_D_C=L;} else {PWM_D_A=L;PWM_D_B=L;PWM_D_C=L;} break; /*--------------------------------------------------*/ case PWM_OUTC: PWM_A=L; PWM_B=L; PWM_C=PWM_STATE; _nop_();_nop_(); if(PWM_Count & MOSD_A) {PWM_D_A=H;PWM_D_B=L;PWM_D_C=L;} else if(PWM_Count & MOSD_B) {PWM_D_A=L;PWM_D_B=H;PWM_D_C=L;} else {PWM_D_A=L;PWM_D_B=L;PWM_D_C=L;} break; /*--------------------------------------------------*/ default : PWM_A=L;PWM_B=L;PWM_C=L; PWM_D_A=L;PWM_D_B=L;PWM_D_C=L; break; } /*--------------------end switch--------------------*/ EA=1; }