Definition in file mc_control.h.
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Functions | |
| U8 | mc_control_current (U8 cur_cmd) |
| use to control current , current regulation loop need parameter : Kp_cur, Ki_cur ,Kd_cur and K_cur_scal in config_motor.h need to call in Te ms | |
| U8 | mc_control_position (S32 Number_of_turns) |
| use to control position , position regulation loop need parameter : Kp, Ki ,Kd and K_scal in config_motor.h need to call in Te ms | |
| U8 | mc_control_speed (U8 speed_cmd) |
| use to control speed , speed regulation loop need parameter : Kp_speed, Ki_speed ,Kd_speed and K_speed_scal in config_motor.h need to call in Te ms | |
| U8 | mc_get_Duty_Cycle () |
| set type of regulation | |
| void | mc_regulation_loop () |
| launch speed control or no regulation | |
| void | mc_set_Current_Loop () |
| set type of regulation | |
| void | mc_set_Open_Loop () |
| set type of regulation | |
| void | mc_set_Position_Loop () |
| set type of regulation | |
| void | mc_set_Speed_Loop () |
| set type of regulation | |
use to control current , current regulation loop need parameter : Kp_cur, Ki_cur ,Kd_cur and K_cur_scal in config_motor.h need to call in Te ms
Definition at line 121 of file mc_control.c.
References cur_error, cur_integ, cur_integral, cur_proportional, K_cur_scal, Ki_cur, Kp_cur, and mci_get_measured_current().
Referenced by mc_regulation_loop().
00122 { 00123 U8 Duty = 0; 00124 S32 increment = 0; 00125 00126 // Error calculation 00127 cur_error = cur_cmd - (mci_get_measured_current());// value -255 <=> 255 00128 00129 // proportional term calculation 00130 cur_proportional = Kp_cur*cur_error; 00131 00132 // integral term calculation 00133 cur_integral = cur_integral + cur_error; 00134 00135 if(cur_integral > 255) cur_integral = 255; 00136 if(cur_integral < -255) cur_integral = -255; 00137 00138 cur_integ = Ki_cur*cur_integral; 00139 00140 // derivative term calculation 00141 /*cur_derivative = cur_error - last_cur_error; 00142 00143 if(cur_derivative > 255) cur_derivative = 255; 00144 if(cur_derivative < -255) cur_derivative = -255; 00145 00146 cur_der = Kd_cur*cur_derivative; 00147 00148 last_cur_error = cur_error;*/ 00149 00150 // Duty Cycle calculation 00151 increment = cur_proportional + cur_integ; 00152 //increment += cur_der; 00153 increment = increment >> K_cur_scal; 00154 00155 // Variable saturation 00156 if(increment >= (S16)(255)) Duty = 255; 00157 else 00158 { 00159 if(increment <= (S16)(0)) Duty = 0; 00160 else Duty = (U8)(increment); 00161 } 00162 00163 // return Duty Cycle 00164 return Duty; 00165 }
Here is the call graph for this function:

Here is the caller graph for this function:

use to control position , position regulation loop need parameter : Kp, Ki ,Kd and K_scal in config_motor.h need to call in Te ms
Definition at line 176 of file mc_control.c.
References CCW, CW, K_pos_scal, Kd_pos, Ki_pos, Kp_pos, last_pos_error, mc_get_Num_Turn(), mci_set_motor_direction(), pos_der, pos_derivative, pos_error, pos_integ, pos_integral, and pos_proportional.
Referenced by mc_regulation_loop().
00177 { 00178 U8 Duty = 0; 00179 S32 increment = 0; 00180 00181 // Error calculation 00182 pos_error = Number_of_turns - mc_get_Num_Turn(); 00183 00184 // proportional term calculation 00185 pos_proportional = Kp_pos*pos_error; 00186 00187 // integral term calculation 00188 pos_integral = pos_integral + pos_error; 00189 00190 if(pos_integral > 255) pos_integral = 255; 00191 if(pos_integral < -255) pos_integral = -255; 00192 00193 pos_integ = Ki_pos * pos_integral; 00194 00195 // derivative term calculation 00196 pos_derivative = pos_error - last_pos_error; 00197 00198 if(pos_derivative > 255) pos_derivative = 255; 00199 if(pos_derivative < -255) pos_derivative = -255; 00200 00201 pos_der = Kd_pos*pos_derivative; 00202 00203 last_pos_error = pos_error; 00204 00205 // Duty Cycle calculation 00206 increment = pos_proportional + pos_integ; 00207 increment += pos_der; 00208 increment = increment >> K_pos_scal; 00209 00210 // Variable saturation 00211 if(increment >= (S16)(0)) 00212 { 00213 if(increment >= (S16)(100))Duty = 100; 00214 else Duty = (U8)(increment); 00215 mci_set_motor_direction(CW); 00216 } 00217 else 00218 { 00219 if(increment <= (S16)(-100)) Duty = 100; 00220 else Duty = (U8)(-increment); 00221 mci_set_motor_direction(CCW); 00222 } 00223 // return Duty Cycle 00224 return Duty; 00225 }
Here is the call graph for this function:

Here is the caller graph for this function:

use to control speed , speed regulation loop need parameter : Kp_speed, Ki_speed ,Kd_speed and K_speed_scal in config_motor.h need to call in Te ms
Definition at line 65 of file mc_control.c.
References K_speed_scal, Ki_speed, Klin_speed, Kp_speed, mci_get_measured_speed(), speed_error, speed_integ, speed_integral, and speed_proportional.
Referenced by mc_regulation_loop().
00066 { 00067 U8 Duty = 0; 00068 S16 increment = 0; 00069 00070 // Error calculation 00071 speed_error = (S16)speed_cmd - mci_get_measured_speed();// value -255 <=> 255 00072 00073 // proportional term calculation 00074 speed_proportional = (S16)Kp_speed * speed_error; 00075 00076 // integral term calculation 00077 speed_integral = speed_integral + speed_error; 00078 00079 if(speed_integral > (S16)255) speed_integral = 255; 00080 if(speed_integral < (S16)-255) speed_integral = -255; 00081 00082 speed_integ = (S16)Ki_speed * speed_integral; 00083 00084 // derivative term calculation 00085 /* speed_derivative = (S16)speed_error - last_speed_error; 00086 00087 if(speed_derivative > (S16)255) speed_derivative = 255; 00088 if(speed_derivative < (S16)-255) speed_derivative = -255; 00089 00090 speed_der = Kd_speed*speed_derivative; 00091 00092 last_speed_error = speed_error;*/ 00093 00094 // Duty Cycle calculation 00095 increment = speed_proportional + speed_integ; 00096 //increment += speed_der; 00097 increment = increment >> K_speed_scal; 00098 increment = increment + Klin_speed; 00099 00100 // Variable saturation 00101 if(increment >= (S16)(240)) Duty = 240; 00102 else 00103 { 00104 if(increment <= (S16)(130)) Duty = 130; 00105 else Duty = (U8)(increment); 00106 } 00107 00108 /* return the new "Duty Cycle" */ 00109 return Duty; 00110 }
Here is the call graph for this function:

Here is the caller graph for this function:

| U8 mc_get_Duty_Cycle | ( | ) |
set type of regulation
Definition at line 287 of file mc_control.c.
References duty_cycle.
Referenced by mc_switch_commutation().
00288 { 00289 return duty_cycle; 00290 }
Here is the caller graph for this function:

| void mc_regulation_loop | ( | ) |
launch speed control or no regulation
Definition at line 236 of file mc_control.c.
References BO_BF, Clear_EXT3, CURRENT_LOOP, duty_cycle, mc_control_current(), mc_control_position(), mc_control_speed(), mci_get_motor_speed(), mci_get_potentiometer_value(), OPEN_LOOP, POSITION_LOOP, Set_EXT3, and SPEED_LOOP.
Referenced by main(), and mci_run().
00237 { 00238 // measure 00239 Set_EXT3(); 00240 00241 switch(BO_BF) 00242 { 00243 case OPEN_LOOP : duty_cycle = mci_get_motor_speed();break; 00244 case SPEED_LOOP : duty_cycle = mc_control_speed(mci_get_motor_speed());break; 00245 case CURRENT_LOOP : duty_cycle = mc_control_current(mci_get_potentiometer_value());break; 00246 case POSITION_LOOP : duty_cycle = /*mc_control_speed(*/mc_control_position(mci_get_potentiometer_value())/*)*/;break; 00247 default : break; 00248 } 00249 00250 // measure 00251 Clear_EXT3(); 00252 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mc_set_Current_Loop | ( | ) |
set type of regulation
Definition at line 273 of file mc_control.c.
References BO_BF, and CURRENT_LOOP.
00273 {BO_BF = CURRENT_LOOP;}
| void mc_set_Open_Loop | ( | ) |
| void mc_set_Position_Loop | ( | ) |
set type of regulation
Definition at line 280 of file mc_control.c.
References BO_BF, and POSITION_LOOP.
00280 {BO_BF = POSITION_LOOP;}
| void mc_set_Speed_Loop | ( | ) |
set type of regulation
Definition at line 266 of file mc_control.c.
References BO_BF, and SPEED_LOOP.
00266 {BO_BF = SPEED_LOOP;}
1.4.7