Expansion SW library to control high power stepper motor(s) using IHM03A1 expansion board(s) with Powerstep01 driver.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   IHM03A1_ExampleFor1Motor HelloWorld_IHM03A1 IHM03A1_ExampleFor3Motors KYPHOS_Stepper_Motor_Control

Fork of X_NUCLEO_IHM03A1 by ST Expansion SW Team

Motor Control Library

Library to handle the X-NUCLEO-IHM03A1 Motor Control Expansion Board based on the Powerstep01 component.

It features the:

  • read and write of Powerstep01 registers
  • Nucleo and expansion board configuration (GPIOs, PWMs, IRQs, etc.)
  • Powerstep01 application commands handling
  • FLAG and BUSY interrupt handling (alarm reporting)
  • Daisy chain 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/128)
  • get/set the control method
  • get/set parameters for voltage mode driving
  • get/set parameters for current mode driving
  • get/set parameters for gate driving
  • configure various protections such as overcurrent detection
  • enable/disable alarms
  • handle step-clock
  • get system status

Daisy-Chain Configuration

The IHM03A1 board can be stacked up to three times so that the Powerstep01 components will be connected in daisy-chain configuration. For this purpose, some resistors must be correctly connected on the boards as depicted here below:

/media/uploads/nucleosam/driving1steppermotor.png /media/uploads/nucleosam/driving2steppermotors.png /media/uploads/nucleosam/driving3steppermotors.png

Platform compatibility

Compatible platforms have been tested with the default configuration provided by the HelloWorld_IHM03A1 example.

