Expansion SW library to control a bipolar stepper motor using X-NUCLEO-IHM05A1 expansion board based on L6208.

Dependencies:   ST_INTERFACES

Dependents:   HelloWorld_IHM05A1 TAU_ROTATING_PLATFORM_IHM05A1 Amaldi_13_Exercise_IHM05A1 Amaldi_13_Exercise_IHM05A1motore ... more

Fork of X-NUCLEO-IHM05A1 by ST Expansion SW Team

Motor Control Library

Library to handle the X-NUCLEO-IHM05A1 Motor Control Expansion Board based on the L6208 component.

It features the:

  • Read and write of device parameters
  • Configuration of GPIOs and IRQs (for enabling, direction, current decay and microstepping)
  • Control of position, speed, acceleration and deceleration
  • Command locking until the device completes movement
  • Handling of overcurrent and thermal alarms (flag interrupt handling)

The API allows to easily:

  • perform various positioning, moves and stops
  • get/set or monitor the motor positions
  • set home position and mark another position
  • get/set minimum and maximum speed
  • get current speed
  • get/set acceleration and deceleration
  • get/set the step mode (up to 1/16)

Board configuration

/media/uploads/nucleosam/mbed-x-nucleo-ihm05a1.png

Platform compatibility

Compatible platforms have been tested with the configurations provided by the HelloWorld_IHM05A1 example.

Files at this revision

API Documentation at this revision

Comitter:
Davidroid
Date:
Fri Jul 28 13:06:36 2017 +0000
Parent:
5:f0856e278c08
Commit message:
Aligning to ARM mbed coding style.

Changed in this revision

Components/L6208/L6208.cpp Show annotated file Show diff for this revision Revisions of this file
Components/L6208/L6208.h Show annotated file Show diff for this revision Revisions of this file
diff -r f0856e278c08 -r c73faac7197f Components/L6208/L6208.cpp
--- a/Components/L6208/L6208.cpp	Mon May 08 15:42:20 2017 +0000
+++ b/Components/L6208/L6208.cpp	Fri Jul 28 13:06:36 2017 +0000
@@ -216,8 +216,14 @@
  **********************************************************/
 motorDecayMode_t L6208::L6208_get_decay_mode(void)
 {
-  if (L6208_IsSysFlag(fastdecaymode)) return (FAST_DECAY);
-  else return (SLOW_DECAY);
+  if (L6208_IsSysFlag(fastdecaymode))
+  {
+      return (FAST_DECAY);
+  }
+  else
+  {
+      return (SLOW_DECAY);
+  }
 }
 
 /******************************************************//**
@@ -1532,7 +1538,10 @@
   devicePrm.stepMode = pInitDevicePrm->stepMode;
   L6208_SetDecayMode(pInitDevicePrm->decayMode);
   devicePrm.moveDwellTime = pInitDevicePrm->moveDwellTime;
-  if (L6208_CONF_PARAM_AUTO_HIZ_STOP) L6208_SetSysFlag(pInitDevicePrm->autoHiZstop);
+  if (L6208_CONF_PARAM_AUTO_HIZ_STOP)
+  {
+    L6208_SetSysFlag(pInitDevicePrm->autoHiZstop);
+  }
   devicePrm.vrefPwmFreq = pInitDevicePrm->vrefPwmFreq;
   devicePrm.vrefPwmPeriod = (uint16_t)((1000000<<8)/pInitDevicePrm->vrefPwmFreq);
   /* Initialize current stepper state machine index  */
@@ -1561,7 +1570,10 @@
   devicePrm.stepMode = (motorStepMode_t) L6208_CONF_PARAM_STEP_MODE;
   L6208_SetDecayMode(L6208_CONF_PARAM_DECAY_MODE);
   devicePrm.moveDwellTime = L6208_CONF_PARAM_DWELL_TIME;
-  if (L6208_CONF_PARAM_AUTO_HIZ_STOP) L6208_SetSysFlag(HiZstop);
+  if (L6208_CONF_PARAM_AUTO_HIZ_STOP) 
+  {
+    L6208_SetSysFlag(HiZstop);
+  }
   devicePrm.vrefPwmFreq = L6208_CONF_VREF_PWM_FREQUENCY;
   devicePrm.vrefPwmPeriod = (uint16_t)((1000000<<8)/L6208_CONF_VREF_PWM_FREQUENCY);
   /* Initialize current stepper state machine index  */
@@ -1815,7 +1827,10 @@
 {
   if(valueIsPwmDutyCycle)
   {
-    if (value > 100) value = 100;
+    if (value > 100)
+    {
+      value = 100;
+    }
     value = (uint16_t)(((uint32_t)devicePrm.vrefPwmPeriod * (uint32_t)value) / 100); 
   }
   if (bridgeId == 0)
diff -r f0856e278c08 -r c73faac7197f Components/L6208/L6208.h
--- a/Components/L6208/L6208.h	Mon May 08 15:42:20 2017 +0000
+++ b/Components/L6208/L6208.h	Fri Jul 28 13:06:36 2017 +0000
@@ -508,8 +508,14 @@
      */
     virtual unsigned int check_status_hw(void)
     {
-        if (!flag_and_enable.read()) return 0x01;
-        else return 0x00;
+        if (!flag_and_enable.read())
+        {
+            return 0x01;
+        }
+        else
+        {
+            return 0x00;
+        }
     }
     
     /**
@@ -1060,7 +1066,10 @@
         {
             vrefB_pwm.period_us(pwmPeriod);
         }
-        else return false;
+        else
+        {
+            return false;
+        }
         return true;
     }
     
@@ -1081,7 +1090,10 @@
         {
             vrefB_pwm.period_us(0);
         }
-        else return false;
+        else
+        {
+            return false;
+        }
         return true;
     }