![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
controller
Revision 0:8dc46da67c9f, committed 2016-11-01
- Comitter:
- IngmarLoohuis
- Date:
- Tue Nov 01 13:07:59 2016 +0000
- Commit message:
- Motor 3 controller
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Nov 01 13:07:59 2016 +0000 @@ -0,0 +1,125 @@ +// 28BYJ-48 stepper motor example +// showing how to control a unipolar stepper motor by mbed digital output ports. +// Tested on the Nucleo F103RB Board +// Based on http://www.geeetech.com/wiki/index.php/Stepper_Motor_5V_4-Phase_5-Wire_%26_ULN2003_Driver_Board_for_Arduino +// Using the ULN2003A Driver. + +#include "mbed.h" +Serial pc(USBTX,USBRX); +Ticker t0; +Ticker t7; + +volatile bool fn0_go = false; +void fn0_activate(){ fn0_go = true; }; //Activates the go−flag +volatile bool fn7_go = false; +void fn7_activate(){ fn7_go = true; }; //Activates the go−flag + +BusOut motor_out(D0, D1, D2, D3); // blue - pink - yellow - orange + +int up = 1; +int down = 0; + +int begin_step = 0; +int teller = 0; + +int motor3_direction = up; // direction + +void motor3_position() +{ + switch(begin_step) + { + case 0: motor_out = 0x1; break; // 0001 + case 1: motor_out = 0x3; break; // 0011 + case 2: motor_out = 0x2; break; // 0010 + case 3: motor_out = 0x6; break; // 0110 + case 4: motor_out = 0x4; break; // 0100 + case 5: motor_out = 0xC; break; // 1100 + case 6: motor_out = 0x8; break; // 1000 + case 7: motor_out = 0x9; break; // 1001 + + default: motor_out = 0x0; break; // 0000 + } + + if(motor3_direction==1) + { + begin_step++; + teller++; + } + else + { + begin_step--; + teller--; + } + if(begin_step>7)begin_step=0; + if(begin_step<0)begin_step=7; + pc.printf("steps = %i/n/r",teller); + + // if(teller<=-10000)//WANNEER DE FUNCTIE VAN RICHTING VERANDERD(MOET NOG STOPPEN WORDEN) + //{ + //motor3_direction=1; + // } +} + +void motor3_clean() +{ + switch(begin_step) + { + case 0: motor_out = 0x1; break; // 0001 + case 1: motor_out = 0x3; break; // 0011 + case 2: motor_out = 0x2; break; // 0010 + case 3: motor_out = 0x6; break; // 0110 + case 4: motor_out = 0x4; break; // 0100 + case 5: motor_out = 0xC; break; // 1100 + case 6: motor_out = 0x8; break; // 1000 + case 7: motor_out = 0x9; break; // 1001 + + default: motor_out = 0x0; break; // 0000 + } + + if(motor3_direction==1) + { + begin_step++; + teller++; + } + else + { + begin_step--; + teller--; + } + if(begin_step>7)begin_step=0; + if(begin_step<0)begin_step=7; + pc.printf("steps = %i/n/r",teller); + + if(teller<=-1000)//WANNEER DE FUNCTIE VAN RICHTING VERANDERD(MOET NOG STOPPEN WORDEN) + { + motor3_direction=up; + } + if(teller>=1000)//WANNEER DE FUNCTIE VAN RICHTING VERANDERD(MOET NOG STOPPEN WORDEN) + { + motor3_direction=down; + } + +} + +int main() +{ + t0.attach(&fn0_activate, 0.0014f); + //t7.attach(&fn7_activate, 0.0014f); +pc.baud(115200); + while(1) + { + if(fn0_go) + { + fn0_go = false; + motor3_position(); + } + //if(fn7_go) + //{ + //fn7_go = false; + //motor3_clean(); + //} + } +} + + + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Nov 01 13:07:59 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sMotor.lib Tue Nov 01 13:07:59 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/XtaticO/code/sMotor/#4b3b9e047ce3