DRV8825 steeper motor controller with serial interface for delimited matlab input input format dir,step, delay
Revision 1:19ba52379a64, committed 2016-09-21
- Comitter:
- kanatronics
- Date:
- Wed Sep 21 11:43:12 2016 +0000
- Parent:
- 0:24171bdfc41f
- Commit message:
- Added ready status LED
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 24171bdfc41f -r 19ba52379a64 main.cpp --- a/main.cpp Fri Sep 16 13:31:15 2016 +0000 +++ b/main.cpp Wed Sep 21 11:43:12 2016 +0000 @@ -1,36 +1,33 @@ -/*Kamil Kanas +/*Kamil Kanas QUB NUCLEO FR401 Serial Stepper motor controller DRV8825 -Matlab interface (dir,step,speed) +Matlab interface: dir,step,speed 15/9/2016 */ #include "mbed.h" -// DRV8825 control pins - -#define stepPin PA_5 //Step pin -#define dirPin PA_6 //Direction pin -#define enPin PA_7 //Enable pin - /*--INITS-------------------------------------------------------------------------------*/ -Serial pc(USBTX, USBRX); // create PC interface -DigitalOut stepOut(stepPin); // step output -DigitalOut dirOut(dirPin); // direction output -DigitalOut enableOut(enPin); //enable output +Serial pc(USBTX, USBRX); // create PC interface +DigitalOut stepOut(PA_7); // step output +DigitalOut dirOut(PA_6); // direction output +DigitalOut enableOut(PA_8); // enable output +DigitalOut ledGreen (PA_5); // green ready led /*--VARIABLES---------------------------------------------------------------------------*/ char buffer[16]; //Serial buffer uint8_t direction; //Direction 0 - right, 1- left uint16_t step; //step 0-400 full turn in half step mode uint16_t speed; //speed -char * pch; //auxilary pointer to buffer +char *pch; //auxilary pointer to buffer char *mot_char[16]; //motor char int mot_int[3]; //motor int /*--FUNCTION DECLARATIONS---------------------------------------------------------------*/ + void int_usb(void); void stepMOtor (int,int,int); void stepDemo (void); + /*--FUNCTION DEFINITIONS----------------------------------------------------------------*/ /* @@ -56,7 +53,6 @@ if (!dir) // Checking direction flag { - enableOut=0; dirOut=0; // drive right @@ -78,7 +74,8 @@ wait_ms(speedS); if (deg==steps-2) { - pc.printf("ready %s \n"); + pc.printf("ready %s\n"); + ledGreen=1; // ready status ON } } } @@ -103,14 +100,16 @@ int main() { int_usb(); + enableOut=1; while(1){ - pc.printf("Hello %s \n"); + //pc.printf("Hello %s \n"); wait(0.5); while(true){ while (pc.readable()) { //if data in the ring buffer pc.gets(buffer,16); //read 7 characters - pc.printf("stringReceived %s ", buffer); + ledGreen=0; + //pc.printf("stringReceived %s ", buffer); char * pch; pch = strtok (buffer,","); int i=0; @@ -126,6 +125,8 @@ mot_int[i]=atoi(mot_char[i]); pc.printf("%d\n", mot_int[i]); } + stepMOtor(mot_int[0],mot_int[1],mot_int[2]); + enableOut=1; break; } }