工业控制
有幸能从报废的机器的光驱中拆除几个电机,大概是像下方图片中那样的。 但是这个电机只有四根外接的引脚,之前对不仅电机不是很懂,这两天通过查阅资料,了解到这个电机被称为两相双极性步进电机。
在此大概叙述下两相双极性电机的工作原理。 如下图所示,步进电机只有两相(即两组定子),双极性代表两个定子缠绕的线圈可以两个方向通电。
简单用图片表示下90度两相双极性步进电机转一圈的过程。 1表示相1正向通电,1~表示相1方向通电。
上面只是简单叙述了下两相双极性步进电机的工作原理,下面进入正题,使用proteus进行仿真Arduino来控制电机。
仿真:使用L298(U3)驱动四线两相双极性步进电机。
代码:MotorTwo为两相双极性电机驱动。
/* Main.ino file generated by New Project wizard * * Created: Thu Sep 5 2013 * Processor: ATmega328P * Compiler: Arduino AVR */#defineLED ( 13 )#defineMOTOR_PIN0 ( 0 )#defineMOTOR_PIN1 ( 1 )#defineMOTOR_PIN2 ( 2 )#defineMOTOR_PIN3 ( 3 )#defineMOTOR_PIN4 ( 4 )#defineMOTOR_PIN5 ( 5 )#defineMOTOR_PIN6 ( 6 )#defineMOTOR_PIN7 ( 7 )#defineMOTOR_ENA ( 8 )#defineMOTOR_ENB ( 9 )voidsetup(){// put your setup code here, to run once:pinMode( LED, OUTPUT ); pinMode( MOTOR_PIN0, OUTPUT ); pinMode( MOTOR_PIN1, OUTPUT ); pinMode( MOTOR_PIN2, OUTPUT ); pinMode( MOTOR_PIN3, OUTPUT ); pinMode( MOTOR_PIN4, OUTPUT ); pinMode( MOTOR_PIN5, OUTPUT ); pinMode( MOTOR_PIN6, OUTPUT ); pinMode( MOTOR_PIN7, OUTPUT ); pinMode( MOTOR_ENA, OUTPUT ); pinMode( MOTOR_ENB, OUTPUT ); }voidMotorOne(){staticinti =3;switch( i-- ) {case0: digitalWrite( MOTOR_PIN0, HIGH ); digitalWrite( MOTOR_PIN1, LOW ); digitalWrite( MOTOR_PIN2, LOW ); digitalWrite( MOTOR_PIN3, LOW );break;case1: digitalWrite( MOTOR_PIN0, LOW ); digitalWrite( MOTOR_PIN1, HIGH ); digitalWrite( MOTOR_PIN2, LOW ); digitalWrite( MOTOR_PIN3, LOW );break;case2: digitalWrite( MOTOR_PIN0, LOW ); digitalWrite( MOTOR_PIN1, LOW ); digitalWrite( MOTOR_PIN2, HIGH ); digitalWrite( MOTOR_PIN3, LOW );break;case3: digitalWrite( MOTOR_PIN0, LOW ); digitalWrite( MOTOR_PIN1, LOW ); digitalWrite( MOTOR_PIN2, LOW ); digitalWrite( MOTOR_PIN3, HIGH );break;default:break; }if(0> i ) i =3; }voidLedLight(){staticinti =0;if(0== i++ ) digitalWrite( LED, HIGH );elsedigitalWrite( LED, LOW );if(2<= i ) i =0; }voidMotorTwo(){staticinti =0;switch( i++ ) {case0: digitalWrite( MOTOR_PIN4, HIGH ); digitalWrite( MOTOR_PIN5, LOW ); digitalWrite( MOTOR_PIN6, LOW ); digitalWrite( MOTOR_PIN7, LOW );break;case1: digitalWrite( MOTOR_PIN4, LOW ); digitalWrite( MOTOR_PIN5, HIGH ); digitalWrite( MOTOR_PIN6, LOW ); digitalWrite( MOTOR_PIN7, LOW );break;case2: digitalWrite( MOTOR_PIN4, LOW ); digitalWrite( MOTOR_PIN5, LOW ); digitalWrite( MOTOR_PIN6, HIGH ); digitalWrite( MOTOR_PIN7, LOW );break;case3: digitalWrite( MOTOR_PIN4, LOW ); digitalWrite( MOTOR_PIN5, LOW ); digitalWrite( MOTOR_PIN6, LOW ); digitalWrite( MOTOR_PIN7, HIGH );break;default:break; }if(4<= i ) i =0; }voidloop(){// put your main code here, to run repeatedly:MotorOne(); LedLight(); MotorTwo(); delay(500); }
全部0条评论
快来发表一下你的评论吧 !