Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_IHM02A1 ConcorsoFinal HelloWorld_IHM02A1_mbedOS HelloWorld_IHM02A1-Serialinterpreter ... more

Fork of X_NUCLEO_IHM02A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM02A1 Motor Control Expansion Board based on the the L6470 component.

Daisy-Chain Configuration

The two L6470 components mounted on this board are connected in daisy-chain configuration. This board can be stacked up to four times so that the eight L6470 components will be connected two-by-two in daisy-chain configuration.

Concerning the SSEL pin of the SPI communication, each expansion board must be in one of the following configuration:

  • SB_23 resistor connected only: SSEL on pin A2;
  • SB_7 resistor connected only: SSEL on pin D2;
  • SB_8 resistor connected only: SSEL on pin D10;
  • SB_9 resistor connected only: SSEL on pin D5.

Arduino Connector Compatibility Warning

X-NUCLEO-IHM02A1 is Arduino compatible with one exception: instead of using D13 pin to drive the SPI clock, it uses D3 pin, hence the default configuration for this library is with the SPI clock on D3 pin.

To be fully Arduino compatible the following patch is required:

  • to remove the SB34 resistor;
  • to solder the SB12 resistor.

Alternatively, you can route the Nucleo board’s D13 pin directly to the expansion board’s D3 pin with a wire. In case you patch your expansion board or route the pin, the SPI clock will be driven on D13 pin rather than on D3 pin, and you have also to initialize the sclk PinName variable with D13 rather than D3. This patch is known to be required, for example, on the following boards: NUCLEO-F103RB, NUCLEO-F302RB, NUCLEO-F411RE, and NUCLEO-F429ZI.

If you use D13 pin for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to the D13 pin.

Example Applications

Revision:
17:4b3dc908724f
Parent:
15:31785d1acd4b
Child:
18:ddf3d5dc8137
--- a/Components/l6470/l6470_class.h	Fri Mar 11 15:49:04 2016 +0000
+++ b/Components/l6470/l6470_class.h	Thu Apr 07 16:55:51 2016 +0000
@@ -194,14 +194,40 @@
         return (unsigned int) L6470_GetStatus();
     }
 
-    /**
+   /**
      * @brief  Getting a parameter.
-     * @param  parameter The parameter's identifier (or its register address).
+     * @param  parameter A parameter's register address.
      * @retval The parameter's value.
+     * @note   The parameter can be one of the following:
+     *           + L6470_ABS_POS_ID
+     *           + L6470_EL_POS_ID
+     *           + L6470_MARK_ID
+     *           + L6470_SPEED_ID
+     *           + L6470_ACC_ID
+     *           + L6470_DEC_ID
+     *           + L6470_MAX_SPEED_ID
+     *           + L6470_MIN_SPEED_ID
+     *           + L6470_FS_SPD_ID
+     *           + L6470_KVAL_HOLD_ID
+     *           + L6470_KVAL_RUN_ID
+     *           + L6470_KVAL_ACC_ID
+     *           + L6470_KVAL_DEC_ID
+     *           + L6470_INT_SPEED_ID
+     *           + L6470_ST_SLP_ID
+     *           + L6470_FN_SLP_ACC_ID
+     *           + L6470_FN_SLP_DEC_ID
+     *           + L6470_K_THERM_ID
+     *           + L6470_ADC_OUT_ID
+     *           + L6470_OCD_TH_ID
+     *           + L6470_STALL_TH_ID
+     *           + L6470_STEP_MODE_ID
+     *           + L6470_ALARM_EN_ID
+     *           + L6470_CONFIG_ID
+     *           + L6470_STATUS_ID
      */
