Control Stepper Motor using Matlab via Serial port

Dependencies:   BufferedSerial X_NUCLEO_IHM01A1 mbed

Files at this revision

API Documentation at this revision

Comitter:
Arkadi
Date:
Tue Jan 26 15:06:37 2016 +0000
Parent:
0:ad32f7e53ed6
Commit message:
Small Fixes and updates

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ad32f7e53ed6 -r fd0fbabd0c8f main.cpp
--- a/main.cpp	Tue Jan 26 10:22:39 2016 +0000
+++ b/main.cpp	Tue Jan 26 15:06:37 2016 +0000
@@ -45,7 +45,7 @@
 char BufferCMD[64]={0};
 uint16_t BufferIndex=0;
 volatile bool Sensor_Sample_Flag=0;
-#define Sample_Interval 10000 // interval in us, (10ms, 100Hz)
+#define Sample_Interval 5000 // interval in us, (5ms, 200Hz)
 float CMDValue=0; // CMD at which speed to run
 char inbyte=' ';
 
@@ -91,7 +91,7 @@
 ////////////////
 // Functions: //
 ////////////////
-// Ticker function
+// Ticker function for stepper speed control, not very eficient.
 void Stepper_PWM() {
     StepPWM=!StepPWM;
     if (StepPWM==1){ //If change to high, step performed Update Stepper Position
@@ -120,7 +120,7 @@
     pc.baud(921600); 
     
     //Attach ticker object:   
-    SensorSampleTicker.attach_us(&Sensor_Sample, Sample_Interval); // create 10Khz Ticker
+    SensorSampleTicker.attach_us(&Sensor_Sample, Sample_Interval); // create Sample Ticker
     
     // Attach millis ticker:
     MillisTicket.attach_us(&MillisCounter, 1000); // create 1Khz Ticker (1ms increment) 
@@ -182,7 +182,7 @@
                if (CMDValue<1.0f){ // Stops
                   StepperTicker.detach(); 
                }else{
-                   StepperTicker.attach(&Stepper_PWM,2.0f/CMDValue); // Set Stepper Freq, 2.0f/Freq : 2 calls to ticker object performs a step
+                   StepperTicker.attach(&Stepper_PWM,0.5f/CMDValue); // Set Stepper Freq, 2.0f/Freq : 2 calls to ticker object performs a step
                }
      
             }//end parser