Revision:
1:8ce2a5d6fbf8
Parent:
0:00a3c3f5a8f0
Child:
2:06f3a5360a45
--- a/Components/powerstep01/powerstep01_class.h	Tue Apr 05 15:18:56 2016 +0000
+++ b/Components/powerstep01/powerstep01_class.h	Thu Apr 07 16:11:47 2016 +0000
@@ -158,30 +158,10 @@
     }
 
     /**
-     * @brief  Getting the version of the firmware.
-     * @param  None.
-     * @retval The version of the firmware.
-     */
-    virtual unsigned int GetFwVersion(void)
-    {
-        return (unsigned int) Powerstep01_GetFwVersion();
-    }
-
-    /**
      * @brief Public functions inherited from the StepperMotor Class
      */
 
     /**
-     * @brief  Attaching an error handler.
-     * @param  fptr An error handler.
-     * @retval None.
-     */
-    virtual void AttachErrorHandler(void (*fptr)(uint16_t error))
-    {
-        Powerstep01_AttachErrorHandler((void (*)(uint16_t error)) fptr);
-    }
-
-    /**
      * @brief  Getting the value of the Status Register.
      * @param  None.
      * @retval None.
@@ -192,86 +172,6 @@
         return (unsigned int) Powerstep01_CmdGetStatus();
     }
 
-   /**
-     * @brief  Getting a parameter register value.
-     * @param  parameter A parameter's register adress.
-     * @retval The parameter's register value.
-     *         parameter can be one of the following:
-     *           + POWERSTEP01_ABS_POS
-     *           + POWERSTEP01_EL_POS
-     *           + POWERSTEP01_MARK
-     *           + POWERSTEP01_SPEED
-     *           + POWERSTEP01_ACC
-     *           + POWERSTEP01_DEC
-     *           + POWERSTEP01_MAX_SPEED
-     *           + POWERSTEP01_MIN_SPEED
-     *           (voltage mode) + POWERSTEP01_KVAL_HOLD : value in %
-     *           (current mode) + POWERSTEP01_TVAL_HOLD : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_RUN  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_RUN  : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_ACC  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_ACC  : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_DEC  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_DEC  : value in mV
-     *           (voltage mode) + POWERSTEP01_INT_SPD
-     *           (voltage mode) + POWERSTEP01_ST_SLP
-     *           (current mode) + POWERSTEP01_T_FAST
-     *           (voltage mode) + POWERSTEP01_FN_SLP_ACC
-     *           (current mode) + POWERSTEP01_TON_MIN
-     *           (voltage mode) + POWERSTEP01_FN_SLP_DEC
-     *           (current mode) + POWERSTEP01_TOFF_MIN
-     *           (voltage mode) + POWERSTEP01_K_THERM
-     *           + POWERSTEP01_ADC_OUT
-     *           + POWERSTEP01_OCD_TH
-     *           (voltage mode) + POWERSTEP01_STALL_TH
-     *           + POWERSTEP01_FS_SPD
-     *           + POWERSTEP01_STEP_MODE
-     *           + POWERSTEP01_ALARM_EN
-     *           + POWERSTEP01_GATECFG1
-     *           + POWERSTEP01_GATECFG2
-     *           + POWERSTEP01_CONFIG
-     *           + POWERSTEP01_STATUS
-     */
-    virtual unsigned int GetParameter(unsigned int parameter)
-    {
-      return (unsigned int) Powerstep01_CmdGetParam((powerstep01_Registers_t)parameter);
-    }
-
-   /**
-     * @brief  Getting a parameter float value.
-     * @param  parameter A parameter's register adress.
-     * @retval The parameter's float value.
-     *         parameter can be one of the following:
-     *           + POWERSTEP01_ABS_POS
-     *           + POWERSTEP01_MARK
-     *           + POWERSTEP01_ACC
-     *           + POWERSTEP01_DEC
-     *           + POWERSTEP01_SPEED     
-     *           + POWERSTEP01_MAX_SPEED
-     *           + POWERSTEP01_MIN_SPEED
-     *           + POWERSTEP01_FS_SPD
-     *           (voltage mode) + POWERSTEP01_INT_SPD
-     *           (voltage mode) + POWERSTEP01_K_THERM
-     *           + POWERSTEP01_OCD_TH
-     *           (voltage mode) + POWERSTEP01_STALL_TH
-     *           (voltage mode) + POWERSTEP01_KVAL_HOLD : value in %
-     *           (current mode) + POWERSTEP01_TVAL_HOLD : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_RUN  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_RUN  : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_ACC  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_ACC  : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_DEC  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_DEC  : value in mV
-     *           (voltage mode) + POWERSTEP01_ST_SLP
-     *           (voltage mode) + POWERSTEP01_FN_SLP_ACC
-     *           (voltage mode) + POWERSTEP01_FN_SLP_DEC
-     */
-    virtual float GetAnalogValue(unsigned int parameter)
-    {
-      return Powerstep01_GetAnalogValue((powerstep01_Registers_t)parameter);
-    }
-
-
     /**
      * @brief  Getting the position.
      * @param  None.
@@ -359,87 +259,6 @@
         }
     }
     
-   /**
-     * @brief  Setting a parameter.
-     * @param  parameter A parameter's register adress.
-     * @param  value The parameter's value.
-     * @retval None.
-     *         parameter can be one of the following:
-     *           + POWERSTEP01_ABS_POS
-     *           + POWERSTEP01_EL_POS
-     *           + POWERSTEP01_MARK
-     *           + POWERSTEP01_ACC
-     *           + POWERSTEP01_DEC
-     *           + POWERSTEP01_MAX_SPEED
-     *           + POWERSTEP01_MIN_SPEED
-     *           (voltage mode) + POWERSTEP01_KVAL_HOLD : value in %
-     *           (current mode) + POWERSTEP01_TVAL_HOLD : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_RUN  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_RUN  : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_ACC  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_ACC  : value in mV
-     *           (voltage mode) + POWERSTEP01_KVAL_DEC  : value in %
-     *           (current mode) + POWERSTEP01_TVAL_DEC  : value in mV
-     *           (voltage mode) + POWERSTEP01_INT_SPD
-     *           (voltage mode) + POWERSTEP01_ST_SLP
-     *           (current mode) + POWERSTEP01_T_FAST
-     *           (voltage mode) + POWERSTEP01_FN_SLP_ACC
-     *           (current mode) + POWERSTEP01_TON_MIN
-     *           (voltage mode) + POWERSTEP01_FN_SLP_DEC
-     *           (current mode) + POWERSTEP01_TOFF_MIN
-     *           (voltage mode) + POWERSTEP01_K_THERM
-     *           + POWERSTEP01_ADC_OUT
-     *           + POWERSTEP01_OCD_TH
-     *           (voltage mode) + POWERSTEP01_STALL_TH
-     *           + POWERSTEP01_FS_SPD
-     *           + POWERSTEP01_STEP_MODE
-     *           + POWERSTEP01_ALARM_EN
-     *           + POWERSTEP01_GATECFG1
-     *           + POWERSTEP01_GATECFG2
-     *           + POWERSTEP01_CONFIG
-     */
-    virtual void SetParameter(unsigned int parameter, unsigned int value)
-    {
-        Powerstep01_CmdSetParam((powerstep01_Registers_t)parameter, (uint32_t)value);
-    }
-
-   /**
-     * @brief  Setting a parameter with an input float value.
-     * @param  param Register adress.
-     * @param  value Float value to convert and set into the register.
-     * @retval TRUE if param and value are valid, FALSE otherwise
-     * @note   parameter can be one of the following:
-     *           + POWERSTEP01_EL_POS
-     *           + POWERSTEP01_ABS_POS
-     *           + POWERSTEP01_MARK
-     *           + POWERSTEP01_ACC
-     *           + POWERSTEP01_DEC
-     *           + POWERSTEP01_MAX_SPEED
-     *           + POWERSTEP01_MIN_SPEED
-     *           + POWERSTEP01_FS_SPD
-     *           + POWERSTEP01_INT_SPD
-     *           + POWERSTEP01_K_THERM
-     *           + POWERSTEP01_OCD_TH
-     *           + POWERSTEP01_STALL_TH
-     *           + POWERSTEP01_KVAL_HOLD
-     *           + POWERSTEP01_KVAL_RUN
-     *           + POWERSTEP01_KVAL_ACC
-     *           + POWERSTEP01_KVAL_DEC
-     *           + POWERSTEP01_ST_SLP
-     *           + POWERSTEP01_FN_SLP_ACC
-     *           + POWERSTEP01_FN_SLP_DEC
-     *           + POWERSTEP01_TVAL_HOLD
-     *           + POWERSTEP01_TVAL_RUN
-     *           + POWERSTEP01_TVAL_ACC
-     *           + POWERSTEP01_TVAL_DEC
-     *           + POWERSTEP01_TON_MIN
-     *           + POWERSTEP01_TOFF_MIN
-     */
-    virtual bool SetAnalogValue(unsigned int param, float value)
-    {
-      return Powerstep01_SetAnalogValue((powerstep01_Registers_t)param, value);
-    }
-
     /**
      * @brief  Setting the current position to be the home position.
      * @param  None.
@@ -514,9 +333,9 @@
      *           + STEP_MODE_1_64
      *           + STEP_MODE_1_128
      */