-    virtual float GetParameter(unsigned int parameter)
+    virtual unsigned int GetParameter(unsigned int parameter)
     {
-        return (float) L6470_GetParam((eL6470_RegId_t) parameter);
+        return (unsigned int) L6470_GetParam((eL6470_RegId_t) parameter);
     }
 
     /**
@@ -285,12 +311,61 @@
     }
 
    /**
-     * @brief  Setting a parameter.
-     * @param  parameter The parameter's identifier (or its register address).
-     * @param  value The parameter's value.
-     * @retval None.
+     * @brief   Setting a parameter.
+     * @param   parameter A parameter's register address.
+     * @param   value The parameter's value.
+     * @retval  None.
+     * @note    The parameter can be one of the following:
+     *           + L6470_ABS_POS_ID
+     *           + L6470_EL_POS_ID
+     *           + L6470_MARK_ID
+     *           + L6470_SPEED_ID
+     *           + L6470_ACC_ID
+     *           + L6470_DEC_ID
+     *           + L6470_MAX_SPEED_ID
+     *           + L6470_MIN_SPEED_ID
+     *           + L6470_FS_SPD_ID
+     *           + L6470_KVAL_HOLD_ID
+     *           + L6470_KVAL_RUN_ID
+     *           + L6470_KVAL_ACC_ID
+     *           + L6470_KVAL_DEC_ID
+     *           + L6470_INT_SPEED_ID
+     *           + L6470_ST_SLP_ID
+     *           + L6470_FN_SLP_ACC_ID
+     *           + L6470_FN_SLP_DEC_ID
+     *           + L6470_K_THERM_ID
+     *           + L6470_ADC_OUT_ID
+     *           + L6470_OCD_TH_ID
+     *           + L6470_STALL_TH_ID
+     *           + L6470_STEP_MODE_ID
+     *           + L6470_ALARM_EN_ID
+     *           + L6470_CONFIG_ID
+     *           + L6470_STATUS_ID
+     * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
+     *          Any attempt to write one of those registers when the conditions are not satisfied
+     *          causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
+     *          last argument byte. Any attempt to set an inexistent register (wrong address value)
+     *          causes the command to be ignored and the WRONG_CMD flag to rise.
+     *          For example, setting some parameters requires first to disable the power bridge;
+     *          this can be done through the SoftHiZ() method.
+     *          They are the following:
+     *           + L6470_ABS_POS_ID
+     *           + L6470_EL_POS_ID
+     *           + L6470_SPEED_ID
+     *           + L6470_ACC_ID
+     *           + L6470_DEC_ID
+     *           + L6470_MAX_SPEED_ID
+     *           + L6470_MIN_SPEED_ID
+     *           + L6470_INT_SPEED_ID
+     *           + L6470_ST_SLP_ID
+     *           + L6470_FN_SLP_ACC_ID
+     *           + L6470_FN_SLP_DEC_ID
+     *           + L6470_ADC_OUT_ID
+     *           + L6470_STEP_MODE_ID
+     *           + L6470_CONFIG_ID
+     *           + L6470_STATUS_ID
      */
-    virtual void SetParameter(unsigned int parameter, float value)
+    virtual void SetParameter(unsigned int parameter, unsigned int value)
     {
         L6470_SetParam((eL6470_RegId_t) parameter, (uint32_t) value);
     }
@@ -328,41 +403,64 @@
     /**
      * @brief  Setting the maximum speed in pps.
      * @param  speed The maximum speed in pps.
-     * @retval None.
+     * @retval "true" in case of success, "false" otherwise.
      */
-    virtual void SetMaxSpeed(unsigned int speed)
+    virtual bool SetMaxSpeed(unsigned int speed)
     {
         L6470_SetParam((eL6470_RegId_t) L6470_MAX_SPEED_ID, (uint32_t) L6470_Step_s_2_MaxSpeed((float) speed));
+        return true;
     }
 
     /**
      * @brief  Setting the minimum speed in pps.
      * @param  speed The minimum speed in pps.
-     * @retval None.
+     * @retval "true" in case of success, "false" otherwise.
      */
