Library to handle the X-NUCLEO-IHM01A1 Motor Control Expansion Board based on the L6474 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   Stepper_Matlab_Control SunTracker_BLE Stepper_Matlab_Control MemsMotorControl ... more

Fork of X_NUCLEO_IHM01A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM01A1 Motor Control Expansion Board based on the the L6474 component.

Daisy-Chain Configuration

This board can be stacked up to three times so that the L6474 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/Davidroid/daisychaintable.png

Platform compatibility

  • NUCLEO boards have been tested with the default configuration provided by the HelloWorld_IHM01A1 example.
  • LPCXpresso11U68 board has been tested with the following patch:
    • to connect with a wire from the LPCX’s D4 pin to the IHM01A1’s D9 pin;
    • to initialize the pwm PinName variable with D4 rather than D9.
  • FRDM-K64F board has been tested with the following patch:
    • to connect with a wire from the FRDM’s D4 pin to the IHM01A1’s D8 pin;
    • to initialize the standby_reset PinName variable with D4 rather than D8.

Example Applications

Revision:
22:ed3a6990a6eb
Parent:
18:2d6ab2b93685
Child:
23:58264db10a17
--- a/Components/l6474/l6474.h	Tue Jan 19 15:57:24 2016 +0000
+++ b/Components/l6474/l6474.h	Tue Feb 09 10:53:31 2016 +0000
@@ -1,42 +1,44 @@
 /**
-  ******************************************************************************
-  * @file    l6474.h 
-  * @author  IPC Rennes
-  * @version V1.5.0
-  * @date    November 12, 2014
-  * @brief   Header for L6474 driver (fully integrated microstepping motor driver)
-  * @note    (C) COPYRIGHT 2014 STMicroelectronics
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
-  *
-  * Redistribution and use in source and binary forms, with or without modification,
-  * are permitted provided that the following conditions are met:
-  *   1. Redistributions of source code must retain the above copyright notice,
-  *      this list of conditions and the following disclaimer.
-  *   2. Redistributions in binary form must reproduce the above copyright notice,
-  *      this list of conditions and the following disclaimer in the documentation
-  *      and/or other materials provided with the distribution.
-  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-  *      may be used to endorse or promote products derived from this software
-  *      without specific prior written permission.
-  *
-  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-  *
-  ******************************************************************************
-  */
+ ******************************************************************************
+ * @file    l6474.h 
+ * @author  IPC Rennes
+ * @version V1.5.0
+ * @date    November 12, 2014
+ * @brief   Header for L6474 driver (fully integrated microstepping motor driver)
+ * @note    (C) COPYRIGHT 2014 STMicroelectronics
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *   1. Redistributions of source code must retain the above copyright notice,
+ *      this list of conditions and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above copyright notice,
+ *      this list of conditions and the following disclaimer in the documentation
+ *      and/or other materials provided with the distribution.
+ *   3. Neither the name of STMicroelectronics nor the names of its contributors
+ *      may be used to endorse or promote products derived from this software
+ *      without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
 
 /* Define to prevent recursive inclusion -------------------------------------*/
+
 #ifndef __L6474_H
 #define __L6474_H
 
