Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
smc.h
00001 /** 00002 * @file SMC.h 00003 * @brief Stepper motor control module 00004 * 00005 * @author Jeroen Lodder 00006 * @date Oktober 2013 00007 * 00008 * @{ 00009 */ 00010 #ifndef StepperMotorControl_H_ 00011 #define StepperMotorControl_H_ 00012 00013 #include <stdint.h> 00014 00015 /** 00016 * @brief Motor control microstepping with Sine or Triangle 00017 * @{ 00018 */ 00019 #define LUT_SINE 1 00020 #define LUT_TRIANGLE 0 00021 #if (LUT_SINE == LUT_TRIANGLE) 00022 #error At least one LUT needs to Enabled or Disabled, not both. 00023 #endif 00024 /** 00025 * @} 00026 */ 00027 00028 /* Api */ 00029 void SMC_init(void); 00030 int SMC_step(int steps, uint8_t dir, uint32_t time_ms, uint8_t free); 00031 uint32_t SMC_idle(void); 00032 void SMC_deinit(void); 00033 void SMC_brake(void); 00034 void SMC_free(void); 00035 void SMC_pause(void); 00036 void SMC_continue(void); 00037 int SMC_getState(void); 00038 void SMC_egg(void); 00039 00040 /* Example of MOSFET bridges 00041 * ------------------------ V+ 00042 * | | | | 00043 * \H1 \H2 \H3 \H4 00044 * |--MA--| |--MB--| 00045 * \L1 \L2 \L3 \L4 00046 * | | | | 00047 * ------------------------ V- 00048 */ 00049 00050 /** 00051 * @brief Motor control lookup tables 00052 * @{ 00053 */ 00054 const uint16_t LUT_H1[32] = { 00055 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 00056 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 00057 }; 00058 00059 const uint16_t LUT_H2[32] = { 00060 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 00061 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 00062 }; 00063 00064 const uint16_t LUT_H3[32] = { 00065 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, 00066 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1 00067 }; 00068 00069 const uint16_t LUT_H4[32] = { 00070 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1, 00071 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, 00072 }; 00073 00074 #if (LUT_SINE == 1) 00075 const uint16_t LUT_L1[32] = { 00076 0 ,102 ,194 ,286 , 00077 363 ,424 ,471 ,501 , 00078 512 ,501 ,471 ,424 , 00079 363 ,286 ,194 ,102 , 00080 0 ,0 ,0 ,0 , 00081 0 ,0 ,0 ,0 , 00082 0 ,0 ,0 ,0 , 00083 0 ,0 ,0 ,0 00084 }; 00085 00086 const uint16_t LUT_L2[32] = { 00087 0 ,0 ,0 ,0 , 00088 0 ,0 ,0 ,0 , 00089 0 ,0 ,0 ,0 , 00090 0 ,0 ,0 ,0 , 00091 0 ,102 ,194,286 , 00092 363 ,424 ,471 ,501 , 00093 512 ,501 ,471 ,424 , 00094 363 ,286 ,194 ,102. 00095 }; 00096 00097 const uint16_t LUT_L3[32] = { 00098 0 ,0 ,0 ,0 , 00099 0 ,0 ,0 ,0 , 00100 0 ,102 ,194 ,286 , 00101 363 ,424 ,471 ,501 , 00102 512 ,501 ,471 ,424 , 00103 363 ,286 ,194 ,102 , 00104 0 ,0 ,0 ,0 , 00105 0 ,0 ,0 ,0 00106 }; 00107 00108 const uint16_t LUT_L4[32] = { 00109 512 ,501,471 ,424 , 00110 363 ,286,194 ,102 , 00111 0 ,0 ,0 ,0 , 00112 0 ,0 ,0 ,0 , 00113 0 ,0 ,0 ,0 , 00114 0 ,0 ,0 ,0 , 00115 0 ,102,194 ,286 , 00116 363 ,424,471 ,501 00117 }; 00118 #endif // LUT_SINE 00119 #if (LUT_TRIANGLE == 1) 00120 const uint16_t LUT_L1[32] = { 00121 0 , 00122 64 , 00123 128, 00124 192, 00125 256, 00126 320, 00127 384, 00128 448, 00129 512, 00130 448, 00131 384, 00132 320, 00133 256, 00134 192, 00135 128, 00136 64 , 00137 0 , 00138 0 , 00139 0 , 00140 0 , 00141 0 , 00142 0 , 00143 0 , 00144 0 , 00145 0 , 00146 0 , 00147 0 , 00148 0 , 00149 0 , 00150 0 , 00151 0 , 00152 0 00153 }; 00154 00155 const uint16_t LUT_L2[32] = { 00156 0 , 00157 0 , 00158 0 , 00159 0 , 00160 0 , 00161 0 , 00162 0 , 00163 0 , 00164 0 , 00165 0 , 00166 0 , 00167 0 , 00168 0 , 00169 0 , 00170 0 , 00171 0 , 00172 0 , 00173 64 , 00174 128, 00175 192, 00176 256, 00177 320, 00178 384, 00179 448, 00180 512, 00181 448, 00182 384, 00183 320, 00184 256, 00185 192, 00186 128, 00187 64 00188 }; 00189 00190 const uint16_t LUT_L3[32] = { 00191 0 , 00192 0 , 00193 0 , 00194 0 , 00195 0 , 00196 0 , 00197 0 , 00198 0 , 00199 0 , 00200 64 , 00201 128, 00202 192, 00203 256, 00204 320, 00205 384, 00206 448, 00207 512, 00208 448, 00209 384, 00210 320, 00211 256, 00212 192, 00213 128, 00214 64 , 00215 0 , 00216 0 , 00217 0 , 00218 0 , 00219 0 , 00220 0 , 00221 0 , 00222 0 00223 }; 00224 00225 const uint16_t LUT_L4[32] = { 00226 512, 00227 448, 00228 384, 00229 320, 00230 256, 00231 192, 00232 128, 00233 64 , 00234 0 , 00235 0 , 00236 0 , 00237 0 , 00238 0 , 00239 0 , 00240 0 , 00241 0 , 00242 0 , 00243 0 , 00244 0 , 00245 0 , 00246 0 , 00247 0 , 00248 0 , 00249 0 , 00250 0 , 00251 64 , 00252 128, 00253 192, 00254 256, 00255 320, 00256 384, 00257 448 00258 }; 00259 #endif //LUT_TRIANGLE 00260 /** 00261 * @} 00262 */ 00263 #endif //StepperMotorControl_H_ 00264 /** 00265 *@} 00266 */ 00267
Generated on Mon Jul 18 2022 01:28:39 by
1.7.2