hw_stepper.h

Go to the documentation of this file.
00001 
00041 #ifndef HW_STEPPER_H
00042 #define HW_STEPPER_H
00043 
00044 #include <hw/hw_cpufreq.h>
00045 
00046 #include <cfg/macros.h>
00047 
00048 #include <drv/timer.h>
00049 
00050 #warning TODO:This is an example implentation, you must implement it!
00051 
00052 #define STEPPER_STROBE_INIT \
00053 do { \
00054         /* put init code for strobe */ \
00055 } while (0)
00056 
00057 
00058 #define STEPPER_STROBE_ON       do { /* Implement me! */ } while(0)
00059 #define STEPPER_STROBE_OFF      do { /* Implement me! */ } while(0)
00060 
00065 #define STEPPER_PRESCALER_LOG2    1
00066 
00070 #define STEPPER_CLOCK ((CPU_FREQ) >> STEPPER_PRESCALER_LOG2)
00071 
00077 #define STEPPER_RESET_DELAY 1
00078 
00079 /*
00080  * Pins define for each stepper
00081  */
00082 #define STEPPER_1_CW_CCW_PIN             0
00083 #define STEPPER_1_HALF_FULL_PIN          0
00084 #define STEPPER_1_CONTROL_PIN            0
00085 #define STEPPER_1_ENABLE_PIN             0
00086 #define STEPPER_1_RESET_PIN              0
00087 
00088 /* put here other stepper motor */
00089 
00090 #define STEPPER_1_SET            do { /* Implement me! */ } while(0)
00091 /* add here the set for other stepper motor */
00092 
00093 #define STEPPER_1_CLEAR          do { /* Implement me! */ } while(0)
00094 /* add here the clear for other stepper motor */
00095 
00096 /*
00097  * Generic macro definition
00098  */
00099 
00100 /*
00101  * Stepper init macro
00102  */
00103 #define STEPPER_PIN_INIT_MACRO(port, index) do { \
00104         /* Add here init pin code */ \
00105     } while (0)
00106 
00107 /*
00108  * Stepper commands macros
00109  */
00110 #define STEPPER_SET_CW(index)             do { /* Implement me! */ } while (0)
00111 #define STEPPER_SET_CCW(index)            do { /* Implement me! */ } while (0)
00112 #define STEPPER_SET_HALF(index)           do { /* Implement me! */ } while (0)
00113 #define STEPPER_SET_FULL(index)           do { /* Implement me! */ } while (0)
00114 #define STEPPER_SET_CONTROL_LOW(index)    do { /* Implement me! */ } while (0)
00115 #define STEPPER_SET_CONTROL_HIGHT(index)  do { /* Implement me! */ } while (0)
00116 #define STEPPER_SET_ENABLE(index)         do { /* Implement me! */ } while (0)
00117 #define STEPPER_SET_DISABLE(index)        do { /* Implement me! */ } while (0)
00118 #define STEPPER_SET_RESET_ENABLE(index)   do { /* Implement me! */ } while (0)
00119 #define STEPPER_SET_RESET_DISABLE(index)  do { /* Implement me! */ } while (0)
00120 
00121 
00122 /*
00123  * Reset stepper macro
00124  */
00125 
00126 #define STEPPER_RESET_MACRO(index) do { \
00127         STEPPER_SET_RESET_ENABLE(index); \
00128         timer_udelay(STEPPER_RESET_DELAY); \
00129         STEPPER_SET_RESET_DISABLE(index); \
00130     } while (0)
00131 
00132 /*
00133  * Set half or full step macro
00134  */
00135 #define STEPPER_SET_STEP_MODE_MACRO(index, flag) do { \
00136         if (flag) \
00137             STEPPER_SET_HALF(index); \
00138         else \
00139             STEPPER_SET_FULL(index); \
00140     } while (0)
00141 
00142 /*
00143  * Set control status macro
00144  */
00145 #warning TODO: This macro is not implemented (see below)
00146 
00147 #define STEPPER_SET_CONTROL_BIT_MACRO(index, flag) do { \
00148         /* if (flag) */ \
00149             /* WARNING This macros not implemented */ \
00150         /* else */ \
00151             /* WARNING This macros not implemented */ \
00152     } while (0)
00153 
00154 /*
00155  * Set current power macro
00156  */
00157 #warning TODO: This macro is not implemented (see below)
00158 
00159 #define STEPPER_SET_POWER_CURRENT_MACRO(index, flag) do { \
00160         /* if (flag) */ \
00161             /* WARNING This macrois not implemented */ \
00162         /* else */ \
00163             /* WARNING This macrois not implemented */ \
00164     } while (0)
00165 
00166 /*
00167  * Set rotation of stepper motor
00168  * - dir = 1: positive rotation
00169  * - dir = 0: no motor moviment
00170  * - dir = -1: negative rotation
00171  *
00172  */
00173 #define STEPPER_SET_DIRECTION_MACRO(index, dir) do { \
00174         switch (dir) \
00175         { \
00176         case 1: \
00177             STEPPER_SET_CW(index); \
00178             break; \
00179         case -1: \
00180             STEPPER_SET_CCW(index); \
00181             break; \
00182         case 0: \
00183             break; \
00184         } \
00185     } while (0)
00186 
00187 
00188 /*
00189  * Define macros for manage low level of stepper.
00190  */
00191 
00192 #define STEPPER_INIT()  do { \
00193         STEPPER_PIN_INIT_MACRO(A, 1); \
00194         /* Add here code for other stepper motor */ \
00195     } while (0)
00196 
00197 
00198 /*
00199  * Enable select stepper motor
00200  */
00201 #define STEPPER_ENABLE(index) do { \
00202         switch (index) \
00203         { \
00204         case 1: \
00205             STEPPER_SET_ENABLE(1); \
00206             break; \
00207             /* Add here code for other stepper motor */ \
00208         } \
00209     } while (0)
00210 
00211 /*
00212  * Enable all stepper connect to micro
00213  */
00214 #define STEPPER_ENABLE_ALL() do { \
00215         STEPPER_SET_ENABLE(1); \
00216         /* Add here code for other stepper motor */ \
00217     } while (0)
00218 
00219 /*
00220  * Disable select stepper motor
00221  */
00222 #define STEPPER_DISABLE(index) do { \
00223         switch (index) \
00224         { \
00225         case 1: \
00226             STEPPER_SET_DISABLE(1); \
00227             break; \
00228             /* Add here code for other stepper motor */ \
00229         } \
00230     } while (0)
00231 
00232 /*
00233  * Disable all stepper connect to micro
00234  */
00235 #define STEPPER_DISABLE_ALL() do { \
00236         STEPPER_SET_DISABLE(1); \
00237         /* Add here code for other stepper motor */ \
00238     } while (0)
00239 
00240 /*
00241  * Reset selected stepper motor
00242  */
00243 #define STEPPER_RESET(index) do { \
00244         switch (index) \
00245         { \
00246         case 1: \
00247             STEPPER_RESET_MACRO(1); \
00248             break; \
00249             /* Add here code for other stepper motor */ \
00250         } \
00251     } while (0)
00252 
00253 /*
00254  * Reset all stepper motor
00255  */
00256 #define STEPPER_RESET_ALL() do { \
00257         STEPPER_RESET_MACRO(1) \
00258         /* Add here code for other stepper motor */ \
00259     } while (0)
00260 
00261 // Set half/full step macros
00262 #define STEPPER_SET_HALF_STEP(index, flag) do { \
00263         switch (index) \
00264         { \
00265         case 1: \
00266             STEPPER_SET_STEP_MODE_MACRO(1, flag); \
00267             break; \
00268             /* Add here code for other stepper motor */ \
00269         } \
00270     } while (0)
00271 
00272 
00273 // Control status
00274 #define STEPPER_SET_CONTROL_BIT(index, flag) do { \
00275         switch (index) \
00276         { \
00277         case 1: \
00278             STEPPER_SET_CONTROL_BIT_MACRO(1, flag); \
00279             break; \
00280             /* Add here code for other stepper motor */ \
00281         } \
00282     } while (0)
00283 
00284 
00285 // Set stepper power current
00286 #define STEPPER_SET_POWER_CURRENT(index, flag) do { \
00287         switch (index) \
00288         { \
00289         case 1: \
00290             STEPPER_SET_POWER_CURRENT_MACRO(1, flag); \
00291             break; \
00292             /* Add here code for other stepper motor */ \
00293         } \
00294     } while (0)
00295 
00296 // Set rotation dirction of stepper motor
00297 #define STEPPER_SET_DIRECTION(index, dir) do { \
00298         switch (index) \
00299         { \
00300         case 1: \
00301             STEPPER_SET_DIRECTION_MACRO(1, dir); \
00302             break; \
00303             /* Add here code for other stepper motor */ \
00304         } \
00305     } while (0)
00306 
00307 #endif /* HW_STEPPER_H */
00308 
00309