X-CUBE-SPN1-20150128 example source code for one motor compiled under mbed. Tested OK on Nucleo F401. l6474.cpp is modified from original with defines in l6474_target_config.h to select the original behaviour (motor de-energised when halted), or new mode to continue powering with a (reduced) current in the coils (braking/position hold capability). On F401 avoid using mbed's InterruptIn on pins 10-15 (any port). Beware of other conflicts! L0 & F0 are included but untested.
l6474_target_config.h
00001 /**************************************************************************//** 00002 * @file l6474_target_config.h 00003 * @author IPC Rennes 00004 * @version V1.5.0 00005 * @date November 12, 2014 00006 * @brief Predefines values for the L6474 registers 00007 * and for the devices parameters 00008 * @note (C) COPYRIGHT 2014 STMicroelectronics 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Define to prevent recursive inclusion -------------------------------------*/ 00040 #ifndef __L6474_TARGET_CONFIG_H 00041 #define __L6474_TARGET_CONFIG_H 00042 00043 #ifdef __cplusplus 00044 extern "C" { 00045 #endif 00046 00047 /** @addtogroup BSP 00048 * @{ 00049 */ 00050 00051 /** @addtogroup L6474 00052 * @{ 00053 */ 00054 00055 /** @addtogroup L6474_Exported_Constants 00056 * @{ 00057 */ 00058 00059 /** @defgroup Predefined_L6474_Registers_Values 00060 * @{ 00061 */ 00062 00063 00064 /// The maximum number of devices in the daisy chain 00065 #define MAX_NUMBER_OF_DEVICES (3) 00066 00067 /************** Motor Energised When Halted or Not ********************/ 00068 00069 /// Switch behaviour: motors de-energised when halted, or energised/braked. 00070 #define L6474_CONF_BRAKE_WHEN_HALTED 00071 /// Reduced motor current, eg half power when halted. 00072 #define L6474_CONF_BRAKE_CURRENT_FACTOR (2) 00073 00074 /************************ Speed Profile *******************************/ 00075 00076 /// Acceleration rate in step/s2 for device 0 (must be greater than 0) 00077 #define L6474_CONF_PARAM_ACC_DEVICE_0 (160) 00078 /// Acceleration rate in step/s2 for device 1 (must be greater than 0) 00079 #define L6474_CONF_PARAM_ACC_DEVICE_1 (160) 00080 /// Acceleration rate in step/s2 for device 2 (must be greater than 0) 00081 #define L6474_CONF_PARAM_ACC_DEVICE_2 (160) 00082 00083 /// Deceleration rate in step/s2 for device 0 (must be greater than 0) 00084 #define L6474_CONF_PARAM_DEC_DEVICE_0 (160) 00085 /// Deceleration rate in step/s2 for device 1 (must be greater than 0) 00086 #define L6474_CONF_PARAM_DEC_DEVICE_1 (160) 00087 /// Deceleration rate in step/s2 for device 2 (must be greater than 0) 00088 #define L6474_CONF_PARAM_DEC_DEVICE_2 (160) 00089 00090 /// Maximum speed in step/s for device 0 (30 step/s < Maximum speed <= 10 000 step/s ) 00091 #define L6474_CONF_PARAM_MAX_SPEED_DEVICE_0 (1600) 00092 /// Maximum speed in step/s for device 1 (30 step/s < Maximum speed <= 10 000 step/s ) 00093 #define L6474_CONF_PARAM_MAX_SPEED_DEVICE_1 (1600) 00094 /// Maximum speed in step/s for device 2 (30 step/s < Maximum speed <= 10 000 step/s ) 00095 #define L6474_CONF_PARAM_MAX_SPEED_DEVICE_2 (1600) 00096 00097 /// Minimum speed in step/s for device 0 (30 step/s <= Minimum speed < 10 000 step/s) 00098 #define L6474_CONF_PARAM_MIN_SPEED_DEVICE_0 (800) 00099 /// Minimum speed in step/s for device 1 (30 step/s <= Minimum speed < 10 000 step/s) 00100 #define L6474_CONF_PARAM_MIN_SPEED_DEVICE_1 (800) 00101 /// Minimum speed in step/s for device 2 (30 step/s <= Minimum speed < 10 000 step/s) 00102 #define L6474_CONF_PARAM_MIN_SPEED_DEVICE_2 (800) 00103 00104 00105 /************************ Phase Current Control *******************************/ 00106 00107 // Current value that is assigned to the torque regulation DAC 00108 /// TVAL register value for device 0 (range 31.25mA to 4000mA) 00109 #define L6474_CONF_PARAM_TVAL_DEVICE_0 (250) 00110 /// TVAL register value for device 1 (range 31.25mA to 4000mA) 00111 #define L6474_CONF_PARAM_TVAL_DEVICE_1 (250) 00112 /// TVAL register value for device 2 (range 31.25mA to 4000mA) 00113 #define L6474_CONF_PARAM_TVAL_DEVICE_2 (250) 00114 00115 /// Fall time value (T_FAST field of T_FAST register) for device 0 (range 2us to 32us) 00116 #define L6474_CONF_PARAM_FAST_STEP_DEVICE_0 (L6474_FAST_STEP_12us) 00117 /// Fall time value (T_FAST field of T_FAST register) for device 1 (range 2us to 32us) 00118 #define L6474_CONF_PARAM_FAST_STEP_DEVICE_1 (L6474_FAST_STEP_12us) 00119 /// Fall time value (T_FAST field of T_FAST register) for device 2 (range 2us to 32us) 00120 #define L6474_CONF_PARAM_FAST_STEP_DEVICE_2 (L6474_FAST_STEP_12us) 00121 00122 /// Maximum fast decay time (T_OFF field of T_FAST register) for device 0 (range 2us to 32us) 00123 #define L6474_CONF_PARAM_TOFF_FAST_DEVICE_0 (L6474_TOFF_FAST_8us) 00124 /// Maximum fast decay time (T_OFF field of T_FAST register) for device 1 (range 2us to 32us) 00125 #define L6474_CONF_PARAM_TOFF_FAST_DEVICE_1 (L6474_TOFF_FAST_8us) 00126 /// Maximum fast decay time (T_OFF field of T_FAST register) for device 2 (range 2us to 32us) 00127 #define L6474_CONF_PARAM_TOFF_FAST_DEVICE_2 (L6474_TOFF_FAST_8us) 00128 00129 /// Minimum ON time (TON_MIN register) for device 0 (range 0.5us to 64us) 00130 #define L6474_CONF_PARAM_TON_MIN_DEVICE_0 (3) 00131 /// Minimum ON time (TON_MIN register) for device 1 (range 0.5us to 64us) 00132 #define L6474_CONF_PARAM_TON_MIN_DEVICE_1 (3) 00133 /// Minimum ON time (TON_MIN register) for device 2 (range 0.5us to 64us) 00134 #define L6474_CONF_PARAM_TON_MIN_DEVICE_2 (3) 00135 00136 /// Minimum OFF time (TOFF_MIN register) for device 0 (range 0.5us to 64us) 00137 #define L6474_CONF_PARAM_TOFF_MIN_DEVICE_0 (21) 00138 /// Minimum OFF time (TOFF_MIN register) for device 1 (range 0.5us to 64us) 00139 #define L6474_CONF_PARAM_TOFF_MIN_DEVICE_1 (21) 00140 /// Minimum OFF time (TOFF_MIN register) for device 2 (range 0.5us to 64us) 00141 #define L6474_CONF_PARAM_TOFF_MIN_DEVICE_2 (21) 00142 00143 /******************************* Others ***************************************/ 00144 00145 /// Overcurrent threshold settings for device 0 (OCD_TH register) 00146 #define L6474_CONF_PARAM_OCD_TH_DEVICE_0 (L6474_OCD_TH_750mA) 00147 /// Overcurrent threshold settings for device 1 (OCD_TH register) 00148 #define L6474_CONF_PARAM_OCD_TH_DEVICE_1 (L6474_OCD_TH_750mA) 00149 /// Overcurrent threshold settings for device 2 (OCD_TH register) 00150 #define L6474_CONF_PARAM_OCD_TH_DEVICE_2 (L6474_OCD_TH_750mA) 00151 00152 /// Alarm settings for device 0 (ALARM_EN register) 00153 #define L6474_CONF_PARAM_ALARM_EN_DEVICE_0 (L6474_ALARM_EN_OVERCURRENT |\ 00154 L6474_ALARM_EN_THERMAL_SHUTDOWN |\ 00155 L6474_ALARM_EN_THERMAL_WARNING |\ 00156 L6474_ALARM_EN_UNDERVOLTAGE |\ 00157 L6474_ALARM_EN_SW_TURN_ON |\ 00158 L6474_ALARM_EN_WRONG_NPERF_CMD) 00159 00160 ///Alarm settings for device 1 (ALARM_EN register) 00161 #define L6474_CONF_PARAM_ALARM_EN_DEVICE_1 (L6474_ALARM_EN_OVERCURRENT |\ 00162 L6474_ALARM_EN_THERMAL_SHUTDOWN |\ 00163 L6474_ALARM_EN_THERMAL_WARNING |\ 00164 L6474_ALARM_EN_UNDERVOLTAGE |\ 00165 L6474_ALARM_EN_SW_TURN_ON |\ 00166 L6474_ALARM_EN_WRONG_NPERF_CMD) 00167 00168 /// Alarm settings for device 2 (ALARM_EN register) 00169 #define L6474_CONF_PARAM_ALARM_EN_DEVICE_2 (L6474_ALARM_EN_OVERCURRENT |\ 00170 L6474_ALARM_EN_THERMAL_SHUTDOWN |\ 00171 L6474_ALARM_EN_THERMAL_WARNING |\ 00172 L6474_ALARM_EN_UNDERVOLTAGE |\ 00173 L6474_ALARM_EN_SW_TURN_ON |\ 00174 L6474_ALARM_EN_WRONG_NPERF_CMD) 00175 00176 /// Step selection settings for device 0 (STEP_SEL field of STEP_MODE register) 00177 #define L6474_CONF_PARAM_STEP_SEL_DEVICE_0 (L6474_STEP_SEL_1_16) 00178 /// Step selection settings for device 1 (STEP_SEL field of STEP_MODE register) 00179 #define L6474_CONF_PARAM_STEP_SEL_DEVICE_1 (L6474_STEP_SEL_1_16) 00180 /// Step selection settings for device 2 (STEP_SEL field of STEP_MODE register) 00181 #define L6474_CONF_PARAM_STEP_SEL_DEVICE_2 (L6474_STEP_SEL_1_16) 00182 00183 /// Synch. selection settings for device 0 (SYNC_SEL field of STEP_MODE register) 00184 #define L6474_CONF_PARAM_SYNC_SEL_DEVICE_0 (L6474_SYNC_SEL_1_2) 00185 /// Synch. selection settings for device 1 (SYNC_SEL field of STEP_MODE register) 00186 #define L6474_CONF_PARAM_SYNC_SEL_DEVICE_1 (L6474_SYNC_SEL_1_2) 00187 /// Synch. selection settings for device 2 (SYNC_SEL field of STEP_MODE register) 00188 #define L6474_CONF_PARAM_SYNC_SEL_DEVICE_2 (L6474_SYNC_SEL_1_2) 00189 00190 /// Target Swicthing Period for device 0 (field TOFF of CONFIG register) 00191 #define L6474_CONF_PARAM_TOFF_DEVICE_0 (L6474_CONFIG_TOFF_044us) 00192 /// Target Swicthing Period for device 1 (field TOFF of CONFIG register) 00193 #define L6474_CONF_PARAM_TOFF_DEVICE_1 (L6474_CONFIG_TOFF_044us) 00194 /// Target Swicthing Period for device 2 (field TOFF of CONFIG register) 00195 #define L6474_CONF_PARAM_TOFF_DEVICE_2 (L6474_CONFIG_TOFF_044us) 00196 00197 /// Slew rate for device 0 (POW_SR field of CONFIG register) 00198 #define L6474_CONF_PARAM_SR_DEVICE_0 (L6474_CONFIG_SR_320V_us) 00199 /// Slew rate for device 1 (POW_SR field of CONFIG register) 00200 #define L6474_CONF_PARAM_SR_DEVICE_1 (L6474_CONFIG_SR_320V_us) 00201 /// Slew rate for device 2 (POW_SR field of CONFIG register) 00202 #define L6474_CONF_PARAM_SR_DEVICE_2 (L6474_CONFIG_SR_320V_us) 00203 00204 /// Over current shutwdown enabling for device 0 (OC_SD field of CONFIG register) 00205 #define L6474_CONF_PARAM_OC_SD_DEVICE_0 (L6474_CONFIG_OC_SD_ENABLE) 00206 /// Over current shutwdown enabling for device 1 (OC_SD field of CONFIG register) 00207 #define L6474_CONF_PARAM_OC_SD_DEVICE_1 (L6474_CONFIG_OC_SD_ENABLE) 00208 /// Over current shutwdown enabling for device 2 (OC_SD field of CONFIG register) 00209 #define L6474_CONF_PARAM_OC_SD_DEVICE_2 (L6474_CONFIG_OC_SD_ENABLE) 00210 00211 /// Torque regulation method for device 0 (EN_TQREG field of CONFIG register) 00212 #define L6474_CONF_PARAM_TQ_REG_DEVICE_0 (L6474_CONFIG_EN_TQREG_TVAL_USED) 00213 ///Torque regulation method for device 1 (EN_TQREG field of CONFIG register) 00214 #define L6474_CONF_PARAM_TQ_REG_DEVICE_1 (L6474_CONFIG_EN_TQREG_TVAL_USED) 00215 /// Torque regulation method for device 2 (EN_TQREG field of CONFIG register) 00216 #define L6474_CONF_PARAM_TQ_REG_DEVICE_2 (L6474_CONFIG_EN_TQREG_TVAL_USED) 00217 00218 /// Clock setting for device 0 (OSC_CLK_SEL field of CONFIG register) 00219 #define L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_0 (L6474_CONFIG_INT_16MHZ) 00220 /// Clock setting for device 1 (OSC_CLK_SEL field of CONFIG register) 00221 #define L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_1 (L6474_CONFIG_INT_16MHZ) 00222 /// Clock setting for device 2 (OSC_CLK_SEL field of CONFIG register) 00223 #define L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_2 (L6474_CONFIG_INT_16MHZ) 00224 00225 00226 /** 00227 * @} 00228 */ 00229 00230 /** 00231 * @} 00232 */ 00233 00234 /** 00235 * @} 00236 */ 00237 00238 /** 00239 * @} 00240 */ 00241 00242 #ifdef __cplusplus 00243 } 00244 #endif 00245 00246 #endif /* __L6474_TARGET_CONFIG_H */
Generated on Tue Jul 12 2022 22:53:31 by 1.7.2