00001 00013 #include "config.h" 00014 #include "config_motor.h" 00015 00016 #include "mc_interface.h" 00017 #include "mc_control.h" 00018 #include "mc_drv.h" 00019 #include "ushell_task.h" 00020 00021 #include "adc\adc_drv.h" 00022 #include "comparator\comparator_drv.h" 00023 00024 U16 g_regulation_period = 0; 00025 U16 g_speed_monitor_period = 0; 00026 extern Bool g_tick; 00027 Bool ramp_up = FALSE; 00028 00029 U8 tick_divider; 00030 U8 new_position = HS_001; // arbitrary rotor position for Ramp Up Sequence 00031 U8 tick_divider_min = 50; 00032 U8 ramp_counter = 0; 00033 00034 00035 void mc_ramp_up_init(void) 00036 { 00037 ramp_counter = 0; 00038 tick_divider_min = 50; 00039 new_position = HS_001; 00040 ramp_up = TRUE; 00041 g_speed_monitor_period = 0; 00042 } 00043 00044 00045 void main(void) 00046 { 00047 ushell_task_init(); 00048 00049 // init motor 00050 mc_motor_init(); // launch initialization of the motor 00051 00052 while(1) 00053 { 00054 // Show PSC state according to the Over Current information 00055 if(PCTL2 & (1<<PRUN2)) switch_OFF_LED();// PSC ON 00056 else switch_ON_LED();//PSC OFF => Over_Current 00057 00058 00059 // Launch regulation loop 00060 // Timer 1 generate an IT (g_tick) all 250us 00061 // Sampling period = n * 250us 00062 if (g_tick == TRUE) 00063 { 00064 g_tick = FALSE; 00065 00066 // Get Current and potentiometer value 00067 mc_ADC_Scheduler(); 00068 00069 if (ramp_up == TRUE) 00070 { 00071 /* BEGIN OF RAMP UP SEQUENCE */ 00072 Disable_comparator0_interrupt(); // disable bemf interrupt 00073 Disable_comparator1_interrupt(); // disable bemf interrupt 00074 Disable_comparator2_interrupt(); // disable bemf interrupt 00075 ramp_counter += 1; 00076 if ( ramp_counter >= 40 ) 00077 { 00078 ramp_counter = 0; 00079 if (tick_divider_min > 3) 00080 { 00081 tick_divider_min -= 1; 00082 } 00083 else 00084 { 00085 ramp_up = FALSE; 00086 g_speed_monitor_period = 1; 00087 // mc_set_Speed_Loop(); // speed regulation loop 00088 mc_set_Open_Loop(); // no regulation loop 00089 mci_set_motor_speed(180); 00090 mc_regulation_loop(); 00091 Enable_comparator0_interrupt(); // enable the bemf signal 00092 Enable_comparator1_interrupt(); // enable the bemf signal 00093 Enable_comparator2_interrupt(); // enable the bemf signal 00094 } 00095 } 00096 00097 tick_divider += 1; 00098 if ( tick_divider >= tick_divider_min ) 00099 { 00100 tick_divider = 0; 00101 00102 if (mci_get_motor_direction()==CCW) 00103 { 00104 switch(new_position) 00105 { 00106 /* ramp up CCW */ 00107 case HS_001: 00108 new_position = HS_011; 00109 break; 00110 00111 case HS_101: 00112 new_position = HS_001; 00113 break; 00114 00115 case HS_100: 00116 new_position = HS_101; 00117 break; 00118 00119 case HS_110: 00120 new_position = HS_100; 00121 break; 00122 00123 case HS_010: 00124 new_position = HS_110; 00125 break; 00126 00127 case HS_011: 00128 new_position = HS_010; 00129 break; 00130 00131 default : 00132 new_position = HS_001; 00133 break; 00134 } 00135 00136 } 00137 else 00138 { 00139 switch(new_position) 00140 { 00141 /* ramp_up CW */ 00142 case HS_001: 00143 new_position = HS_101; 00144 break; 00145 00146 case HS_101: 00147 new_position = HS_100; 00148 break; 00149 00150 case HS_100: 00151 new_position = HS_110; 00152 break; 00153 00154 case HS_110: 00155 new_position = HS_010; 00156 break; 00157 00158 case HS_010: 00159 new_position = HS_011; 00160 break; 00161 00162 case HS_011: 00163 new_position = HS_001; 00164 break; 00165 00166 default : 00167 new_position = HS_001; 00168 break; 00169 } 00170 00171 } 00172 mc_switch_commutation(new_position); 00173 } 00174 /* END OF RAMP UP SEQUENCE */ 00175 } 00176 00177 00178 g_regulation_period += 1; 00179 if ( g_regulation_period >= 8 ) //n * 250us = Te : 2mS 00180 { 00181 g_regulation_period = 1; 00182 mc_regulation_loop(); // launch regulation loop 00183 } 00184 00185 00186 /* monitor the speed */ 00187 if (mci_run_stop == RUN) 00188 { 00189 g_speed_monitor_period += 1; 00190 if ( g_speed_monitor_period >= 4000 ) //n * 250us = 1S 00191 { 00192 g_speed_monitor_period = 1; 00193 if (mci_get_measured_speed() > 250) mc_ramp_up_init(); 00194 if (mci_get_measured_speed() < (100/27)) mc_ramp_up_init(); 00195 } 00196 } 00197 00198 /* monitor the uart communication */ 00199 ushell_task(); 00200 00201 } 00202 } 00203 } 00204
1.4.7