motor.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. #include "foc/motor/motor.h"
  2. #include "foc/motor/current.h"
  3. #include "foc/foc_config.h"
  4. #include "foc/mc_error.h"
  5. #include "foc/samples.h"
  6. #include "math/fast_math.h"
  7. #include "bsp/timer_count32.h"
  8. #include "libs/time_measure.h"
  9. #include "bsp/delay.h"
  10. #include "bsp/bsp.h"
  11. #include "bsp/adc.h"
  12. #include "bsp/pwm.h"
  13. #include "bsp/fan_pwm.h"
  14. #include "foc/commands.h"
  15. #include "libs/logger.h"
  16. #include "bsp/sched_timer.h"
  17. #include "foc/core/e_ctrl.h"
  18. #include "foc/samples.h"
  19. #include "foc/motor/motor_param.h"
  20. #include "foc/core/foc_observer.h"
  21. #include "foc/core/thro_torque.h"
  22. #include "app/nv_storage.h"
  23. //#include "foc/core/torque.h"
  24. #include "foc/limit.h"
  25. #ifdef CONFIG_DQ_STEP_RESPONSE
  26. extern float target_d;
  27. extern float target_q;
  28. #endif
  29. static bool mc_is_hwbrake(void);
  30. static bool mc_is_gpio_mlock(void);
  31. static void _pwm_brake_prot_timer_handler(shark_timer_t *);
  32. static shark_timer_t _brake_prot_timer = TIMER_INIT(_brake_prot_timer, _pwm_brake_prot_timer_handler);
  33. static void _autohold_beep_timer_handler(shark_timer_t *);
  34. static shark_timer_t _autohold_beep_timer = TIMER_INIT(_autohold_beep_timer, _autohold_beep_timer_handler);
  35. static void _fan_det_timer_handler(shark_timer_t *);
  36. static shark_timer_t _fan_det_timer1 = TIMER_INIT(_fan_det_timer1, _fan_det_timer_handler);
  37. static shark_timer_t _fan_det_timer2 = TIMER_INIT(_fan_det_timer2, _fan_det_timer_handler);
  38. static void _encoder_zero_off_timer_handler(shark_timer_t *);
  39. static shark_timer_t _encoder_zero_off_timer = TIMER_INIT(_encoder_zero_off_timer, _encoder_zero_off_timer_handler);
  40. static void _led_off_timer_handler(shark_timer_t *);
  41. static shark_timer_t _led_off_timer = TIMER_INIT(_led_off_timer, _led_off_timer_handler);
  42. static motor_t motor = {
  43. .s_direction = POSITIVE,
  44. .n_gear = 0,
  45. .b_is96Mode = false,
  46. .mode = CTRL_MODE_OPEN,
  47. };
  48. static void MC_Check_MosVbusThrottle(void) {
  49. int count = 1000;
  50. float ibus_adc = 0;
  51. float vref_adc = 0;
  52. float vref_5v_adc = 0;
  53. gpio_phase_u_detect(true);
  54. while(count-- > 0) {
  55. task_udelay(20);
  56. sample_uvw_phase();
  57. sample_throttle();
  58. sample_vbus();
  59. vref_adc += adc_get_vref();
  60. vref_5v_adc += adc_get_5v_ref();
  61. }
  62. adc_set_vref_calc(vref_adc/1000.0f);
  63. adc_set_5vref_calc(vref_5v_adc/1000.0f);
  64. sys_debug("5v ref %f\n", vref_5v_adc/1000.0f);
  65. count = 50;
  66. while(count-- >0) {
  67. task_udelay(300);
  68. ibus_adc += adc_get_ibus();
  69. }
  70. u16 offset = ((float)ibus_adc)/50.0f;
  71. sys_debug("ibus offset %d\n", offset);
  72. sample_ibus_offset(offset);
  73. gpio_phase_u_detect(false);
  74. float abc[3];
  75. get_phase_vols(abc);
  76. int vbus_vol = get_vbus_int();
  77. if (vbus_vol > nv_get_foc_params()->s_maxDCVol) {
  78. mc_set_critical_error(FOC_CRIT_OV_Vol_Err);
  79. }
  80. if (vbus_vol <= nv_get_foc_params()->s_minDCVol) {
  81. mc_set_critical_error(FOC_CRIT_UN_Vol_Err);
  82. }
  83. vbus_vol = get_acc_vol();
  84. sys_debug("acc vol %d\n", vbus_vol);
  85. if (vbus_vol >= nv_get_foc_params()->s_maxDCVol) {
  86. mc_set_critical_error(FOC_CRIT_ACC_OV_Err);
  87. }
  88. if (vbus_vol <= nv_get_foc_params()->s_minDCVol) {
  89. mc_set_critical_error(FOC_CRIT_ACC_Un_Err);
  90. }
  91. if ((get_throttle_float() < nv_get_foc_params()->f_minThroVol) || (get_throttle_float() > nv_get_foc_params()->f_maxThroVol)) {
  92. if (!motor.b_ignor_throttle) {
  93. mc_set_critical_error(FOC_CRIT_THRO_Err);
  94. }
  95. }
  96. if (abc[0] > vbus_vol/2 || abc[1] > vbus_vol/2 || abc[2] > vbus_vol/2) {
  97. mc_set_critical_error(FOC_CRIT_H_MOS_Err);
  98. }else if (abc[0] < 0.001f){
  99. mc_set_critical_error(FOC_CRIT_L_MOS_Err);
  100. }else if ((abc[0] > 0.5f) && (abc[1] < 0.001f || abc[2] < 0.001f)) {
  101. mc_set_critical_error(FOC_CRIT_Phase_Conn_Err);
  102. }
  103. sys_debug("phase vol %f, %f, %f\n", abc[0], abc[1], abc[2]);
  104. }
  105. static u32 _self_check_task(void *p) {
  106. if (ENC_Check_error()) {
  107. err_add_record(FOC_CRIT_Encoder_Err, 0);
  108. mc_set_critical_error(FOC_CRIT_Encoder_Err);
  109. }
  110. if (get_tick_ms() < 5000) { //启动后5s内检测锁电机线
  111. if (mc_is_gpio_mlock()) {
  112. mc_lock_motor(true);
  113. }
  114. }
  115. if (motor.b_lock_motor) {
  116. if (!mc_is_gpio_mlock()) {
  117. mc_lock_motor(false);
  118. }
  119. }
  120. if (fan_pwm_is_running()) {
  121. if ((get_delta_ms(motor.fan[0].start_ts) >= 5000) && (motor.fan[0].rpm == 0)) {
  122. mc_set_critical_error(FOC_CRIT_Fan1_Err);
  123. }else if (motor.fan[0].rpm > 0) {
  124. mc_clr_critical_error(FOC_CRIT_Fan1_Err);
  125. }
  126. if ((get_delta_ms(motor.fan[1].start_ts) >= 5000) && (motor.fan[1].rpm == 0)) {
  127. mc_set_critical_error(FOC_CRIT_Fan2_Err);
  128. }else if (motor.fan[1].rpm > 0) {
  129. mc_clr_critical_error(FOC_CRIT_Fan2_Err);
  130. }
  131. }
  132. return 5;
  133. }
  134. static bool mc_detect_vbus_mode(void) {
  135. #ifdef CONFIG_FORCE_96V_MODE
  136. motor.b_is96Mode = true;
  137. return false;
  138. #else
  139. bool is_96mode = motor.b_is96Mode;
  140. motor.b_is96Mode = get_vbus_int() >= CONFIG_96V_MODE_VOL;
  141. return (is_96mode != motor.b_is96Mode);
  142. #endif
  143. }
  144. static void _mc_internal_init(u8 mode, bool start) {
  145. motor.mode = mode;
  146. motor.throttle = 0;
  147. motor.b_start = start;
  148. motor.b_runStall = false;
  149. motor.runStall_time = 0;
  150. motor.b_epm = false;
  151. motor.b_epm_cmd_move = false;
  152. motor.epm_dir = EPM_Dir_None;
  153. motor.n_autohold_time = 0;
  154. motor.b_auto_hold = 0;
  155. motor.b_break = false;
  156. motor.b_wait_brk_release = false;
  157. motor.b_force_run = false;
  158. motor.b_cruise = false;
  159. }
  160. static void _led_off_timer_handler(shark_timer_t *t) {
  161. gpio_led_enable(false);
  162. }
  163. static void mc_gear_vmode_changed(void) {
  164. mc_gear_t *gears = mc_get_gear_config();
  165. //sys_debug("limit %d-%d-%d, mode = %s\n", gears[motor.n_gear].u_maxRPM, gears[motor.n_gear].u_maxIdc, gears[motor.n_gear].u_maxTorque, motor.b_is96Mode?"96V":"48V");
  166. PMSM_FOC_SpeedLimit(gears->n_max_speed);
  167. PMSM_FOC_DCCurrLimit(gears->n_max_idc);
  168. PMSM_FOC_TorqueLimit(gears->n_max_trq);
  169. eCtrl_set_accl_time((u16)gears->n_accl_time);
  170. }
  171. static s16 mc_get_gear_idc_limit(void) {
  172. if (motor.b_is96Mode) {
  173. return nv_get_gear_configs()->gears_96[motor.n_gear].n_max_idc;
  174. }else {
  175. return nv_get_gear_configs()->gears_48[motor.n_gear].n_max_idc;
  176. }
  177. }
  178. void mc_init(void) {
  179. fan_pwm_init();
  180. adc_init();
  181. pwm_3phase_init();
  182. samples_init();
  183. motor_encoder_init();
  184. foc_command_init();
  185. thro_torque_init();
  186. mc_detect_vbus_mode();
  187. PMSM_FOC_CoreInit();
  188. eCtrl_init(mc_get_gear_config()->n_accl_time, nv_get_foc_params()->n_dec_time);
  189. mc_gpio_init();
  190. MC_Check_MosVbusThrottle();
  191. sched_timer_enable(CONFIG_SPD_CTRL_US);
  192. shark_task_create(_self_check_task, NULL);
  193. pwm_up_enable(true);
  194. gpio_led_enable(true);
  195. shark_timer_post(&_led_off_timer, 5000);
  196. }
  197. motor_t * mc_params(void) {
  198. return &motor;
  199. }
  200. void mc_need_update(void) {
  201. motor.b_updated = true;
  202. }
  203. mc_gear_t *mc_get_gear_config(void) {
  204. mc_gear_t *gears;
  205. if (motor.b_is96Mode) {
  206. gears = &nv_get_gear_configs()->gears_96[0];
  207. }else {
  208. gears = &nv_get_gear_configs()->gears_48[0];
  209. }
  210. return &gears[motor.n_gear];
  211. }
  212. bool mc_unsafe_critical_error(void) {
  213. u32 err = motor.n_CritiCalErrMask & (~(FOC_Cri_Err_Mask(FOC_CRIT_Fan1_Err)));
  214. err = err & (~(FOC_Cri_Err_Mask(FOC_CRIT_Fan2_Err)));
  215. #ifdef CONFIG_DQ_STEP_RESPONSE
  216. sys_debug("err=0x%x\n", err);
  217. err = err & (~(FOC_Cri_Err_Mask(FOC_CRIT_Encoder_Err)));
  218. err = err & (~(FOC_Cri_Err_Mask(FOC_CRIT_THRO_Err)));
  219. sys_debug("err=0x%x\n", err);
  220. #endif
  221. if (motor.b_ignor_throttle) {
  222. err = err & (~(FOC_Cri_Err_Mask(FOC_CRIT_THRO_Err)));
  223. }
  224. return (err != 0);
  225. }
  226. bool mc_start(u8 mode) {
  227. if (motor.b_start) {
  228. return true;
  229. }
  230. #ifdef CONFIG_DQ_STEP_RESPONSE
  231. mode = CTRL_MODE_CURRENT;
  232. target_d = 0.0f;
  233. target_q = 0.0f;
  234. #endif
  235. mc_detect_vbus_mode();
  236. if (motor.b_lock_motor) {
  237. PMSM_FOC_SetErrCode(FOC_NotAllowed);
  238. return false;
  239. }
  240. MC_Check_MosVbusThrottle();
  241. if (mc_unsafe_critical_error()) {
  242. PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
  243. return false;
  244. }
  245. if (mode > CTRL_MODE_CURRENT) {
  246. PMSM_FOC_SetErrCode(FOC_Param_Err);
  247. return false;
  248. }
  249. if (motor_encoder_get_speed() > CONFIG_ZERO_SPEED_RPM) {
  250. PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
  251. return false;
  252. }
  253. if (!mc_throttle_released()) {
  254. PMSM_FOC_SetErrCode(FOC_Throttle_Err);
  255. return false;
  256. }
  257. pwm_up_enable(false);
  258. _mc_internal_init(mode, true);
  259. #if 0
  260. torque_reset();
  261. #else
  262. thro_torque_reset();
  263. #endif
  264. eCtrl_init(mc_get_gear_config()->n_accl_time, nv_get_foc_params()->n_dec_time);
  265. motor_encoder_start(true);
  266. PMSM_FOC_Start(mode);
  267. PMSM_FOC_RT_LimInit();
  268. pwm_turn_on_low_side();
  269. delay_ms(10);
  270. phase_current_offset_calibrate();
  271. pwm_start();
  272. delay_us(10); //wait for ebrake error
  273. if (mc_unsafe_critical_error()) {
  274. mc_stop();
  275. return false;
  276. }
  277. adc_start_convert();
  278. phase_current_calibrate_wait();
  279. if (phase_curr_offset_check()) {
  280. mc_set_critical_error(FOC_CRIT_CURR_OFF_Err);
  281. mc_stop();
  282. return false;
  283. }
  284. if (mc_is_hwbrake()) {
  285. PMSM_FOC_Brake(true);
  286. }
  287. gpio_beep(200);
  288. return true;
  289. }
  290. bool mc_stop(void) {
  291. if (!motor.b_start) {
  292. return true;
  293. }
  294. if (motor.b_lock_motor) {
  295. PMSM_FOC_SetErrCode(FOC_NotAllowed);
  296. return false;
  297. }
  298. if (motor_encoder_get_speed() > CONFIG_ZERO_SPEED_RPM) {
  299. PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
  300. return false;
  301. }
  302. if (!mc_throttle_released()) {
  303. PMSM_FOC_SetErrCode(FOC_Throttle_Err);
  304. return false;
  305. }
  306. u32 mask = cpu_enter_critical();
  307. _mc_internal_init(CTRL_MODE_OPEN, false);
  308. adc_stop_convert();
  309. pwm_stop();
  310. PMSM_FOC_Stop();
  311. motor_encoder_start(false);
  312. pwm_up_enable(true);
  313. cpu_exit_critical(mask);
  314. return true;
  315. }
  316. bool mc_set_gear(u8 gear) {
  317. if (gear >= CONFIG_MAX_GEAR_NUM) {
  318. PMSM_FOC_SetErrCode(FOC_Param_Err);
  319. return false;
  320. }
  321. if (motor.n_gear != gear) {
  322. motor.n_gear = gear;
  323. u32 mask = cpu_enter_critical();
  324. mc_gear_vmode_changed();
  325. cpu_exit_critical(mask);
  326. }
  327. return true;
  328. }
  329. u8 mc_get_gear(void) {
  330. if (motor.n_gear == 3){
  331. return 0;
  332. }
  333. return motor.n_gear + 1;
  334. }
  335. bool mc_enable_cruise(bool enable) {
  336. if (enable == motor.b_cruise) {
  337. return true;
  338. }
  339. if (PMSM_FOC_EnableCruise(enable)) {
  340. motor.b_cruise = enable;
  341. motor.cruise_time = enable?shark_get_seconds():0;
  342. motor.cruise_torque = 0.0f;
  343. return true;
  344. }
  345. return false;
  346. }
  347. bool mc_is_cruise_enabled(void) {
  348. return motor.b_cruise;
  349. }
  350. bool mc_set_cruise_speed(bool rpm_abs, float target_rpm) {
  351. bool ret;
  352. if (rpm_abs) {
  353. ret = PMSM_FOC_Set_CruiseSpeed(target_rpm);
  354. }else {
  355. ret = PMSM_FOC_Set_CruiseSpeed(PMSM_FOC_GetSpeed() + target_rpm);
  356. }
  357. if (ret) {
  358. motor.cruise_time = shark_get_seconds();
  359. motor.cruise_torque = 0.0f;
  360. }
  361. return ret;
  362. }
  363. void mc_set_idc_limit(s16 limit) {
  364. s16 g_limit = mc_get_gear_idc_limit();
  365. limit = min(g_limit, limit);
  366. PMSM_FOC_DCCurrLimit(limit);
  367. }
  368. bool mc_set_foc_mode(u8 mode) {
  369. if (mode == motor.mode) {
  370. return true;
  371. }
  372. if (!motor.b_start) {
  373. return false;
  374. }
  375. u32 mask = cpu_enter_critical();
  376. bool ret = false;
  377. if (PMSM_FOC_SetCtrlMode(mode)) {
  378. motor.mode = mode;
  379. if (mode == CTRL_MODE_OPEN || mode == CTRL_MODE_CURRENT) {
  380. PMSM_FOC_Start(motor.mode);
  381. pwm_enable_channel();
  382. }
  383. ret = true;
  384. }
  385. cpu_exit_critical(mask);
  386. return ret;
  387. }
  388. bool mc_start_epm(bool epm) {
  389. if (motor.b_epm == epm) {
  390. return true;
  391. }
  392. if (!motor.b_start) {
  393. PMSM_FOC_SetErrCode(FOC_NotAllowed);
  394. return false;
  395. }
  396. if (motor_encoder_get_speed() > CONFIG_ZERO_SPEED_RPM) {
  397. PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
  398. return false;
  399. }
  400. if (!mc_throttle_released()) {
  401. PMSM_FOC_SetErrCode(FOC_Throttle_Err);
  402. return false;
  403. }
  404. u32 mask = cpu_enter_critical();
  405. motor.b_epm = epm;
  406. if (epm) {
  407. eCtrl_set_TgtSpeed(0);
  408. motor.mode = CTRL_MODE_SPD;
  409. PMSM_FOC_TorqueLimit(nv_get_foc_params()->s_maxEpmTorqueLim);
  410. PMSM_FOC_SetCtrlMode(CTRL_MODE_SPD);
  411. }else {
  412. motor.epm_dir = EPM_Dir_None;
  413. motor.mode = CTRL_MODE_TRQ;
  414. motor.b_epm_cmd_move = false;
  415. PMSM_FOC_SetCtrlMode(CTRL_MODE_TRQ);
  416. mc_gear_vmode_changed();
  417. }
  418. cpu_exit_critical(mask);
  419. return false;
  420. }
  421. bool mc_is_epm(void) {
  422. return motor.b_epm;
  423. }
  424. bool mc_is_start(void) {
  425. return (motor.b_start || PMSM_FOC_Is_Start());
  426. }
  427. bool mc_start_epm_move(EPM_Dir_t dir, bool is_command) {
  428. if (!motor.b_epm || !motor.b_start) {
  429. PMSM_FOC_SetErrCode(FOC_NotAllowed);
  430. return false;
  431. }
  432. if ((dir == motor.epm_dir) && (is_command == motor.b_epm_cmd_move)) {
  433. return true;
  434. }
  435. u32 mask = cpu_enter_critical();
  436. motor.epm_dir = dir;
  437. if (dir != EPM_Dir_None) {
  438. motor.b_epm_cmd_move = is_command;
  439. if (!PMSM_FOC_Is_Start()) {
  440. PMSM_FOC_Start(motor.mode);
  441. pwm_enable_channel();
  442. }
  443. float rpm = nv_get_foc_params()->s_maxEpmRPM;
  444. if (dir == EPM_Dir_Back) {
  445. rpm = -rpm;
  446. }
  447. sys_debug("rpm %f\n", rpm);
  448. PMSM_FOC_Set_Speed(rpm);
  449. }else {
  450. motor.b_epm_cmd_move = false;
  451. PMSM_FOC_Set_Speed(0);
  452. }
  453. cpu_exit_critical(mask);
  454. return true;
  455. }
  456. void mc_set_fan_duty(u8 duty) {
  457. sys_debug("fan duty %d\n", duty);
  458. if (!fan_pwm_is_running() && duty > 0) {
  459. motor.fan[0].start_ts = get_tick_ms();
  460. motor.fan[1].start_ts = get_tick_ms();
  461. shark_timer_post(&_fan_det_timer1, 5000);
  462. shark_timer_post(&_fan_det_timer2, 5000);
  463. }else if (duty == 0) {
  464. shark_timer_cancel(&_fan_det_timer1);
  465. shark_timer_cancel(&_fan_det_timer2);
  466. }
  467. fan_set_duty(duty);
  468. }
  469. bool mc_command_epm_move(EPM_Dir_t dir) {
  470. return mc_start_epm_move(dir, true);
  471. }
  472. bool mc_throttle_epm_move(EPM_Dir_t dir) {
  473. return mc_start_epm_move(dir, false);
  474. }
  475. void mc_set_throttle_r(bool use, u8 r) {
  476. motor.u_throttle_ration = r;
  477. motor.b_ignor_throttle = use;
  478. if (motor.b_ignor_throttle) {
  479. mc_clr_critical_error(FOC_CRIT_THRO_Err);
  480. }
  481. }
  482. void mc_use_throttle(void) {
  483. motor.b_ignor_throttle = false;
  484. }
  485. void mc_get_running_status(u8 *data) {
  486. data[0] = motor.mode;
  487. data[0] |= (PMSM_FOC_AutoHoldding()?1:0) << 2;
  488. data[0] |= (motor.b_break?1:0) << 3;
  489. data[0] |= (PMSM_FOC_Get()->in.b_cruiseEna?1:0) << 4;
  490. data[0] |= (motor.b_start?1:0) << 5;
  491. data[0] |= (mc_is_epm()?1:0) << 6;
  492. data[0] |= (motor.b_lock_motor) << 7; //motor locked
  493. }
  494. u16 mc_get_running_status2(void) {
  495. u16 data = 0;
  496. data = motor.n_gear;
  497. data |= (PMSM_FOC_AutoHoldding()?1:0) << 2;
  498. data |= (motor.b_break?1:0) << 3;
  499. data |= (PMSM_FOC_Get()->in.b_cruiseEna?1:0) << 4;
  500. data |= (motor.b_start?1:0) << 5;
  501. data |= (mc_is_epm()?1:0) << 6;
  502. data |= (motor.b_lock_motor) << 7; //motor locked
  503. data |= (eCtrl_is_eBrk_Running()?1:0) << 8; //能量回收运行标志
  504. data |= ((motor.n_CritiCalErrMask != 0)?1:0) << 9;
  505. data |= (fan_pwm_is_running()?1:0) << 10; //风扇是否运行
  506. data |= (motor.b_runStall?1:0) << 11; //是否堵转
  507. data |= (PMSM_FOC_iDC_is_Limited()?1:0) << 12; //是否欠压限制母线电流
  508. data |= (PMSM_FOC_Torque_is_Limited()?1:0) << 13; //是否高温限扭矩
  509. data |= (motor.b_is96Mode?1:0) << 14; //是否高压模式
  510. return data;
  511. }
  512. static float _force_angle = 0.0f;
  513. static int _force_wait = 2000;
  514. /* 开环,强制给定电角度和DQ的电压 */
  515. void mc_force_run_open(s16 vd, s16 vq) {
  516. if (motor.b_start || motor.b_force_run) {
  517. if (vd == 0 && vq == 0) {
  518. PMSM_FOC_SetOpenVdq(0, 0);
  519. delay_ms(500);
  520. wdog_reload();
  521. adc_stop_convert();
  522. pwm_stop();
  523. PMSM_FOC_Stop();
  524. pwm_up_enable(true);
  525. motor.b_force_run = false;
  526. motor.b_ignor_throttle = false;
  527. }
  528. return;
  529. }
  530. if (vd == 0 && vq == 0) {
  531. return;
  532. }
  533. motor.b_ignor_throttle = true;
  534. MC_Check_MosVbusThrottle();
  535. if (mc_unsafe_critical_error()) {
  536. PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
  537. }
  538. pwm_up_enable(false);
  539. pwm_turn_on_low_side();
  540. task_udelay(500);
  541. PMSM_FOC_Start(CTRL_MODE_OPEN);
  542. phase_current_offset_calibrate();
  543. pwm_start();
  544. adc_start_convert();
  545. pwm_enable_channel();
  546. phase_current_calibrate_wait();
  547. PMSM_FOC_Set_Angle(0);
  548. PMSM_FOC_SetOpenVdq(vd, 0);
  549. _force_wait = 2000;
  550. motor.b_force_run = true;
  551. }
  552. void mc_encoder_off_calibrate(s16 vd) {
  553. if (motor.b_start || motor.b_calibrate) {
  554. return;
  555. }
  556. motor.b_calibrate = true;
  557. pwm_up_enable(false);
  558. pwm_turn_on_low_side();
  559. task_udelay(500);
  560. PMSM_FOC_Start(CTRL_MODE_OPEN);
  561. phase_current_offset_calibrate();
  562. pwm_start();
  563. adc_start_convert();
  564. phase_current_calibrate_wait();
  565. PMSM_FOC_Set_Angle(0);
  566. PMSM_FOC_SetOpenVdq(vd, 0);
  567. delay_ms(2000);
  568. motor_encoder_set_direction(POSITIVE);
  569. for (int i = 0; i < 200; i++) {
  570. for (float angle = 0; angle < 360; angle++) {
  571. PMSM_FOC_Set_Angle(angle);
  572. delay_ms(1);
  573. if (i > 20) {
  574. motor_encoder_offset(angle);
  575. }
  576. }
  577. wdog_reload();
  578. if (motor_encoder_offset_is_finish()) {
  579. break;
  580. }
  581. }
  582. motor_encoder_set_direction(NEGATIVE);
  583. delay_ms(100);
  584. for (int i = 0; i < 200; i++) {
  585. for (float angle = 360; angle > 0; angle--) {
  586. PMSM_FOC_Set_Angle(angle);
  587. delay_ms(1);
  588. if (i > 10) {
  589. motor_encoder_offset(angle);
  590. }
  591. }
  592. wdog_reload();
  593. if (motor_encoder_offset_is_finish()) {
  594. break;
  595. }
  596. }
  597. delay_ms(500);
  598. PMSM_FOC_SetOpenVdq(0, 0);
  599. delay_ms(500);
  600. wdog_reload();
  601. adc_stop_convert();
  602. pwm_stop();
  603. PMSM_FOC_Stop();
  604. pwm_up_enable(true);
  605. motor_encoder_data_upload();
  606. motor.b_calibrate = false;
  607. }
  608. static void _encoder_zero_off_timer_handler(shark_timer_t *t){
  609. if (!motor.b_calibrate) {
  610. return;
  611. }
  612. float enc_off = 0.0f;
  613. float phase = motor_encoder_zero_phase_detect(&enc_off);
  614. PMSM_FOC_SetOpenVdq(0, 0);
  615. delay_ms(50);
  616. adc_stop_convert();
  617. pwm_stop();
  618. PMSM_FOC_Stop();
  619. _mc_internal_init(CTRL_MODE_OPEN, false);
  620. motor.b_calibrate = false;
  621. if (phase != INVALID_ANGLE) {
  622. nv_save_angle_offset(phase);
  623. }
  624. }
  625. bool mc_encoder_zero_calibrate(s16 vd) {
  626. if (motor.b_calibrate) {
  627. if (vd == 0) {
  628. encoder_clear_cnt_offset();
  629. shark_timer_cancel(&_encoder_zero_off_timer);
  630. PMSM_FOC_SetOpenVdq(0, 0);
  631. delay_ms(500);
  632. adc_stop_convert();
  633. pwm_stop();
  634. PMSM_FOC_Stop();
  635. _mc_internal_init(CTRL_MODE_OPEN, false);
  636. motor.b_calibrate = false;
  637. motor.b_ignor_throttle = false;
  638. }
  639. return true;
  640. }
  641. encoder_clear_cnt_offset();
  642. motor.b_ignor_throttle = true;
  643. MC_Check_MosVbusThrottle();
  644. if (mc_unsafe_critical_error()) {
  645. PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
  646. return false;
  647. }
  648. _mc_internal_init(CTRL_MODE_OPEN, true);
  649. motor.b_calibrate = true;
  650. pwm_turn_on_low_side();
  651. task_udelay(500);
  652. PMSM_FOC_Start(CTRL_MODE_OPEN);
  653. phase_current_offset_calibrate();
  654. pwm_start();
  655. adc_start_convert();
  656. pwm_enable_channel();
  657. phase_current_calibrate_wait();
  658. PMSM_FOC_Set_Angle(0);
  659. PMSM_FOC_SetOpenVdq(vd, 0);
  660. shark_timer_post(&_encoder_zero_off_timer, 6*1000);
  661. return true;
  662. }
  663. bool mc_current_sensor_calibrate(float current) {
  664. if (!mc_start(CTRL_MODE_OPEN)) {
  665. return false;
  666. }
  667. phase_current_sensor_start_calibrate(current);
  668. phase_current_calibrate_wait();
  669. return true;
  670. }
  671. bool mc_lock_motor(bool lock) {
  672. if (motor.b_lock_motor == lock) {
  673. return true;
  674. }
  675. int ret = true;
  676. u32 mask = cpu_enter_critical();
  677. if (motor.b_start) {
  678. PMSM_FOC_SetErrCode(FOC_NotAllowed);
  679. ret = false;
  680. goto ml_ex_cri;
  681. }
  682. if (lock && (motor_encoder_get_speed() > CONFIG_ZERO_SPEED_RPM)) {
  683. PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
  684. ret = false;
  685. goto ml_ex_cri;
  686. }
  687. motor.b_lock_motor = lock;
  688. if (lock) {
  689. pwm_start();
  690. pwm_update_duty(FOC_PWM_Half_Period/2, FOC_PWM_Half_Period/2, FOC_PWM_Half_Period/2);
  691. pwm_enable_channel();
  692. }else {
  693. pwm_stop();
  694. }
  695. ml_ex_cri:
  696. cpu_exit_critical(mask);
  697. return ret;
  698. }
  699. bool mc_auto_hold(bool hold) {
  700. if (motor.b_auto_hold == hold) {
  701. return true;
  702. }
  703. if (nv_get_foc_params()->n_autoHold == 0) {
  704. PMSM_FOC_SetErrCode(FOC_NotAllowed);
  705. return false;
  706. }
  707. if (!motor.b_start) {
  708. PMSM_FOC_SetErrCode(FOC_NotAllowed);
  709. return false;
  710. }
  711. if (hold && !mc_throttle_released()) {
  712. PMSM_FOC_SetErrCode(FOC_Throttle_Err);
  713. return false;
  714. }
  715. u32 mask = cpu_enter_critical();
  716. motor.b_auto_hold = hold;
  717. if (!PMSM_FOC_Is_Start()) {
  718. PMSM_FOC_Start(motor.mode);
  719. PMSM_FOC_AutoHold(hold);
  720. pwm_enable_channel();
  721. }else {
  722. PMSM_FOC_AutoHold(hold);
  723. }
  724. cpu_exit_critical(mask);
  725. return true;
  726. }
  727. void mc_set_critical_error(u8 err) {
  728. motor.n_CritiCalErrMask |= (1u << err);
  729. }
  730. void mc_clr_critical_error(u8 err) {
  731. motor.n_CritiCalErrMask &= ~(1u << err);
  732. }
  733. u32 mc_get_critical_error(void) {
  734. return motor.n_CritiCalErrMask;
  735. }
  736. bool mc_throttle_released(void) {
  737. if (motor.b_ignor_throttle) {
  738. return motor.u_throttle_ration == 0;
  739. }
  740. return get_throttle_float() <= nv_get_foc_params()->n_startThroVol;
  741. }
  742. static bool mc_is_gpio_mlock(void) {
  743. int count = 50;
  744. int settimes = 0;
  745. while(count-- > 0) {
  746. bool b1 = gpio_motor_locked();
  747. if (b1) {
  748. settimes ++;
  749. }
  750. delay_us(1);
  751. }
  752. if (settimes == 0) {
  753. return false;
  754. }else if (settimes == 50) {
  755. return true;
  756. }
  757. //有干扰,do nothing
  758. return false;
  759. }
  760. static bool mc_is_hwbrake(void) {
  761. int count = 50;
  762. int settimes = 0;
  763. while(count-- > 0) {
  764. bool b1 = mc_get_gpio_brake() && mc_get_gpio_brake1();
  765. if (b1) {
  766. settimes ++;
  767. }
  768. delay_us(1);
  769. }
  770. if (settimes == 0) {
  771. #if GPIO_BREAK_MODE==GPIO_LOW_BRK_MODE
  772. return true;
  773. #else
  774. return false;
  775. #endif
  776. }else if (settimes == 50) {
  777. #if GPIO_BREAK_MODE==GPIO_LOW_BRK_MODE
  778. return false;
  779. #else
  780. return true;
  781. #endif
  782. }
  783. //有干扰,do nothing
  784. motor.n_brake_errors++;
  785. return false;
  786. }
  787. static void _fan_det_timer_handler(shark_timer_t *t) {
  788. if (t == &_fan_det_timer1) {
  789. motor.fan[0].rpm = 0;
  790. motor.fan[0].det_ts = 0;
  791. }else {
  792. motor.fan[1].rpm = 0;
  793. motor.fan[1].det_ts = 0;
  794. }
  795. }
  796. void Fan_IRQHandler(int idx) {
  797. fan_t *fan = motor.fan + idx;
  798. u32 pre_ts = fan->det_ts;
  799. u32 delta_ts = get_delta_ms(pre_ts);
  800. fan->det_ts = get_tick_ms();
  801. float rpm = 60.0f * 1000 / (float)delta_ts;
  802. LowPass_Filter(fan->rpm, rpm, 0.1f);
  803. if (idx == 0) {
  804. shark_timer_post(&_fan_det_timer1, 100);
  805. }else {
  806. shark_timer_post(&_fan_det_timer2, 100);
  807. }
  808. }
  809. void MC_Brake_IRQHandler(void) {
  810. if (mc_is_hwbrake()) {
  811. motor.b_break = true;
  812. }else {
  813. motor.b_break = false;
  814. }
  815. if (!motor.b_start) {
  816. return;
  817. }
  818. if (motor.b_break) {
  819. PMSM_FOC_Brake(true);
  820. }else {
  821. PMSM_FOC_Brake(false);
  822. }
  823. }
  824. static void _pwm_brake_prot_timer_handler(shark_timer_t *t){
  825. pwm_brake_enable(true);
  826. sys_debug("MC protect error\n");
  827. }
  828. void MC_Protect_IRQHandler(void){
  829. pwm_brake_enable(false);
  830. shark_timer_post(&_brake_prot_timer, 1000);
  831. if (!motor.b_start) {
  832. return;
  833. }
  834. mc_set_critical_error(FOC_CRIT_Phase_Err);
  835. _mc_internal_init(CTRL_MODE_OPEN, false);
  836. adc_stop_convert();
  837. pwm_stop();
  838. PMSM_FOC_Stop();
  839. pwm_up_enable(true);
  840. }
  841. void TIMER_UP_IRQHandler(void){
  842. if (!motor.b_start && !PMSM_FOC_Is_Start()) {
  843. motor_encoder_update();
  844. }
  845. }
  846. measure_time_t g_meas_foc = {.exec_max_time = 20, .intval_max_time = 62, .intval_low_err = 0, .intval_hi_err = 0, .first = true,};
  847. #define TIME_MEATURE_START() time_measure_start(&g_meas_foc)
  848. #define TIME_MEATURE_END() time_measure_end(&g_meas_foc)
  849. /*ADC 电流采集中断,调用FOC的核心处理函数*/
  850. void ADC_IRQHandler(void) {
  851. if (phase_current_offset()) {//check if is adc offset checked
  852. return;
  853. }
  854. if (phase_current_sensor_do_calibrate()){
  855. pwm_update_duty(100, FOC_PWM_Half_Period-100, 100);
  856. pwm_update_sample(FOC_PWM_Half_Period-1, FOC_PWM_Half_Period+1, PHASE_BC);
  857. return;
  858. }
  859. TIME_MEATURE_START();
  860. PMSM_FOC_Schedule();
  861. TIME_MEATURE_END();
  862. }
  863. #ifndef CONFIG_DQ_STEP_RESPONSE
  864. static bool mc_can_stop_foc(void) {
  865. if (mc_throttle_released() && PMSM_FOC_GetSpeed() == 0.0f) {
  866. if (!PMSM_FOC_AutoHoldding() && motor.epm_dir == EPM_Dir_None) {
  867. return true;
  868. }
  869. }
  870. /* 启用无感观测器,同时速度低于观测器允许的最小速度,关闭输出,滑行 */
  871. if (!foc_observer_is_encoder() && PMSM_FOC_GetSpeed() < CONFIG_SMO_MIN_SPEED) {
  872. return true;
  873. }
  874. return false;
  875. }
  876. static bool mc_can_restart_foc(void) {
  877. return (!PMSM_FOC_Is_Start()) && (!mc_throttle_released()) && (!mc_unsafe_critical_error());
  878. }
  879. #endif
  880. static bool mc_run_stall_process(u8 run_mode) {
  881. if ((run_mode == CTRL_MODE_TRQ || run_mode == CTRL_MODE_SPD) && !PMSM_FOC_AutoHoldding()) {
  882. //堵转判断
  883. if (motor.b_runStall) {
  884. if (!mc_throttle_released()) {
  885. return true;
  886. }
  887. motor.runStall_time = 0;
  888. motor.b_runStall = false; //转把释放,清除堵转标志
  889. }else if (PMSM_FOC_Get_Real_dqVector() >= CONFIG_STALL_MAX_CURRENT){
  890. if (ABS(PMSM_FOC_GetSpeed()) < 1.0f && (motor.runStall_time == 0)) {
  891. motor.runStall_time = get_tick_ms();
  892. motor.runStall_pos = motor_encoder_get_position();
  893. }
  894. if (motor.runStall_time > 0) {
  895. if (get_delta_ms(motor.runStall_time) >= CONFIG_STALL_MAX_TIME) {
  896. motor.b_runStall = true;
  897. motor.runStall_time = 0;
  898. PMSM_FOC_Set_Torque(0);
  899. #if 0
  900. torque_reset();
  901. #else
  902. thro_torque_reset();
  903. #endif
  904. return true;
  905. }
  906. if (ABS(motor.runStall_pos - motor_encoder_get_position()) >= 0.2f) {
  907. motor.runStall_time = 0;
  908. }
  909. }
  910. }else {
  911. motor.runStall_time = 0;
  912. }
  913. }
  914. return false;
  915. }
  916. static void _autohold_beep_timer_handler(shark_timer_t *t) {
  917. gpio_beep(60);
  918. }
  919. static void mc_autohold_process(void) {
  920. if (nv_get_foc_params()->n_autoHold == 0) {
  921. if (PMSM_FOC_AutoHoldding()) {
  922. mc_auto_hold(false);
  923. }
  924. return;
  925. }
  926. if (PMSM_FOC_AutoHoldding()) {
  927. if (!mc_throttle_released()) {
  928. mc_auto_hold(false);
  929. motor.b_wait_brk_release = false;
  930. }else if (!motor.b_break && motor.b_wait_brk_release) {
  931. motor.b_wait_brk_release = false;
  932. }else if (motor.b_break && !motor.b_wait_brk_release) {
  933. mc_auto_hold(false);
  934. }
  935. }
  936. if (!PMSM_FOC_AutoHoldding() && motor.b_break && (motor_encoder_get_speed() < CONFIG_ZERO_SPEED_RPM)) {
  937. if (motor.n_autohold_time == 0) {
  938. motor.n_autohold_time = get_tick_ms();
  939. }else {
  940. if (get_delta_ms(motor.n_autohold_time) >= CONFIG_AUTOHOLD_DETECT_TIME) {
  941. if (mc_auto_hold(true)) {
  942. motor.b_wait_brk_release = true;
  943. shark_timer_post(&_autohold_beep_timer, 0);
  944. }
  945. }
  946. }
  947. }else {
  948. motor.n_autohold_time = 0;
  949. }
  950. }
  951. static void mc_process_throttle_epm(void) {
  952. if (!motor.b_epm_cmd_move) {//通过命令前进后退,不处理转把
  953. if (mc_throttle_released()) {
  954. mc_throttle_epm_move(EPM_Dir_None);
  955. }else {
  956. mc_throttle_epm_move(EPM_Dir_Forward);
  957. }
  958. }
  959. }
  960. static bool mc_process_force_running(void) {
  961. if (motor.b_calibrate || (motor.mode == CTRL_MODE_OPEN)) {
  962. if (motor.b_force_run) {
  963. if (_force_wait > 0) {
  964. --_force_wait;
  965. }else {
  966. _force_angle += 1.0f;
  967. rand_angle(_force_angle);
  968. PMSM_FOC_Set_Angle(_force_angle);
  969. }
  970. }
  971. return true;
  972. }
  973. return false;
  974. }
  975. #ifdef CONFIG_CRUISE_ENABLE_ACCL
  976. static void mc_process_curise(void) {
  977. static bool can_pause_resume = false;
  978. if (motor.b_cruise) {
  979. if (PMSM_FOC_GetSpeed() < CONFIG_MIN_CRUISE_RPM) {
  980. mc_enable_cruise(false);
  981. return;
  982. }
  983. /* 定速巡航模式下,必须转把归位后才能开始通过拧动转把加速 */
  984. if (mc_throttle_released() && !can_pause_resume) {
  985. can_pause_resume = true;
  986. }
  987. if (!can_pause_resume) {
  988. return;
  989. }
  990. if (PMSM_FOC_Is_CruiseEnabled()) {
  991. u32 cruise_time = shark_get_seconds() - motor.cruise_time;
  992. if ((cruise_time >= 3) && motor.cruise_torque == 0.0f) {
  993. motor.cruise_torque = PMSM_FOC_Get()->in.s_targetTorque;
  994. }else if ((cruise_time >= 3) && (motor.cruise_torque > 0.0f)){
  995. #if 0
  996. float trq_req = get_thro_request_torque();
  997. #else
  998. float trq_req = get_user_request_torque();
  999. #endif
  1000. if (trq_req > motor.cruise_torque * 1.2f) {
  1001. PMSM_FOC_PauseCruise(); //需要加速,暂停定速巡航
  1002. }
  1003. }
  1004. }else {
  1005. #if 0
  1006. float trq_req = get_thro_request_torque();
  1007. #else
  1008. float trq_req = get_user_request_torque();
  1009. #endif
  1010. if (trq_req <= motor.cruise_torque * 1.1f) {
  1011. PMSM_FOC_ResumeCruise(); //重新开始定速巡航,巡航速度还是前一次定速巡航给的速度
  1012. motor.cruise_time = shark_get_seconds();
  1013. }
  1014. }
  1015. }else {
  1016. can_pause_resume = false;
  1017. }
  1018. }
  1019. #endif
  1020. /*FOC 的部分处理,比如速度环,状态机,转把采集等*/
  1021. measure_time_t g_meas_MCTask;
  1022. #define mc_TaskStart time_measure_start(&g_meas_MCTask)
  1023. #define mc_TaskEnd time_measure_end(&g_meas_MCTask)
  1024. void Sched_MC_mTask(void) {
  1025. mc_TaskStart;
  1026. adc_vref_filter();
  1027. #ifdef CONFIG_CRUISE_ENABLE_ACCL
  1028. mc_process_curise();
  1029. #endif
  1030. u8 runMode = PMSM_FOC_CtrlMode();
  1031. /*保护功能*/
  1032. bool limted = PMSM_FOC_RunTime_Limit();
  1033. /* 母线电流,实际采集的相电流矢量大小的计算 */
  1034. PMSM_FOC_Calc_Current();
  1035. if (mc_process_force_running()) {
  1036. mc_TaskEnd;
  1037. return;
  1038. }
  1039. if (mc_detect_vbus_mode() || limted) {
  1040. mc_gear_vmode_changed();
  1041. }
  1042. /* 堵转处理 */
  1043. if (mc_run_stall_process(runMode) || (runMode == CTRL_MODE_CURRENT)) {
  1044. eCtrl_Running();
  1045. PMSM_FOC_Slow_Task();
  1046. mc_TaskEnd;
  1047. return;
  1048. }
  1049. if ((runMode != CTRL_MODE_OPEN) || (motor.mode != CTRL_MODE_OPEN)) {
  1050. #ifndef CONFIG_DQ_STEP_RESPONSE
  1051. mc_autohold_process();
  1052. if (motor.mode != CTRL_MODE_OPEN) {
  1053. u32 mask;
  1054. if (mc_can_stop_foc()) {
  1055. if (PMSM_FOC_Is_Start()) {
  1056. mask = cpu_enter_critical();
  1057. PMSM_FOC_Stop();
  1058. pwm_disable_channel();
  1059. cpu_exit_critical(mask);
  1060. }
  1061. }
  1062. if (mc_can_restart_foc()) {
  1063. mask = cpu_enter_critical();
  1064. PMSM_FOC_Start(motor.mode);
  1065. mc_gear_vmode_changed();
  1066. #if 0
  1067. torque_reset();
  1068. #else
  1069. thro_torque_reset();
  1070. #endif
  1071. pwm_enable_channel();
  1072. cpu_exit_critical(mask);
  1073. }
  1074. }
  1075. if (runMode != CTRL_MODE_OPEN) {
  1076. eCtrl_Running();
  1077. if ((runMode == CTRL_MODE_SPD) && mc_is_epm()) {
  1078. mc_process_throttle_epm();
  1079. }else {
  1080. #if 0
  1081. if (motor.b_ignor_throttle) { //使用软件设置的油门开度
  1082. float r = (float)motor.u_throttle_ration/100.0f;
  1083. request_torque(r);
  1084. }else {
  1085. throttle_process(runMode, get_throttle_float());
  1086. }
  1087. #else
  1088. float thro = get_throttle_float();
  1089. if (motor.b_ignor_throttle) {
  1090. float r = (float)motor.u_throttle_ration/100.0f;
  1091. thro = thro_ration_to_voltage(r);
  1092. }
  1093. thro_torque_process(runMode, thro);
  1094. #endif
  1095. }
  1096. PMSM_FOC_Slow_Task();
  1097. }
  1098. #endif
  1099. }
  1100. mc_TaskEnd;
  1101. }