-    virtual void SetMinSpeed(unsigned int speed)
+    virtual bool SetMinSpeed(unsigned int speed)
     {
         L6470_SetParam((eL6470_RegId_t) L6470_MIN_SPEED_ID, (uint32_t) L6470_Step_s_2_MinSpeed((float) speed));
+        return true;
     }
 
     /**
      * @brief  Setting the acceleration in pps^2.
      * @param  acceleration The acceleration in pps^2.
-     * @retval None.
+     * @retval "true" in case of success, "false" otherwise.
      */
-    virtual void SetAcceleration(unsigned int acceleration)
+    virtual bool SetAcceleration(unsigned int acceleration)
     {
         L6470_SetParam((eL6470_RegId_t) L6470_ACC_ID, (uint32_t) L6470_Step_s2_2_Acc((float) acceleration));
+        return true;
     }
 
     /**
      * @brief  Setting the deceleration in pps^2.
      * @param  deceleration The deceleration in pps^2.
-     * @retval None.
+     * @retval "true" in case of success, "false" otherwise.
      */
-    virtual void SetDeceleration(unsigned int deceleration)
+    virtual bool SetDeceleration(unsigned int deceleration)
     {
         L6470_SetParam((eL6470_RegId_t) L6470_DEC_ID, (uint32_t) L6470_Step_s2_2_Dec((float) deceleration));
+        return true;
+    }
+
+    /**
+     * @brief   Setting the Step Mode.
+     * @param   step_mode The Step Mode.
+     * @retval "true" in case of success, "false" otherwise.
+     * @warning Setting the step mode implies first disabling the power bridge through
+     *          the SoftHiZ() method.
+     * @warning Every time step mode is changed, the values of the home
+     *          and mark positions lose meaning and are reset.
+     */
+    virtual bool SetStepMode(step_mode_t step_mode)
+    {
+        if ((eMotorStepMode_t) step_mode > MICROSTEP_1_128)
+            return false;
+
+        SoftHiZ();
+        L6470_SetParam((eL6470_RegId_t) L6470_STEP_MODE_ID, (eMotorStepMode_t) step_mode);
+        return true;
     }
 
     /**
@@ -508,12 +606,15 @@
     }
 
     /**
-      * @brief  Switching to step-clock mode.
-      * @param  direction The direction of rotation.
-      * @retval None.
-      */
+     * @brief   Switching to step-clock mode.
+     * @param   direction The direction of rotation.
+     * @retval  None.
+     * @warning Setting the step-clock mode implies first disabling the power bridge through
+     *          the SoftHiZ() method.
+     */
     virtual void StepClock(direction_t direction)
     {
+        SoftHiZ();
         L6470_StepClock((eL6470_DirId_t) (direction == StepperMotor::FWD ? L6470_DIR_FWD_ID : L6470_DIR_REV_ID));
     }
 
@@ -554,11 +655,37 @@
         prepared_action = PREPARED_NO_ACTION;
     }
 
