00001 00012 #include "config.h" 00013 #include "config_motor.h" 00014 00015 #include "mc_interface.h" 00016 #include "mc_control.h" 00017 #include "mc_drv.h" 00018 00019 void mc_ramp_up_init(void); 00020 00021 Bool mci_direction = CW; 00022 Bool mci_run_stop = STOP; 00023 U8 mci_cmd_speed = 0; 00024 00025 U8 mci_measured_speed = 0; 00026 U32 mci_measured_current = 0; 00027 U8 mci_potentiometer_value = 0; 00028 00029 00036 Bool mci_motor_is_running(void) 00037 { 00038 return mci_run_stop; 00039 } 00040 00041 00048 void mc_motor_init() 00049 { 00050 mc_init_HW(); 00051 mc_init_SW(); 00052 00053 mci_stop(); 00054 mci_store_measured_speed(0); 00055 } 00056 00057 /* 00058 * @brief speed modification 00059 * @pre initialization of motor 00060 * @post new value of speed 00061 */ 00062 void mci_set_motor_speed(U8 speed) 00063 { 00064 mci_cmd_speed = speed; 00065 } 00066 00067 /* 00068 * @brief speed visualization 00069 * @pre initialization of motor 00070 * @post get speed value 00071 */ 00072 U8 mci_get_motor_speed(void) 00073 { 00074 return mci_cmd_speed; 00075 } 00076 00077 /* 00078 * @brief direction modification 00079 * @pre initialization of motor 00080 * @post new value of direction 00081 */ 00082 void mci_set_motor_direction(U8 direction) 00083 { 00084 // if ((mci_direction == CW) || (mci_direction == CCW)) mci_direction = direction; 00085 mci_direction = direction; 00086 } 00087 00088 /* 00089 * @brief set the direction in CW 00090 * @pre initialization of motor 00091 * @post new value of direction 00092 */ 00093 void mci_forward(void) 00094 { 00095 mci_direction = CW; 00096 } 00097 00098 /* 00099 * @brief set the direction in CCW 00100 * @pre initialization of motor 00101 * @post new value of direction 00102 */ 00103 void mci_backward(void) 00104 { 00105 mci_direction = CCW; 00106 } 00107 00108 /* 00109 * @brief direction visualization 00110 * @pre initialization of motor 00111 * @post get direction value 00112 */ 00113 /* U8 mci_get_motor_direction(void) 00114 { 00115 return mci_direction; 00116 } */ 00117 00123 void mci_store_measured_speed(U8 measured_speed) 00124 { 00125 mci_measured_speed = measured_speed; 00126 } 00127 00134 U8 mci_get_measured_speed(void) 00135 { 00136 return mci_measured_speed; 00137 } 00138 00144 U16 mci_get_measured_current(void) 00145 { 00146 /* U16 value_to_return; 00147 value_to_return = mci_measured_current>>6; 00148 if (value_to_return > 994) 00149 { 00150 value_to_return = value_to_return - 994; 00151 } 00152 else 00153 { 00154 value_to_return = 994 - value_to_return; 00155 } 00156 return value_to_return;*/ 00157 return mci_measured_current; 00158 } 00159 00165 void mci_store_measured_current(U16 current) 00166 { 00167 mci_measured_current = ((63*mci_measured_current)+(64*current))>>6; 00168 } 00169 00175 U8 mci_get_potentiometer_value(void) 00176 { 00177 return mci_potentiometer_value; 00178 } 00179 00185 void mci_store_potentiometer_value(U8 potentiometer) 00186 { 00187 mci_potentiometer_value = potentiometer; 00188 } 00189 00196 void mci_run(void) 00197 { 00198 mc_motor_init(); // launch initialization of the motor 00199 mci_run_stop = RUN; 00200 mci_set_motor_speed(DUTY_RAMP_UP); /* set a speed for the ramp-up */ 00201 mc_set_Open_Loop(); /* set the regulation type */ 00202 mc_regulation_loop(); /* execute the regulation one time */ 00203 mc_ramp_up_init(); 00204 PSC_Run(); 00205 } 00206 00207 void mci_stop(void) 00208 { 00209 PSC_Stop(); 00210 mci_run_stop = STOP; 00211 } 00212 00213 00214 void mci_set_speed(U16 speed) 00215 { 00216 mci_set_motor_speed((U8)speed); 00217 } 00218
1.4.7