00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 //_____ I N C L U D E S ___________________________________________________ 00013 #include "config.h" 00014 00015 #include "mc_interface.h" 00016 #include "mc_control.h" 00017 #include "mc_drv.h" 00018 00019 00020 Bool mci_direction = CW; 00021 Bool mci_run_stop = FALSE; 00022 U8 mc_cmd_speed = 0; 00023 00024 U8 mc_measured_speed = 0; 00025 U32 mci_measured_current = 0; 00026 U8 mc_potentiometer_value = 0; 00027 00034 void mci_run(void) 00035 { 00036 /* TL: TO BE MODIFIED 00037 if (!(PCTL2 & (1<<PRUN2))) // if there is an overcurrent 00038 { 00039 PSC0_Init(255,0,1,0); 00040 PSC1_Init(255,0,1,0); 00041 PSC2_Init(255,0,1,0); 00042 } 00043 */ 00044 mci_run_stop = TRUE; 00045 mc_regulation_loop(); 00046 mc_duty_cycle(mc_get_Duty_Cycle()); 00047 mc_switch_commutation(mc_get_hall()); 00048 mc_disable_during_inrush(); /* disable overcurrent during inrush */ 00049 } 00050 00057 void mci_retry_run(void) 00058 { 00059 mci_run_stop = TRUE; 00060 mc_regulation_loop(); 00061 mc_duty_cycle(mc_get_Duty_Cycle()); 00062 mc_switch_commutation(mc_get_hall()); 00063 mc_disable_during_inrush(); /* disable overcurrent during inrush */ 00064 } 00065 00072 Bool mc_motor_is_running(void) 00073 { 00074 return mci_run_stop; 00075 } 00076 00083 void mci_stop(void) 00084 { 00085 mci_run_stop=FALSE; 00086 } 00087 00094 void mc_init() 00095 { 00096 mc_init_HW(); 00097 Enable_interrupt(); 00098 00099 mci_stop(); 00100 mci_forward(); 00101 mci_set_motor_speed(0); 00102 mc_set_motor_measured_speed(0); 00103 } 00104 00105 /* 00106 * @brief speed modification 00107 * @pre initialization of motor 00108 * @post new value of speed 00109 */ 00110 void mci_set_motor_speed(U8 speed) 00111 { 00112 mc_cmd_speed = speed; 00113 } 00114 00115 /* 00116 * @brief speed visualization 00117 * @pre initialization of motor 00118 * @post get speed value 00119 */ 00120 U8 mc_get_motor_speed(void) 00121 { 00122 return mc_cmd_speed; 00123 } 00124 00125 /* 00126 * @brief direction modification 00127 * @pre initialization of motor 00128 * @post new value of direction 00129 */ 00130 void mci_forward(void) 00131 { 00132 mci_direction = CW; 00133 } 00134 00135 /* 00136 * @brief direction modification 00137 * @pre initialization of motor 00138 * @post new value of direction 00139 */ 00140 void mci_backward(void) 00141 { 00142 mci_direction = CCW; 00143 } 00144 00145 /* 00146 * @brief direction visualization 00147 * @pre initialization of motor 00148 * @post get direction value 00149 */ 00150 U8 mc_get_motor_direction(void) 00151 { 00152 return mci_direction; 00153 } 00154 00160 void mc_set_motor_measured_speed(U8 measured_speed) 00161 { 00162 mc_measured_speed = measured_speed; 00163 } 00164 00171 U8 mci_get_measured_speed(void) 00172 { 00173 return mc_measured_speed; 00174 } 00175 00181 U16 mci_get_measured_current(void) 00182 { 00183 return mci_measured_current/64; 00184 } 00185 00191 void mci_store_measured_current(U16 current) 00192 { 00193 mci_measured_current = ((63*mci_measured_current)+(64*current))>>6; 00194 } 00195 00201 U8 mc_get_potentiometer_value(void) 00202 { 00203 return mc_potentiometer_value; 00204 } 00205 00211 void mc_set_potentiometer_value(U8 potentiometer) 00212 { 00213 mc_potentiometer_value = potentiometer; 00214 } 00215 00216 void mci_set_speed(U16 speed) 00217 { 00218 mci_set_motor_speed((U8)speed); 00219 }
1.5.7.1