encoder.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. #include "bsp/bsp.h"
  2. #include "bsp/bsp_driver.h"
  3. #include "foc/motor/encoder.h"
  4. #include "foc/motor/motor_param.h"
  5. #include "libs/logger.h"
  6. #include "app/nv_storage.h"
  7. #include "math/fast_math.h"
  8. #if CONFIG_MOT_TYPE==MOTOR_BLUESHARK_OLD
  9. #include "encoder_off2.h"
  10. #elif CONFIG_MOT_TYPE==MOTOR_BLUESHARK_NEW1
  11. #include "encoder_off3.h"
  12. #elif CONFIG_MOT_TYPE==MOTOR_BLUESHARK_NEW2
  13. #if ENCODER_TYPE==ENCODER_MPS
  14. #include "encoder_off4.h"
  15. #endif
  16. #elif CONFIG_MOT_TYPE==MOTOR_BLUESHARK_ZD_100
  17. #if ENCODER_TYPE==ENCODER_MPS
  18. #include "encoder_off5.h"
  19. #endif
  20. #endif
  21. /* 磁编码器使用一对极的磁铁,所以编码器获取的角度和机械角度相同需要转为电角度*/
  22. static encoder_t g_encoder;
  23. static __INLINE s16 _abi_count(void) {
  24. #ifdef ENCODER_CC_INVERT
  25. return ((g_encoder.cpr -1) - (s16)ENC_COUNT);
  26. #else
  27. return (s16)ENC_COUNT;
  28. #endif
  29. }
  30. static __INLINE void encoder_pll_update_gain(void) {
  31. if (g_encoder.pll_bandwidth_shadow != g_encoder.pll_bandwidth) {
  32. g_encoder.pll_bandwidth = g_encoder.pll_bandwidth_shadow;
  33. g_encoder.est_pll.kp = 2.0f * g_encoder.pll_bandwidth;
  34. g_encoder.est_pll.ki = 0.25f * g_encoder.est_pll.kp * g_encoder.est_pll.kp;
  35. }
  36. }
  37. static void _init_pll(void) {
  38. g_encoder.est_pll.DT = FOC_CTRL_US;
  39. g_encoder.est_pll.max_wp = g_encoder.cpr;
  40. g_encoder.pll_bandwidth = 0;
  41. g_encoder.pll_bandwidth_shadow = nv_get_motor_params()->est_pll_band;
  42. encoder_pll_update_gain();
  43. PLL_Reset(&g_encoder.est_pll, (float)_abi_count());
  44. }
  45. void encoder_init(void) {
  46. encoder_init_clear();
  47. enc_intf_init(ENC_MAX_RES);
  48. }
  49. void encoder_set_direction(s8 direction) {
  50. g_encoder.direction = direction;
  51. //g_encoder.cali_angle = INVALID_ANGLE;
  52. }
  53. void encoder_set_bandwidth(float bandwidth) {
  54. g_encoder.pll_bandwidth_shadow = bandwidth;
  55. }
  56. void encoder_init_clear(void) {
  57. g_encoder.cpr = ENC_MAX_RES;
  58. g_encoder.enc_offset = 0;
  59. g_encoder.motor_poles = nv_get_motor_params()->poles;
  60. g_encoder.b_index_found = false;
  61. g_encoder.direction = POSITIVE;
  62. g_encoder.abi_angle = 0.0f;
  63. g_encoder.pwm_angle = 0.0f;
  64. g_encoder.est_angle_counts = 0;
  65. g_encoder.est_vel_counts = 0;
  66. g_encoder.est_vel_cnt_filter = 0;
  67. g_encoder.position = 0.0f;
  68. g_encoder.interpolation = 0.0f;
  69. //g_encoder.cali_angle = INVALID_ANGLE;
  70. g_encoder.enc_count_off = 0xFFFFFFFF;
  71. g_encoder.b_cali_err = false;
  72. g_encoder.produce_error = false;
  73. g_encoder.last_delta_cnt = MAX_S16;
  74. g_encoder.enc_maybe_err = ENCODER_NO_ERR;
  75. g_encoder.start_dianostic_cnt = 0;
  76. g_encoder.align_cnt = 0;
  77. g_encoder.align_step = 0;
  78. g_encoder.pwm_time_ms = get_tick_ms();
  79. _init_pll();
  80. }
  81. void encoder_lock_position(bool enable) {
  82. if (g_encoder.b_lock_pos != enable) {
  83. g_encoder.b_lock_pos = enable;
  84. if (enable) {
  85. encoder_set_bandwidth(nv_get_motor_params()->pos_lock_pll_band);
  86. }else {
  87. encoder_set_bandwidth(nv_get_motor_params()->est_pll_band);
  88. }
  89. }
  90. }
  91. void encoder_epm_pll_band(bool epm) {
  92. if (epm) {
  93. encoder_set_bandwidth(nv_get_motor_params()->epm_pll_band);
  94. }else {
  95. encoder_set_bandwidth(nv_get_motor_params()->est_pll_band);
  96. }
  97. }
  98. static __INLINE float _pll_over_comp(void) {
  99. u8 dir = ENC_DIR_DOWN;
  100. #ifdef ENCODER_CC_INVERT
  101. dir = ENC_DIR_UP;
  102. #endif
  103. if(ENC_Direction() == dir){
  104. return -((float)g_encoder.cpr);
  105. }
  106. return (float)g_encoder.cpr;
  107. }
  108. static __INLINE bool encoder_run_pll(float cnt) {
  109. float pll_comp = 0.0f;
  110. if (g_encoder.b_timer_ov) {
  111. pll_comp = _pll_over_comp();
  112. g_encoder.b_timer_ov = false;
  113. }
  114. encoder_pll_update_gain();
  115. g_encoder.est_vel_counts = PLL_run(&g_encoder.est_pll, cnt, pll_comp);
  116. g_encoder.est_angle_counts = g_encoder.est_pll.observer;
  117. bool snap_to_zero_vel = false;
  118. g_encoder.est_vel_cnt_filter = LowPass_Filter(g_encoder.est_vel_cnt_filter, g_encoder.est_vel_counts, 0.1f);
  119. if (ABS(g_encoder.est_pll.out) < 0.5f * g_encoder.est_pll.DT * g_encoder.est_pll.ki) {
  120. g_encoder.est_vel_cnt_filter = g_encoder.est_vel_counts = g_encoder.est_pll.out = 0.0f; // align delta-sigma on zero to prevent jitter
  121. snap_to_zero_vel = true;
  122. }
  123. return snap_to_zero_vel;
  124. }
  125. /* 偏心补偿 */
  126. static __INLINE float _eccentricity_compensation(int cnt) {
  127. #ifdef FIR_PHASE_SHIFT
  128. int cnt_off = (cnt + FIR_PHASE_SHIFT);//g_encoder.cpr;
  129. if (g_encoder.encoder_off_map != NULL) { //do offset calibrate, can not do encentricity compensation
  130. return 0.0f;
  131. }
  132. return -(S16Q10toF(_encoder_off_map[cnt_off]));
  133. #else
  134. return 0.0f;
  135. #endif
  136. }
  137. #define CONFIG_ENC_DETECT_ERR
  138. ///#define CONFIG_ENC_ERR_TEST
  139. #define CONFIG_ENC_DIANOSTIC_MIN_CNT (10.0F * ENC_MAX_RES * FOC_CTRL_US) //600rpm, 每隔控制周期 0.2232 机械角度
  140. u32 enc_pwm_err_ms = 0;
  141. s16 enc_delta_err1 = 0;
  142. s16 enc_delta_err2 = 0;
  143. static s16 enc_r = 0;
  144. static s16 enc_cnt = 0;
  145. static s16 enc_last_cnt = 0;
  146. static s16 enc_test1 = 0;
  147. static s16 enc_test2 = 0;
  148. static s16 enc_test3 = 0;
  149. static s16 enc_test4 = 0;
  150. #define MAX_CPR_CNT_PER_CTL 40
  151. /* 9000RPM = 150 RPS = 150 * ENC_MAX_RES * FOC_CTRL_US = 39, 每个控制周期 39个count */
  152. static void encoder_detect_error(s16 cnt) {
  153. #ifdef CONFIG_ENC_DETECT_ERR
  154. static u32 _mayerr_cnt = 0;
  155. if (ENCODER_NO_ERR == g_encoder.enc_maybe_err) {
  156. s16 delta_cnt = cnt - g_encoder.last_cnt;
  157. bool skip = false;
  158. if (g_encoder.b_timer_ov) {
  159. bool is_jitter = ((cnt > (ENC_MAX_RES - MAX_CPR_CNT_PER_CTL*2) && g_encoder.last_cnt > (ENC_MAX_RES - MAX_CPR_CNT_PER_CTL*2)) ||
  160. (cnt < (MAX_CPR_CNT_PER_CTL*2) && g_encoder.last_cnt < (MAX_CPR_CNT_PER_CTL*2))); //需要处理低速在overflow附近震荡
  161. if (!is_jitter) {
  162. s16 com = _pll_over_comp();
  163. if (com > 0) {
  164. delta_cnt = delta_cnt + com;
  165. }else {
  166. delta_cnt = delta_cnt + com;
  167. }
  168. enc_test4 = delta_cnt;
  169. }
  170. }
  171. if ((delta_cnt > 200) || (delta_cnt < -200)) {
  172. enc_test1 = cnt;
  173. enc_test2 = g_encoder.last_cnt;
  174. enc_test3 = g_encoder.b_timer_ov;
  175. }
  176. #ifdef CONFIG_ENC_ERR_TEST
  177. if (g_encoder.produce_error) {
  178. delta_cnt = 0;
  179. }
  180. #endif
  181. if (g_encoder.last_delta_cnt == MAX_S16) {
  182. g_encoder.last_delta_cnt = delta_cnt;
  183. skip = true;
  184. }
  185. if ((g_encoder.last_delta_cnt <= CONFIG_ENC_DIANOSTIC_MIN_CNT*1.2f) && get_delta_ms(g_encoder.pwm_time_ms) >= 8) {
  186. g_encoder.enc_maybe_err = ENCODER_PWM_ERR;
  187. enc_pwm_err_ms = get_delta_ms(g_encoder.pwm_time_ms);
  188. enc_delta_err2 = (s16)((g_encoder.est_vel_counts/g_encoder.cpr) * 60.0f);
  189. }
  190. if (g_encoder.start_dianostic_cnt < 0xFFFF) {
  191. g_encoder.start_dianostic_cnt ++;
  192. }
  193. if (!skip && ((g_encoder.last_delta_cnt > CONFIG_ENC_DIANOSTIC_MIN_CNT) || (_mayerr_cnt != 0)) && (g_encoder.start_dianostic_cnt >= 1000)) {
  194. float last_delta = (float)g_encoder.last_delta_cnt;
  195. float r = (float)delta_cnt / (last_delta + 0.0000001f);
  196. float r_abs = ABS(r);
  197. float r_thr;
  198. u32 cnt_thr;
  199. if (g_encoder.last_delta_cnt <= CONFIG_ENC_DIANOSTIC_MIN_CNT * 2) { //0.4个机械角度
  200. r_thr = 0.3f;
  201. cnt_thr = 4;
  202. }else if (g_encoder.last_delta_cnt <= CONFIG_ENC_DIANOSTIC_MIN_CNT * 4) { //0.8个机械角度
  203. r_thr = 0.5f;
  204. cnt_thr = 3;
  205. }else if (g_encoder.last_delta_cnt <= CONFIG_ENC_DIANOSTIC_MIN_CNT * 6) { //1.3个机械角度
  206. r_thr = 0.6f;
  207. cnt_thr = 2;
  208. }else {
  209. r_thr = 0.7f;
  210. cnt_thr = 1;
  211. }
  212. if (r_thr >= 0.5f) {
  213. if (r < 0) {
  214. r_thr = 2.0f;
  215. }else if (r_abs <= 0.01f) {
  216. cnt_thr = 1;
  217. }
  218. }
  219. if (r_abs <= r_thr || r_abs >= (2.0f - r_thr)) {
  220. _mayerr_cnt ++;
  221. if (_mayerr_cnt >= cnt_thr) {
  222. g_encoder.enc_maybe_err = ENCODER_AB_ERR;
  223. enc_delta_err1 = g_encoder.last_delta_cnt;
  224. enc_delta_err2 = (s16)((g_encoder.est_vel_counts/g_encoder.cpr) * 60.0f);
  225. enc_r = r*100;
  226. enc_cnt = cnt;
  227. enc_last_cnt = g_encoder.last_cnt;
  228. }
  229. }else {
  230. _mayerr_cnt = 0;
  231. }
  232. }else {
  233. _mayerr_cnt = 0;
  234. }
  235. g_encoder.last_delta_cnt = delta_cnt;
  236. }
  237. #else
  238. g_encoder.enc_maybe_err = ENCODER_NO_ERR;
  239. #endif
  240. }
  241. float encoder_get_theta(void) {
  242. if (!g_encoder.b_index_found) {
  243. return g_encoder.pwm_angle;
  244. }
  245. s16 cnt = _abi_count();
  246. __NOP();__NOP();__NOP();__NOP();
  247. if (ENC_OverFlow()) {
  248. cnt = _abi_count();
  249. if((cnt > (ENC_MAX_RES - MAX_CPR_CNT_PER_CTL*2) && g_encoder.last_cnt > (ENC_MAX_RES - MAX_CPR_CNT_PER_CTL*2)) ||
  250. (cnt < (MAX_CPR_CNT_PER_CTL*2) && g_encoder.last_cnt < (MAX_CPR_CNT_PER_CTL*2))) { //需要处理低速在overflow附近震荡
  251. g_encoder.b_timer_ov = false;
  252. }else {
  253. g_encoder.b_timer_ov = true;
  254. }
  255. ENC_ClearUpFlags();
  256. }
  257. encoder_detect_error(cnt);
  258. bool snap_to_zero_vel = encoder_run_pll((float)(cnt));
  259. if (snap_to_zero_vel) {
  260. g_encoder.interpolation = 0.1f;
  261. }else {
  262. if (cnt == g_encoder.last_cnt) {
  263. g_encoder.interpolation += g_encoder.est_vel_cnt_filter * FOC_CTRL_US;
  264. if (g_encoder.interpolation > ENC_MAX_interpolation) {
  265. g_encoder.interpolation = ENC_MAX_interpolation;
  266. }else if (g_encoder.interpolation < -ENC_MAX_interpolation) {
  267. g_encoder.interpolation = -ENC_MAX_interpolation;
  268. }
  269. }else {
  270. g_encoder.interpolation = 0.0f;
  271. }
  272. }
  273. step_towards_s16(&g_encoder.align_step, g_encoder.align_cnt, 2);
  274. g_encoder.abi_angle = ENC_Pluse_Nr_2_angle((float)(cnt/* + g_encoder.align_step*/) + g_encoder.interpolation) * g_encoder.motor_poles + g_encoder.enc_offset;
  275. g_encoder.abi_angle += _eccentricity_compensation(cnt);
  276. rand_angle(g_encoder.abi_angle);
  277. g_encoder.last_cnt = cnt;
  278. g_encoder.last_us = task_get_usecond();
  279. g_encoder.position += (g_encoder.est_vel_counts/g_encoder.cpr) * FOC_CTRL_US;
  280. return g_encoder.abi_angle;
  281. }
  282. void encoder_produce_error(bool error) {
  283. g_encoder.produce_error = error;
  284. }
  285. u8 encoder_may_error(void) {
  286. return g_encoder.enc_maybe_err;
  287. }
  288. float encoder_get_speed(void) {
  289. if (g_encoder.enc_maybe_err != ENCODER_NO_ERR) {
  290. return 0;
  291. }
  292. return (g_encoder.est_vel_counts/g_encoder.cpr) * 60.0f;
  293. }
  294. float encoder_get_vel_count(void) {
  295. return g_encoder.est_vel_counts;
  296. }
  297. float encoder_get_position(void) {
  298. return g_encoder.position;
  299. }
  300. float encoder_zero_phase_detect(float *enc_off) {
  301. delay_ms(5);
  302. float total_enc_off = g_encoder.pwm_count;
  303. float prev_offset = g_encoder.enc_offset;
  304. float phase = encoder_get_pwm_angle();
  305. float total_ph = phase;
  306. int count = 0;
  307. for(; count < 10; count++) {
  308. delay_ms(5); //wait time for pwm
  309. float angle_now = encoder_get_pwm_angle();
  310. if (ABS(phase - angle_now) > 2.0f) {
  311. g_encoder.enc_offset = prev_offset;
  312. g_encoder.enc_count_off = 0xFFFFFFFF;
  313. g_encoder.b_cali_err = true;
  314. sys_debug("err %f, %f, %d\n", phase, angle_now, count);
  315. return INVALID_ANGLE;
  316. }
  317. phase = angle_now;
  318. total_ph += phase;
  319. total_enc_off += g_encoder.pwm_count;
  320. }
  321. sys_debug("count = %d, %f, %d\n", count, total_enc_off, g_encoder.pwm_count);
  322. float offset_now = total_ph/(float)(count + 1);
  323. g_encoder.enc_offset = offset_now;
  324. g_encoder.enc_count_off = (u32)(total_enc_off/(float)(count + 1));
  325. if (enc_off) {
  326. *enc_off = (float)g_encoder.enc_count_off;
  327. sys_debug("encoder off %f\n", *enc_off);
  328. }
  329. sys_debug("encoder ph off = %f\n", offset_now);
  330. return offset_now;
  331. }
  332. void encoder_clear_cnt_offset(void) {
  333. g_encoder.b_cali_err = false;
  334. g_encoder.enc_count_off = 0xFFFFFFFF;
  335. }
  336. u32 encoder_get_cnt_offset(void) {
  337. return g_encoder.enc_count_off;
  338. }
  339. bool encoder_get_cali_error(void) {
  340. return g_encoder.b_cali_err;
  341. }
  342. static void encoder_sync_pwm_abs(void) {
  343. u32 mask = cpu_enter_critical();
  344. ENC_COUNT = g_encoder.pwm_count;
  345. g_encoder.last_cnt = g_encoder.pwm_count;
  346. g_encoder.est_pll.observer = (float)g_encoder.pwm_count;
  347. g_encoder.abi_angle = g_encoder.pwm_angle;
  348. g_encoder.b_index_found = true;
  349. g_encoder.last_delta_cnt = MAX_S16;
  350. g_encoder.align_cnt = g_encoder.align_step = 0;
  351. PLL_Reset(&g_encoder.est_pll, (float)_abi_count());
  352. cpu_exit_critical(mask);
  353. }
  354. /*I 信号的中断处理,一圈一个中断*/
  355. static int abi_I_delta = 0xFFFFFFF;
  356. void ENC_ABI_IRQHandler(void) {
  357. g_encoder.z_index_cnt = _abi_count();
  358. #if 0
  359. if (!g_encoder.b_index_found){
  360. encoder_sync_pwm_abs();
  361. }
  362. if (g_encoder.z_index_cnt > 10 && g_encoder.z_index_cnt < (g_encoder.cpr - 10)) {
  363. if (abi_I_delta == 0xFFFFFFF) {
  364. abi_I_delta = g_encoder.z_index_cnt;
  365. }
  366. }
  367. #else
  368. if (g_encoder.z_index_cnt > 10 && g_encoder.z_index_cnt < 50) {
  369. g_encoder.align_cnt = -(g_encoder.z_index_cnt - 5);
  370. }else if (g_encoder.z_index_cnt > (g_encoder.cpr - 50) && g_encoder.z_index_cnt < (g_encoder.cpr - 10)) {
  371. g_encoder.align_cnt = g_encoder.cpr - g_encoder.z_index_cnt - 5;
  372. }else {
  373. if (g_encoder.z_index_cnt <=10 || g_encoder.z_index_cnt >= (g_encoder.cpr - 10)) {
  374. g_encoder.align_cnt = 0;
  375. }else if (g_encoder.enc_maybe_err == ENCODER_NO_ERR){
  376. abi_I_delta = g_encoder.z_index_cnt;
  377. }
  378. }
  379. #endif
  380. }
  381. /* 编码器AB信号读书溢出处理 */
  382. void ENC_TIMER_Overflow(void) {
  383. //g_encoder.b_timer_ov = true;
  384. }
  385. /*PWM 信号捕获一个周期的处理 */
  386. static int pwm_count = 0;
  387. static int pwm_check_count = 0;
  388. static int pwm_duty_err = 0;
  389. static float pwm_err_min = 0;
  390. static float pwm_err_max = 0;
  391. void ENC_PWM_Duty_Handler(float t, float d) {
  392. float duty = ENC_Duty(d, t);
  393. if (duty < ENC_PWM_Min_P || duty > ENC_PWM_Max_P) {
  394. pwm_duty_err++;
  395. if (duty < ENC_PWM_Min_P) {
  396. pwm_err_min = duty;
  397. duty = ENC_PWM_Min_P;
  398. }else {
  399. pwm_err_max = duty;
  400. duty = ENC_PWM_Max_P;
  401. }
  402. }
  403. float Nr = ENC_Duty_2_Pluse_Nr(duty);
  404. if (Nr < 0) {
  405. Nr = 0;
  406. }else if (Nr > ENC_MAX_RES) {
  407. Nr = ENC_MAX_RES;
  408. }
  409. u32 n_nr = (u32)Nr;
  410. if (Nr - n_nr >= 0.5f) {
  411. g_encoder.pwm_count = n_nr + 1;
  412. }else {
  413. g_encoder.pwm_count = n_nr;
  414. }
  415. g_encoder.pwm_angle = ENC_Pluse_Nr_2_angle(Nr) * g_encoder.motor_poles + g_encoder.enc_offset;
  416. rand_angle(g_encoder.pwm_angle);
  417. if (!g_encoder.b_index_found && pwm_count++ >= 10) {
  418. encoder_sync_pwm_abs();
  419. }
  420. pwm_check_count ++;
  421. #ifdef CONFIG_ENC_ERR_TEST
  422. if (!g_encoder.produce_error) {
  423. g_encoder.pwm_time_ms = get_tick_ms();
  424. }
  425. #else
  426. g_encoder.pwm_time_ms = get_tick_ms();
  427. #endif
  428. }
  429. static u32 _check_time = 0;
  430. bool ENC_Check_error(void) {
  431. bool error = false;
  432. if (get_delta_ms(_check_time) > 200) {
  433. if (pwm_check_count == 0) {
  434. error = true;
  435. }
  436. pwm_check_count = 0;
  437. _check_time = get_tick_ms();
  438. }
  439. return error;
  440. }
  441. float encoder_get_pwm_angle(void) {
  442. #ifdef ENCODER_CC_INVERT
  443. g_encoder.pwm_angle = 360.0f - (g_encoder.pwm_angle - g_encoder.enc_offset) + g_encoder.enc_offset;
  444. rand_angle(g_encoder.pwm_angle);
  445. #endif
  446. return g_encoder.pwm_angle;
  447. }
  448. float encoder_get_abi_angle(void) {
  449. s16 cnt = _abi_count();
  450. float angle = ENC_Pluse_Nr_2_angle((float)(cnt + g_encoder.align_step)) * g_encoder.motor_poles + g_encoder.enc_offset;
  451. rand_angle(angle);
  452. return angle;
  453. }
  454. void encoder_log(void) {
  455. sys_debug("pwm %f, abi %f\n", encoder_get_pwm_angle(), encoder_get_abi_angle());
  456. sys_debug("pwm count %d, I count %d,%d,%d\n", g_encoder.pwm_count, abi_I_delta, g_encoder.align_cnt, g_encoder.align_step);
  457. sys_debug("pwm freq %f, err %d, %f, %f\n", enc_get_pwm_freq(), pwm_duty_err, pwm_err_min, pwm_err_max);
  458. if (g_encoder.enc_maybe_err) {
  459. sys_debug("E:%d,%d,%d,%d,%d,%d, %d\n", enc_test1, enc_test2, enc_test3, enc_r, enc_cnt, enc_last_cnt, enc_test4);
  460. }
  461. }