-    /**
+   /**
      * @brief  Preparing the command to get a parameter.
-     * @param  parameter The parameter's identifier (or its register address).
+     * @param  parameter A parameter's register address.
      * @retval None.
      * @note   The command will be sent by issuing "PerformAction()".
+     *         The parameter can be one of the following:
+     *           + L6470_ABS_POS_ID
+     *           + L6470_EL_POS_ID
+     *           + L6470_MARK_ID
+     *           + L6470_SPEED_ID
+     *           + L6470_ACC_ID
+     *           + L6470_DEC_ID
+     *           + L6470_MAX_SPEED_ID
+     *           + L6470_MIN_SPEED_ID
+     *           + L6470_FS_SPD_ID
+     *           + L6470_KVAL_HOLD_ID
+     *           + L6470_KVAL_RUN_ID
+     *           + L6470_KVAL_ACC_ID
+     *           + L6470_KVAL_DEC_ID
+     *           + L6470_INT_SPEED_ID
+     *           + L6470_ST_SLP_ID
+     *           + L6470_FN_SLP_ACC_ID
+     *           + L6470_FN_SLP_DEC_ID
+     *           + L6470_K_THERM_ID
+     *           + L6470_ADC_OUT_ID
+     *           + L6470_OCD_TH_ID
+     *           + L6470_STALL_TH_ID
+     *           + L6470_STEP_MODE_ID
+     *           + L6470_ALARM_EN_ID
+     *           + L6470_CONFIG_ID
+     *           + L6470_STATUS_ID
      */
     virtual void PrepareGetParameter(unsigned int parameter)
     {
@@ -670,10 +797,59 @@
 
    /**
      * @brief  Preparing the command to set a parameter.
-     * @param  parameter The parameter's identifier (or its register address).
+     * @param  parameter A parameter's register address.
      * @param  value The parameter's value.
      * @retval None.
      * @note   The command will be sent by issuing "PerformAction()".
+     *         The parameter can be one of the following:
+     *           + L6470_ABS_POS_ID
+     *           + L6470_EL_POS_ID
+     *           + L6470_MARK_ID
+     *           + L6470_SPEED_ID
+     *           + L6470_ACC_ID
+     *           + L6470_DEC_ID
+     *           + L6470_MAX_SPEED_ID
+     *           + L6470_MIN_SPEED_ID
+     *           + L6470_FS_SPD_ID
+     *           + L6470_KVAL_HOLD_ID
+     *           + L6470_KVAL_RUN_ID
+     *           + L6470_KVAL_ACC_ID
+     *           + L6470_KVAL_DEC_ID
+     *           + L6470_INT_SPEED_ID
+     *           + L6470_ST_SLP_ID
+     *           + L6470_FN_SLP_ACC_ID
+     *           + L6470_FN_SLP_DEC_ID
+     *           + L6470_K_THERM_ID
+     *           + L6470_ADC_OUT_ID
+     *           + L6470_OCD_TH_ID
+     *           + L6470_STALL_TH_ID
+     *           + L6470_STEP_MODE_ID
+     *           + L6470_ALARM_EN_ID
+     *           + L6470_CONFIG_ID
+     *           + L6470_STATUS_ID
+     * @warning Some registers can only be written in particular conditions (see L6470's datasheet).
+     *          Any attempt to write one of those registers when the conditions are not satisfied
+     *          causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the
+     *          last argument byte. Any attempt to set an inexistent register (wrong address value)
+     *          causes the command to be ignored and the WRONG_CMD flag to rise.
+     *          For example, setting some parameters requires first to disable the power bridge;
+     *          this can be done through the SoftHiZ() method.
+     *          They are the following:
+     *           + L6470_ABS_POS_ID
+     *           + L6470_EL_POS_ID
+     *           + L6470_SPEED_ID
+     *           + L6470_ACC_ID
+     *           + L6470_DEC_ID
+     *           + L6470_MAX_SPEED_ID
+     *           + L6470_MIN_SPEED_ID
+     *           + L6470_INT_SPEED_ID
+     *           + L6470_ST_SLP_ID
+     *           + L6470_FN_SLP_ACC_ID
+     *           + L6470_FN_SLP_DEC_ID
+     *           + L6470_ADC_OUT_ID
+     *           + L6470_STEP_MODE_ID
+     *           + L6470_CONFIG_ID
+     *           + L6470_STATUS_ID
      */
     virtual void PrepareSetParameter(unsigned int parameter, unsigned int value)
     {
@@ -946,10 +1122,12 @@
     }
 
     /**
-      * @brief  Preparing the command to switch to step-clock mode.
-      * @param  direction The direction of rotation.
-      * @retval None.
-      * @note   The command will be sent by issuing "PerformAction()".
+      * @brief   Preparing the command to switch to step-clock mode.
+      * @param   direction The direction of rotation.
+      * @retval  None.
+      * @warning Setting the step-clock mode requires an explicit action by the user to first
+      *          disable the power bridge through the SoftHiZ() method.
+      * @note    The command will be sent by issuing "PerformAction()".
       */
     virtual void PrepareStepClock(direction_t direction)
     {