@@ -44,23 +46,30 @@
  extern "C" {
 #endif 
 
+
 /* Includes ------------------------------------------------------------------*/
+
 #include "l6474_target_config.h"
 #include "../Common/motor.h"
    
+
+/* Definitions ---------------------------------------------------------------*/
+
 /** @addtogroup BSP
-  * @{
-  */   
-   
+ * @{
+ */
+
+/** @addtogroup Components
+ * @{
+ */  
+  
 /** @addtogroup L6474
-  * @{
-  */   
-   
-/* Exported Constants --------------------------------------------------------*/
-
-/** @defgroup L6474_Exported_Constants
-  * @{
-  */   
+ * @{
+ */
+  
+/** @defgroup L6474_Exported_Defines L6474_Exported_Defines
+ * @{
+ */  
 
 /// Current FW version
 #define L6474_FW_VERSION                        (5)
@@ -80,15 +89,8 @@
 /// L6474 sign bit mask for ABS_POS register
 #define L6474_ABS_POS_SIGN_BIT_MASK ((uint32_t) 0x00200000)
 
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
      
-/* Exported Types  -------------------------------------------------------*/
+/* Types ---------------------------------------------------------------------*/
 
 /** @defgroup L6474_Exported_Types
   * @{
@@ -431,77 +433,94 @@
   L6474_RESERVED_CMD1 = ((uint8_t) 0xEB),
   L6474_RESERVED_CMD2 = ((uint8_t) 0xF8)
 } L6474_Commands_t;
-/**
-  * @}
-  */
 
-/** @defgroup Motor_Driver_Initialization_Structure
-  * @{
-  */
-/// Motor driver initialization structure definition  
+/** 
+ * @brief  L6474 driver initialization structure definition.
+ */
+/* ACTION --------------------------------------------------------------------*
+ * Declare here the component's initialization structure, if any, one         *
+ * variable per line without initialization.                                  *
+ *                                                                            *
+ * Example:                                                                   *
+ *   typedef struct                                                           *
+ *   {                                                                        *
+ *     int frequency;                                                         *
+ *     int update_mode;                                                       *
+ *   } COMPONENT_Init_t;                                                      *
+ *----------------------------------------------------------------------------*/
 typedef struct
 {
-    /* Acceleration rate in step/s2. Range: (0..+inf). */
-    int acceleration_step_s2;
+  /* Acceleration rate in step/s2. Range: (0..+inf). */
+  int acceleration_step_s2;
 
-    /* Deceleration rate in step/s2. Range: (0..+inf). */
-    int deceleration_step_s2;
+  /* Deceleration rate in step/s2. Range: (0..+inf). */
+  int deceleration_step_s2;
 
-    /* Maximum speed in step/s. Range: (30..10000]. */
-    int maximum_speed_step_s;
+  /* Maximum speed in step/s. Range: (30..10000]. */
+  int maximum_speed_step_s;
 
-    /* Minimum speed in step/s. Range: [30..10000). */
-    int minimum_speed_step_s;
+  /* Minimum speed in step/s. Range: [30..10000). */
+  int minimum_speed_step_s;
 
-    /* Torque regulation current in mA. Range: 31.25mA to 4000mA. */
-    float torque_regulation_current_mA;
+  /* Torque regulation current in mA. Range: 31.25mA to 4000mA. */
+  float torque_regulation_current_mA;
 
-    /* Overcurrent threshold (OCD_TH register). */
-    L6474_OCD_TH_t overcurrent_threshold;
+  /* Overcurrent threshold (OCD_TH register). */
+  L6474_OCD_TH_t overcurrent_threshold;
 
-    /* Overcurrent shutwdown (OC_SD field of CONFIG register). */
-    L6474_CONFIG_OC_SD_t overcurrent_shutwdown;
+  /* Overcurrent shutwdown (OC_SD field of CONFIG register). */
+  L6474_CONFIG_OC_SD_t overcurrent_shutwdown;
 
-    /* Torque regulation method (EN_TQREG field of CONFIG register). */
-    L6474_CONFIG_EN_TQREG_t torque_regulation_method;
-    
-    /* Step selection (STEP_SEL field of STEP_MODE register). */
-    L6474_STEP_SEL_t step_selection;
+  /* Torque regulation method (EN_TQREG field of CONFIG register). */
+  L6474_CONFIG_EN_TQREG_t torque_regulation_method;
+  
+  /* Step selection (STEP_SEL field of STEP_MODE register). */
+  L6474_STEP_SEL_t step_selection;
 
-    /* Sync selection (SYNC_SEL field of STEP_MODE register). */
-    L6474_SYNC_SEL_t sync_selection;
+  /* Sync selection (SYNC_SEL field of STEP_MODE register). */
+  L6474_SYNC_SEL_t sync_selection;
 
-    /* Fall time value (T_FAST field of T_FAST register). Range: 2us to 32us. */
-    L6474_FAST_STEP_t fall_time;
+  /* Fall time value (T_FAST field of T_FAST register). Range: 2us to 32us. */
+  L6474_FAST_STEP_t fall_time;
 
-    /* Maximum fast decay time (T_OFF field of T_FAST register). Range: 2us to 32us. */
-    L6474_TOFF_FAST_t maximum_fast_decay_time;
+  /* Maximum fast decay time (T_OFF field of T_FAST register). Range: 2us to 32us. */
+  L6474_TOFF_FAST_t maximum_fast_decay_time;
 
-    /* Minimum ON time in us (TON_MIN register). Range: 0.5us to 64us. */
-    float minimum_ON_time_us;
-
-    /* Minimum OFF time in us (TOFF_MIN register). Range: 0.5us to 64us. */
-    float minimum_OFF_time_us;
+  /* Minimum ON time in us (TON_MIN register). Range: 0.5us to 64us. */
+  float minimum_ON_time_us;
 
-    /* Target Swicthing Period (field TOFF of CONFIG register). */
-    L6474_CONFIG_TOFF_t target_swicthing_period;
+  /* Minimum OFF time in us (TOFF_MIN register). Range: 0.5us to 64us. */
+  float minimum_OFF_time_us;
 
-    /* Slew rate (POW_SR field of CONFIG register). */
-    L6474_CONFIG_POW_SR_t slew_rate;
+  /* Target Swicthing Period (field TOFF of CONFIG register). */
+  L6474_CONFIG_TOFF_t target_swicthing_period;
 
-    /* Clock setting (OSC_CLK_SEL field of CONFIG register). */
-    L6474_CONFIG_OSC_MGMT_t clock;
+  /* Slew rate (POW_SR field of CONFIG register). */
+  L6474_CONFIG_POW_SR_t slew_rate;
 
-    /* Alarm (ALARM_EN register). */
-    int alarm;
-} L6474_InitTypeDef;
-/**
-  * @}
-  */
+  /* Clock setting (OSC_CLK_SEL field of CONFIG register). */
+  L6474_CONFIG_OSC_MGMT_t clock;
+
+  /* Alarm (ALARM_EN register). */
+  int alarm;
+} L6474_Init_t;
 
 /** 
-  * @brief  L6474 driver data structure definition
-  */ 
+ * @brief  L6474 driver data structure definition.
+ */ 
+/* ACTION --------------------------------------------------------------------*
+ * Declare here the structure of component's data, if any, one variable per   *
+ * line without initialization.                                               *
+ *                                                                            *
+ * Example:                                                                   *
+ *   typedef struct                                                           *
+ *   {                                                                        *
+ *       int T0_out;                                                          *
+ *       int T1_out;                                                          *
+ *       float T0_degC;                                                       *
+ *       float T1_degC;                                                       *
+ *   } COMPONENT_Data_t;                                                      *
+ *----------------------------------------------------------------------------*/
 typedef struct
 {
   /// Function pointer to flag interrupt call back
@@ -516,30 +535,36 @@
   uint8_t device_instance;
   uint8_t spiTxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
   uint8_t spiRxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
-} L6474_DrvDataTypeDef;
-/**
-  * @}
-  */
+} L6474_Data_t;
 
 
-/* Exported functions --------------------------------------------------------*/
+/* Functions -----------------------------------------------------------------*/
+
+/** @addtogroup BSP
+ * @{
+ */
 
-/** @defgroup L6474_Exported_Functions
-  * @{
-  */   
+/** @addtogroup Components
+ * @{
+ */
+
+/** @addtogroup L6474
+ * @{
+ */
+
+/** @defgroup L6474_Imported_Functions L6474_Imported_Functions
+ * @{
+ */
 
 /* ACTION --------------------------------------------------------------------*
  * Declare here extern I/O and interrupt related functions you might need,    *
  * and implemented then in a glue logic file on the target environment, for   *
- * example within the "x_nucleo_<board>.c" file., e.g.:                       *
- *   extern DrvStatusTypeDef COMPONENT_IO_Init (void *handle);                *
- *   extern DrvStatusTypeDef COMPONENT_IO_Read (handle, buf, regadd, bytes);  *
- *   extern DrvStatusTypeDef COMPONENT_IO_Write(handle, buf, regadd, bytes);  *
- *   extern void COMPONENT_IO_ITConfig(void);                                 *
+ * example within the "x_nucleo_board.c" file., e.g.:                         *
+ *   extern Status_t COMPONENT_IO_Init (void *handle);                        *
+ *   extern Status_t COMPONENT_IO_Read (handle, buf, regadd, bytes);          *
+ *   extern Status_t COMPONENT_IO_Write(handle, buf, regadd, bytes);          *
+ *   extern void     COMPONENT_IO_ITConfig(void);                             *
  *----------------------------------------------------------------------------*/
-/** @defgroup MotorControl_Board_Linked_Functions
-  * @{
-  */   
 ///Delay of the requested number of milliseconds
 extern void L6474_Delay(void *handle, uint32_t delay);     
 ///Enable Irq
@@ -565,27 +590,10 @@
 ///Write bytes to the L6474s via SPI
 extern uint8_t L6474_SpiWriteBytes(void *handle, uint8_t *pByteToTransmit, uint8_t *pReceivedByte);
 
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-
-/**
-  * @}
-  */
-
 #ifdef __cplusplus
   }
 #endif
 
 #endif /* #ifndef __L6474_H */
 
-
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/