#include "config.h"#include "mc_interface.h"#include "mc_control.h"#include "mc_drv.h"#include "adc\adc_drv.h"#include "ushell_task.h"
Go to the source code of this file.
Functions | |
| void | compute_new_position (void) |
| this function computes the new position during ramp_up | |
| int | main (void) |
| Main Entry. | |
Variables | |
| U8 | duty_cycle |
| Parameter to set PWM Duty Cycle after regulation calculation. | |
| U8 | duty_cycle_reference |
| U16 | g_regulation_period = 0 |
| Define the sampling period. | |
| volatile Bool | g_tick |
| Use for control the sampling period value. | |
| U16 | motor_speed = 0 |
| User Speed Order. | |
| U8 | motor_state = MS_STOP |
| U8 | new_position = MS_001 |
| Bool | overcurrent |
| U8 | ramp_up_index = 0 |
| U8 | ru_period_counter = 0 |
| U8 | ru_step_length = RAMP_UP_STEP_MAX |
| U8 | ru_step_length_cntr = 0 |
| Reference before filtering. | |
| void compute_new_position | ( | void | ) | [inline] |
this function computes the new position during ramp_up
Definition at line 130 of file main.c.
References CCW, mci_get_motor_direction(), MS_001, MS_010, MS_011, MS_100, MS_101, MS_110, and new_position.
Referenced by main().
00131 { 00132 if (mci_get_motor_direction()==CCW) 00133 { 00134 switch(new_position) 00135 { 00136 /* ramp up CCW */ 00137 case MS_001: 00138 new_position = MS_011; 00139 break; 00140 00141 case MS_101: 00142 new_position = MS_001; 00143 break; 00144 00145 case MS_100: 00146 new_position = MS_101; 00147 break; 00148 00149 case MS_110: 00150 new_position = MS_100; 00151 break; 00152 00153 case MS_010: 00154 new_position = MS_110; 00155 break; 00156 00157 case MS_011: 00158 new_position = MS_010; 00159 break; 00160 00161 default : 00162 new_position = MS_001; 00163 break; 00164 } 00165 00166 } 00167 else 00168 { 00169 switch(new_position) 00170 { 00171 /* ramp_up CW */ 00172 case MS_001: 00173 new_position = MS_101; 00174 break; 00175 00176 case MS_101: 00177 new_position = MS_100; 00178 break; 00179 00180 case MS_100: 00181 new_position = MS_110; 00182 break; 00183 00184 case MS_110: 00185 new_position = MS_010; 00186 break; 00187 00188 case MS_010: 00189 new_position = MS_011; 00190 break; 00191 00192 case MS_011: 00193 new_position = MS_001; 00194 break; 00195 00196 default : 00197 new_position = MS_001; 00198 break; 00199 } 00200 00201 } 00202 }
| int main | ( | void | ) |
Main Entry.
The main entry point for the control motor application.
The mc_regulation_loop() function is launched every 80ms.
Definition at line 210 of file main.c.
References Clear_PC7, compute_new_position(), duty_cycle, duty_cycle_filter(), duty_cycle_reference, FALSE, g_regulation_period, g_tick, mc_ADC_Scheduler(), mc_duty_cycle(), mc_get_duty_cycle(), mc_get_potentiometer_value(), mc_init(), mc_regulation_loop(), mc_switch_commutation(), mci_backward(), mci_run(), mci_set_ref_speed(), motor_state, MS_ALIGN, MS_LAST_RAMP_UP, MS_RAMP_UP, MS_RUNNING, MS_STOP, new_position, POT_REF_MIN, ramp_up_index, RAMP_UP_INDEX_MAX, RAMP_UP_PERIOD, ru_period_counter, ru_step_length, ru_step_length_cntr, Set_PC7, start_running_phase(), TRUE, ushell_active, ushell_task(), and ushell_task_init().
00211 { 00212 U8 temp; 00213 // init motor 00214 mc_init(); // launch initialization of the motor application 00215 00216 // Initialyze the communication system for External Command through Uart 00217 ushell_task_init(); 00218 00219 mci_backward(); 00220 00221 mci_run(); 00222 00223 while(1) 00224 { 00225 00226 // Timer 0 generates an (g_tick) all 256 * 4us => 1.024mS 00227 // g_tick period = 1.024mS 00228 if (g_tick == TRUE) 00229 { 00230 g_tick = FALSE; 00231 00232 // Get Current and potentiometer value 00233 mc_ADC_Scheduler(); 00234 00235 switch(motor_state) 00236 { 00237 case (MS_ALIGN): 00238 ru_period_counter--; 00239 if (ru_period_counter==0) 00240 { 00241 Clear_PC7(); 00242 motor_state=MS_RAMP_UP; 00243 } 00244 break; 00245 00246 case (MS_RAMP_UP): 00247 // divide the ramp-up phase in constant periods equal 00248 // to RAMP_UP_PERIOD * (g_tick periop) 00249 // generate the ru_step_length for each period 00250 // with data from the table 00251 ru_period_counter += 1; 00252 if ( ru_period_counter >= RAMP_UP_PERIOD ) 00253 { 00254 ru_period_counter = 0; 00255 ru_step_length = ramp_up_time_table[ramp_up_index]; 00256 mc_duty_cycle(ramp_up_duty_table[ramp_up_index]); 00257 duty_cycle = ramp_up_duty_table[ramp_up_index]; 00258 duty_cycle_reference = duty_cycle; 00259 00260 if (ramp_up_index < RAMP_UP_INDEX_MAX) 00261 { 00262 ramp_up_index += 1; 00263 } 00264 else 00265 { 00266 motor_state=MS_LAST_RAMP_UP; 00267 00268 } 00269 } 00270 00271 // monitor the length of each step 00272 ru_step_length_cntr += 1; 00273 if ( ru_step_length_cntr >= ru_step_length ) 00274 { 00275 ru_step_length_cntr = 0; 00276 compute_new_position(); 00277 mc_switch_commutation((Motor_Position)new_position); 00278 // Toggle_PC7(); // generate a probe signal on PC7 00279 } 00280 break; 00281 00282 case (MS_LAST_RAMP_UP): 00283 00284 // monitor the length of each step 00285 ru_step_length_cntr += 1; 00286 if ( ru_step_length_cntr >= ru_step_length ) 00287 { 00288 ru_step_length_cntr = 0; 00289 compute_new_position(); 00290 mc_switch_commutation((Motor_Position)new_position); 00291 start_running_phase(); 00292 motor_state=MS_RUNNING; 00293 Set_PC7(); // generate a probe signal on PC7 00294 } 00295 break; 00296 00297 case (MS_RUNNING): 00298 g_regulation_period += 1; 00299 if ( g_regulation_period >= 40 ) //n * 1mS = Te 00300 { 00301 g_regulation_period = 0; 00302 00303 if (ushell_active == FALSE) 00304 { 00305 // Set User Speed Command with potentiometer 00306 temp = mc_get_potentiometer_value(); 00307 if (temp > (POT_REF_MIN)) 00308 { 00309 mci_set_ref_speed((U8)temp); 00310 mc_regulation_loop(); // launch regulation loop 00311 mc_duty_cycle(mc_get_duty_cycle()); 00312 } 00313 else 00314 { 00315 mci_set_ref_speed(POT_REF_MIN); 00316 mc_regulation_loop(); // launch regulation loop 00317 mc_duty_cycle(mc_get_duty_cycle()); 00318 } 00319 } 00320 else 00321 { 00322 mc_regulation_loop(); // launch regulation loop 00323 mc_duty_cycle(mc_get_duty_cycle()); 00324 } 00325 } 00326 break; 00327 00328 case (MS_STOP): 00329 if (ushell_active == FALSE) 00330 { 00331 temp = mc_get_potentiometer_value(); 00332 if (temp > (POT_REF_MIN)) 00333 { 00334 mci_run(); 00335 } 00336 } 00337 break; 00338 00339 default : 00340 motor_state=MS_STOP; 00341 break; 00342 } 00343 00344 00345 ushell_task(); 00346 // mc_inrush_task(); // manage the inrush current 00347 duty_cycle_filter (); 00348 00349 00350 } 00351 00352 } 00353 }
Parameter to set PWM Duty Cycle after regulation calculation.
Definition at line 48 of file mc_control.c.
Referenced by duty_cycle_filter(), main(), and mc_get_duty_cycle().
Definition at line 50 of file mc_control.c.
Referenced by duty_cycle_filter(), main(), and mc_regulation_loop().
Use for control the sampling period value.
Definition at line 74 of file mc_drv.c.
Referenced by main(), and ovfl_timer0().
| U16 motor_speed = 0 |
| U8 motor_state = MS_STOP |
| U8 new_position = MS_001 |
| U8 ru_period_counter = 0 |
| U8 ru_step_length = RAMP_UP_STEP_MAX |
1.5.7.1