-    virtual void SetStepMode(motorStepMode_t step_mode)
+    virtual bool SetStepMode(step_mode_t step_mode)
     {
-        Powerstep01_SelectStepMode((motorStepMode_t) step_mode);
+        return Powerstep01_SelectStepMode((motorStepMode_t) step_mode);
     }
 
     /**
@@ -565,17 +384,6 @@
     }
 
     /**
-     * @brief  Running the motor towards a specified direction.
-     * @param  direction The direction of rotation.
-     * @param  speed in steps/s.
-     * @retval None.
-     */
-    virtual void Run(direction_t direction, float speed)
-    {
-        Powerstep01_CmdRun((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD), Speed_Steps_s_to_RegVal(speed));
-    }
-
-    /**
      * @brief  Moving the motor towards a specified direction for a certain number of steps.
      * @param  direction The direction of rotation.
      * @param  steps The desired number of steps.
@@ -639,7 +447,17 @@
     /**
      * @brief Public functions NOT inherited
      */
-
+     
+    /**
+     * @brief  Attaching an error handler.
+     * @param  fptr An error handler.
+     * @retval None.
+     */
+    virtual void AttachErrorHandler(void (*fptr)(uint16_t error))
+    {
+        Powerstep01_AttachErrorHandler((void (*)(uint16_t error)) fptr);
+    }
+    
     /**
      * @brief  Checks if the device is busy by reading the busy pin position.
      * @param  None.
@@ -680,6 +498,40 @@
     }
 
     /**
+     * @brief  Getting a parameter float value.
+     * @param  parameter A parameter's register adress.
+     * @retval The parameter's float value.
+     *         parameter can be one of the following:
+     *           + POWERSTEP01_ABS_POS
+     *           + POWERSTEP01_MARK
+     *           + POWERSTEP01_ACC
+     *           + POWERSTEP01_DEC
+     *           + POWERSTEP01_SPEED     
+     *           + POWERSTEP01_MAX_SPEED
+     *           + POWERSTEP01_MIN_SPEED
+     *           + POWERSTEP01_FS_SPD
+     *           (voltage mode) + POWERSTEP01_INT_SPD
+     *           (voltage mode) + POWERSTEP01_K_THERM
+     *           + POWERSTEP01_OCD_TH
+     *           (voltage mode) + POWERSTEP01_STALL_TH
+     *           (voltage mode) + POWERSTEP01_KVAL_HOLD : value in %
+     *           (current mode) + POWERSTEP01_TVAL_HOLD : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_RUN  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_RUN  : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_ACC  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_ACC  : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_DEC  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_DEC  : value in mV
+     *           (voltage mode) + POWERSTEP01_ST_SLP
+     *           (voltage mode) + POWERSTEP01_FN_SLP_ACC
+     *           (voltage mode) + POWERSTEP01_FN_SLP_DEC
+     */
+    virtual float GetAnalogValue(unsigned int parameter)
+    {
+      return Powerstep01_GetAnalogValue((powerstep01_Registers_t)parameter);
+    }
+
+    /**
      * @brief Get the value of the STATUS register which was 
      * fetched by using Powerstep01_FetchAndClearAllStatus.
      * The fetched values are available  as long as there
@@ -690,6 +542,61 @@
     {
         return Powerstep01_GetFetchedStatus();
     }
+
+    /**
+     * @brief  Getting the version of the firmware.
+     * @param  None.
+     * @retval The version of the firmware.
+     */
+    virtual unsigned int GetFwVersion(void)
+    {
+        return (unsigned int) Powerstep01_GetFwVersion();
+    }
+
+    /**
+     * @brief  Getting a parameter register value.
+     * @param  parameter A parameter's register adress.
+     * @retval The parameter's register value.
+     *         parameter can be one of the following:
+     *           + POWERSTEP01_ABS_POS
+     *           + POWERSTEP01_EL_POS
+     *           + POWERSTEP01_MARK
+     *           + POWERSTEP01_SPEED
+     *           + POWERSTEP01_ACC
+     *           + POWERSTEP01_DEC
+     *           + POWERSTEP01_MAX_SPEED
+     *           + POWERSTEP01_MIN_SPEED
+     *           (voltage mode) + POWERSTEP01_KVAL_HOLD : value in %
+     *           (current mode) + POWERSTEP01_TVAL_HOLD : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_RUN  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_RUN  : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_ACC  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_ACC  : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_DEC  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_DEC  : value in mV
+     *           (voltage mode) + POWERSTEP01_INT_SPD
+     *           (voltage mode) + POWERSTEP01_ST_SLP
+     *           (current mode) + POWERSTEP01_T_FAST
+     *           (voltage mode) + POWERSTEP01_FN_SLP_ACC
+     *           (current mode) + POWERSTEP01_TON_MIN
+     *           (voltage mode) + POWERSTEP01_FN_SLP_DEC
+     *           (current mode) + POWERSTEP01_TOFF_MIN
+     *           (voltage mode) + POWERSTEP01_K_THERM
+     *           + POWERSTEP01_ADC_OUT
+     *           + POWERSTEP01_OCD_TH
+     *           (voltage mode) + POWERSTEP01_STALL_TH
+     *           + POWERSTEP01_FS_SPD
+     *           + POWERSTEP01_STEP_MODE
+     *           + POWERSTEP01_ALARM_EN
+     *           + POWERSTEP01_GATECFG1
+     *           + POWERSTEP01_GATECFG2
+     *           + POWERSTEP01_CONFIG
+     *           + POWERSTEP01_STATUS
+     */
+    virtual unsigned int GetRawParameter(unsigned int parameter)
+    {
+      return (unsigned int) Powerstep01_CmdGetParam((powerstep01_Registers_t)parameter);
+    }
     
     /**
      * @brief  Issues PowerStep01 Go Until command.
@@ -783,7 +690,18 @@
     {
         Powerstep01_CmdResetPos();
     }
-    
+
+    /**
+     * @brief  Running the motor towards a specified direction.
+     * @param  direction The direction of rotation.
+     * @param  speed in steps/s.
+     * @retval None.
+     */
+    virtual void Run(direction_t direction, float speed)
+    {
+        Powerstep01_CmdRun((motorDir_t) (direction == StepperMotor::FWD ? FORWARD : BACKWARD), Speed_Steps_s_to_RegVal(speed));
+    }
+        
     /**
      * @brief Sends commands stored previously in the queue by QueueCommands.
      * @param  None.
@@ -795,6 +713,87 @@
     }
     
     /**
+     * @brief  Setting a parameter with an input float value.
+     * @param  param Register adress.
+     * @param  value Float value to convert and set into the register.
+     * @retval TRUE if param and value are valid, FALSE otherwise
+     * @note   parameter can be one of the following:
+     *           + POWERSTEP01_EL_POS
+     *           + POWERSTEP01_ABS_POS
+     *           + POWERSTEP01_MARK
+     *           + POWERSTEP01_ACC
+     *           + POWERSTEP01_DEC
+     *           + POWERSTEP01_MAX_SPEED
+     *           + POWERSTEP01_MIN_SPEED
+     *           + POWERSTEP01_FS_SPD
+     *           + POWERSTEP01_INT_SPD
+     *           + POWERSTEP01_K_THERM
+     *           + POWERSTEP01_OCD_TH
+     *           + POWERSTEP01_STALL_TH
+     *           + POWERSTEP01_KVAL_HOLD
+     *           + POWERSTEP01_KVAL_RUN
+     *           + POWERSTEP01_KVAL_ACC
+     *           + POWERSTEP01_KVAL_DEC
+     *           + POWERSTEP01_ST_SLP
+     *           + POWERSTEP01_FN_SLP_ACC
+     *           + POWERSTEP01_FN_SLP_DEC
+     *           + POWERSTEP01_TVAL_HOLD
+     *           + POWERSTEP01_TVAL_RUN
+     *           + POWERSTEP01_TVAL_ACC
+     *           + POWERSTEP01_TVAL_DEC
+     *           + POWERSTEP01_TON_MIN
+     *           + POWERSTEP01_TOFF_MIN
+     */
+    virtual bool SetAnalogValue(unsigned int param, float value)
+    {
+      return Powerstep01_SetAnalogValue((powerstep01_Registers_t)param, value);
+    }
+    
+    /**
+     * @brief  Setting a parameter.
+     * @param  parameter A parameter's register adress.
+     * @param  value The parameter's value.
+     * @retval None.
+     *         parameter can be one of the following:
+     *           + POWERSTEP01_ABS_POS
+     *           + POWERSTEP01_EL_POS
+     *           + POWERSTEP01_MARK
+     *           + POWERSTEP01_ACC
+     *           + POWERSTEP01_DEC
+     *           + POWERSTEP01_MAX_SPEED
+     *           + POWERSTEP01_MIN_SPEED
+     *           (voltage mode) + POWERSTEP01_KVAL_HOLD : value in %
+     *           (current mode) + POWERSTEP01_TVAL_HOLD : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_RUN  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_RUN  : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_ACC  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_ACC  : value in mV
+     *           (voltage mode) + POWERSTEP01_KVAL_DEC  : value in %
+     *           (current mode) + POWERSTEP01_TVAL_DEC  : value in mV
+     *           (voltage mode) + POWERSTEP01_INT_SPD
+     *           (voltage mode) + POWERSTEP01_ST_SLP
+     *           (current mode) + POWERSTEP01_T_FAST
+     *           (voltage mode) + POWERSTEP01_FN_SLP_ACC
+     *           (current mode) + POWERSTEP01_TON_MIN
+     *           (voltage mode) + POWERSTEP01_FN_SLP_DEC
+     *           (current mode) + POWERSTEP01_TOFF_MIN
+     *           (voltage mode) + POWERSTEP01_K_THERM
+     *           + POWERSTEP01_ADC_OUT
+     *           + POWERSTEP01_OCD_TH
+     *           (voltage mode) + POWERSTEP01_STALL_TH
+     *           + POWERSTEP01_FS_SPD
+     *           + POWERSTEP01_STEP_MODE
+     *           + POWERSTEP01_ALARM_EN
+     *           + POWERSTEP01_GATECFG1
+     *           + POWERSTEP01_GATECFG2
+     *           + POWERSTEP01_CONFIG
+     */
+    virtual void SetRawParameter(unsigned int parameter, unsigned int value)
+    {
+        Powerstep01_CmdSetParam((powerstep01_Registers_t)parameter, (uint32_t)value);
+    }
+    
+    /**
      * @brief  Enable the step clock mode.
      * @param  frequency the frequency of PWM.
      * @retval None.
@@ -1250,12 +1249,12 @@
     void Powerstep01_ErrorHandler(uint16_t error);
     void Powerstep01_FetchAndClearAllStatus(void); 
     uint16_t Powerstep01_GetFetchedStatus(void);
-    uint8_t Powerstep01_GetFwVersion(void);
+    uint32_t Powerstep01_GetFwVersion(void);
     int32_t Powerstep01_GetMark(void);
     int32_t Powerstep01_GetPosition(void);
     bool Powerstep01_IsDeviceBusy(void);
     uint16_t Powerstep01_ReadStatusRegister(void);
-    void Powerstep01_SelectStepMode(motorStepMode_t stepMode);
+    bool Powerstep01_SelectStepMode(motorStepMode_t stepMode);
     void Powerstep01_SetHome(void);
     void Powerstep01_SetMark(void);
     void Powerstep01_WaitForAllDevicesNotBusy(void);