LibDriver AS5600
Loading...
Searching...
No Matches
driver_as5600_register_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static as5600_handle_t gs_handle;
41
50{
51 uint8_t res;
52 uint8_t status;
53 uint8_t agc;
54 uint16_t magnitude;
55 uint16_t pos;
56 uint16_t pos_check;
57 uint16_t ang;
58 uint16_t ang_check;
59 uint16_t reg;
60 float deg;
61 float deg_check;
62 as5600_info_t info;
63 as5600_bool_t enable;
68 as5600_hysteresis_t hysteresis;
70
71 /* link interface function */
79
80 /* get chip information */
81 res = as5600_info(&info);
82 if (res != 0)
83 {
84 as5600_interface_debug_print("as5600: get info failed.\n");
85
86 return 1;
87 }
88 else
89 {
90 /* print chip information */
91 as5600_interface_debug_print("as5600: chip is %s.\n", info.chip_name);
92 as5600_interface_debug_print("as5600: manufacturer is %s.\n", info.manufacturer_name);
93 as5600_interface_debug_print("as5600: interface is %s.\n", info.interface);
94 as5600_interface_debug_print("as5600: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
95 as5600_interface_debug_print("as5600: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
96 as5600_interface_debug_print("as5600: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
97 as5600_interface_debug_print("as5600: max current is %0.2fmA.\n", info.max_current_ma);
98 as5600_interface_debug_print("as5600: max temperature is %0.1fC.\n", info.temperature_max);
99 as5600_interface_debug_print("as5600: min temperature is %0.1fC.\n", info.temperature_min);
100 }
101
102 /* as5600 init */
103 res = as5600_init(&gs_handle);
104 if (res != 0)
105 {
106 as5600_interface_debug_print("as5600: init failed.\n");
107
108 return 1;
109 }
110
111 /* start register test */
112 as5600_interface_debug_print("as5600: start register test.\n");
113
114 /* as5600_set_start_position/as5600_get_start_position test */
115 as5600_interface_debug_print("as5600: as5600_set_start_position/as5600_get_start_position test.\n");
116
117 pos = rand() % 0xFFF;
118 res = as5600_set_start_position(&gs_handle, pos);
119 if (res != 0)
120 {
121 as5600_interface_debug_print("as5600: set start position failed.\n");
122 (void)as5600_deinit(&gs_handle);
123
124 return 1;
125 }
126 as5600_interface_debug_print("as5600: set start position %d.\n", pos);
127 res = as5600_get_start_position(&gs_handle, &pos_check);
128 if (res != 0)
129 {
130 as5600_interface_debug_print("as5600: get start position failed.\n");
131 (void)as5600_deinit(&gs_handle);
132
133 return 1;
134 }
135 as5600_interface_debug_print("as5600: check start position %s.\n", (pos_check == pos) ? "ok" : "error");
136
137 /* as5600_set_stop_position/as5600_get_stop_position test */
138 as5600_interface_debug_print("as5600: as5600_set_stop_position/as5600_get_stop_position test.\n");
139
140 pos = rand() % 0xFFF;
141 res = as5600_set_stop_position(&gs_handle, pos);
142 if (res != 0)
143 {
144 as5600_interface_debug_print("as5600: set stop position failed.\n");
145 (void)as5600_deinit(&gs_handle);
146
147 return 1;
148 }
149 as5600_interface_debug_print("as5600: set stop position %d.\n", pos);
150 res = as5600_get_stop_position(&gs_handle, &pos_check);
151 if (res != 0)
152 {
153 as5600_interface_debug_print("as5600: get stop position failed.\n");
154 (void)as5600_deinit(&gs_handle);
155
156 return 1;
157 }
158 as5600_interface_debug_print("as5600: check stop position %s.\n", (pos_check == pos) ? "ok" : "error");
159
160 /* as5600_set_max_angle/as5600_get_max_angle test */
161 as5600_interface_debug_print("as5600: as5600_set_max_angle/as5600_get_max_angle test.\n");
162
163 ang = 0;
164 res = as5600_set_max_angle(&gs_handle, ang);
165 if (res != 0)
166 {
167 as5600_interface_debug_print("as5600: set max angle failed.\n");
168 (void)as5600_deinit(&gs_handle);
169
170 return 1;
171 }
172 as5600_interface_debug_print("as5600: set max angle %d.\n", ang);
173 res = as5600_get_max_angle(&gs_handle, &ang_check);
174 if (res != 0)
175 {
176 as5600_interface_debug_print("as5600: get max angle failed.\n");
177 (void)as5600_deinit(&gs_handle);
178
179 return 1;
180 }
181 as5600_interface_debug_print("as5600: check max angle %s.\n", (ang_check == ang) ? "ok" : "error");
182
183 /* as5600_set_watch_dog/as5600_get_watch_dog test */
184 as5600_interface_debug_print("as5600: as5600_set_watch_dog/as5600_get_watch_dog test.\n");
185
186 /* enable watch dog */
187 res = as5600_set_watch_dog(&gs_handle, AS5600_BOOL_TRUE);
188 if (res != 0)
189 {
190 as5600_interface_debug_print("as5600: set watch dog failed.\n");
191 (void)as5600_deinit(&gs_handle);
192
193 return 1;
194 }
195 as5600_interface_debug_print("as5600: enable watch dog.\n");
196 res = as5600_get_watch_dog(&gs_handle, &enable);
197 if (res != 0)
198 {
199 as5600_interface_debug_print("as5600: get watch dog failed.\n");
200 (void)as5600_deinit(&gs_handle);
201
202 return 1;
203 }
204 as5600_interface_debug_print("as5600: check watch dog %s.\n", (enable == AS5600_BOOL_TRUE) ? "ok" : "error");
205
206 /* disable watch dog */
207 res = as5600_set_watch_dog(&gs_handle, AS5600_BOOL_FALSE);
208 if (res != 0)
209 {
210 as5600_interface_debug_print("as5600: set watch dog failed.\n");
211 (void)as5600_deinit(&gs_handle);
212
213 return 1;
214 }
215 as5600_interface_debug_print("as5600: disable watch dog.\n");
216 res = as5600_get_watch_dog(&gs_handle, &enable);
217 if (res != 0)
218 {
219 as5600_interface_debug_print("as5600: get watch dog failed.\n");
220 (void)as5600_deinit(&gs_handle);
221
222 return 1;
223 }
224 as5600_interface_debug_print("as5600: check watch dog %s.\n", (enable == AS5600_BOOL_FALSE) ? "ok" : "error");
225
226 /* as5600_set_fast_filter_threshold/as5600_get_fast_filter_threshold test */
227 as5600_interface_debug_print("as5600: as5600_set_fast_filter_threshold/as5600_get_fast_filter_threshold test.\n");
228
229 /* slow filter only */
231 if (res != 0)
232 {
233 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
234 (void)as5600_deinit(&gs_handle);
235
236 return 1;
237 }
238 as5600_interface_debug_print("as5600: set fast filter threshold slow filter only.\n");
239 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
240 if (res != 0)
241 {
242 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
243 (void)as5600_deinit(&gs_handle);
244
245 return 1;
246 }
247 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_SLOW_FILTER_ONLY) ? "ok" : "error");
248
249 /* 6 lsb */
251 if (res != 0)
252 {
253 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
254 (void)as5600_deinit(&gs_handle);
255
256 return 1;
257 }
258 as5600_interface_debug_print("as5600: set fast filter threshold 6 lsb.\n");
259 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
260 if (res != 0)
261 {
262 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
263 (void)as5600_deinit(&gs_handle);
264
265 return 1;
266 }
267 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_6LSB) ? "ok" : "error");
268
269 /* 7 lsb */
271 if (res != 0)
272 {
273 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
274 (void)as5600_deinit(&gs_handle);
275
276 return 1;
277 }
278 as5600_interface_debug_print("as5600: set fast filter threshold 7 lsb.\n");
279 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
280 if (res != 0)
281 {
282 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
283 (void)as5600_deinit(&gs_handle);
284
285 return 1;
286 }
287 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_7LSB) ? "ok" : "error");
288
289 /* 9 lsb */
291 if (res != 0)
292 {
293 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
294 (void)as5600_deinit(&gs_handle);
295
296 return 1;
297 }
298 as5600_interface_debug_print("as5600: set fast filter threshold 9 lsb.\n");
299 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
300 if (res != 0)
301 {
302 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
303 (void)as5600_deinit(&gs_handle);
304
305 return 1;
306 }
307 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_9LSB) ? "ok" : "error");
308
309 /* 10 lsb */
311 if (res != 0)
312 {
313 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
314 (void)as5600_deinit(&gs_handle);
315
316 return 1;
317 }
318 as5600_interface_debug_print("as5600: set fast filter threshold 10 lsb.\n");
319 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
320 if (res != 0)
321 {
322 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
323 (void)as5600_deinit(&gs_handle);
324
325 return 1;
326 }
327 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_10LSB) ? "ok" : "error");
328
329 /* 18 lsb */
331 if (res != 0)
332 {
333 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
334 (void)as5600_deinit(&gs_handle);
335
336 return 1;
337 }
338 as5600_interface_debug_print("as5600: set fast filter threshold 18 lsb.\n");
339 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
340 if (res != 0)
341 {
342 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
343 (void)as5600_deinit(&gs_handle);
344
345 return 1;
346 }
347 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_18LSB) ? "ok" : "error");
348
349 /* 21 lsb */
351 if (res != 0)
352 {
353 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
354 (void)as5600_deinit(&gs_handle);
355
356 return 1;
357 }
358 as5600_interface_debug_print("as5600: set fast filter threshold 21 lsb.\n");
359 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
360 if (res != 0)
361 {
362 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
363 (void)as5600_deinit(&gs_handle);
364
365 return 1;
366 }
367 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_21LSB) ? "ok" : "error");
368
369 /* 24 lsb */
371 if (res != 0)
372 {
373 as5600_interface_debug_print("as5600: set fast filter threshold failed.\n");
374 (void)as5600_deinit(&gs_handle);
375
376 return 1;
377 }
378 as5600_interface_debug_print("as5600: set fast filter threshold 24 lsb.\n");
379 res = as5600_get_fast_filter_threshold(&gs_handle, &threshold);
380 if (res != 0)
381 {
382 as5600_interface_debug_print("as5600: get fast filter threshold failed.\n");
383 (void)as5600_deinit(&gs_handle);
384
385 return 1;
386 }
387 as5600_interface_debug_print("as5600: check fast filter threshold %s.\n", (threshold == AS5600_FAST_FILTER_THRESHOLD_24LSB) ? "ok" : "error");
388
389 /* as5600_set_slow_filter/as5600_get_slow_filter test */
390 as5600_interface_debug_print("as5600: as5600_set_slow_filter/as5600_get_slow_filter test.\n");
391
392 /* 16X */
394 if (res != 0)
395 {
396 as5600_interface_debug_print("as5600: set slow filter failed.\n");
397 (void)as5600_deinit(&gs_handle);
398
399 return 1;
400 }
401 as5600_interface_debug_print("as5600: set slow filter 16X.\n");
402 res = as5600_get_slow_filter(&gs_handle, &filter);
403 if (res != 0)
404 {
405 as5600_interface_debug_print("as5600: get slow filter failed.\n");
406 (void)as5600_deinit(&gs_handle);
407
408 return 1;
409 }
410 as5600_interface_debug_print("as5600: check slow filter %s.\n", (filter == AS5600_SLOW_FILTER_16X) ? "ok" : "error");
411
412 /* 8X */
414 if (res != 0)
415 {
416 as5600_interface_debug_print("as5600: set slow filter failed.\n");
417 (void)as5600_deinit(&gs_handle);
418
419 return 1;
420 }
421 as5600_interface_debug_print("as5600: set slow filter 8X.\n");
422 res = as5600_get_slow_filter(&gs_handle, &filter);
423 if (res != 0)
424 {
425 as5600_interface_debug_print("as5600: get slow filter failed.\n");
426 (void)as5600_deinit(&gs_handle);
427
428 return 1;
429 }
430 as5600_interface_debug_print("as5600: check slow filter %s.\n", (filter == AS5600_SLOW_FILTER_8X) ? "ok" : "error");
431
432 /* 4X */
434 if (res != 0)
435 {
436 as5600_interface_debug_print("as5600: set slow filter failed.\n");
437 (void)as5600_deinit(&gs_handle);
438
439 return 1;
440 }
441 as5600_interface_debug_print("as5600: set slow filter 4X.\n");
442 res = as5600_get_slow_filter(&gs_handle, &filter);
443 if (res != 0)
444 {
445 as5600_interface_debug_print("as5600: get slow filter failed.\n");
446 (void)as5600_deinit(&gs_handle);
447
448 return 1;
449 }
450 as5600_interface_debug_print("as5600: check slow filter %s.\n", (filter == AS5600_SLOW_FILTER_4X) ? "ok" : "error");
451
452 /* 2X */
454 if (res != 0)
455 {
456 as5600_interface_debug_print("as5600: set slow filter failed.\n");
457 (void)as5600_deinit(&gs_handle);
458
459 return 1;
460 }
461 as5600_interface_debug_print("as5600: set slow filter 2X.\n");
462 res = as5600_get_slow_filter(&gs_handle, &filter);
463 if (res != 0)
464 {
465 as5600_interface_debug_print("as5600: get slow filter failed.\n");
466 (void)as5600_deinit(&gs_handle);
467
468 return 1;
469 }
470 as5600_interface_debug_print("as5600: check slow filter %s.\n", (filter == AS5600_SLOW_FILTER_2X) ? "ok" : "error");
471
472 /* as5600_set_pwm_frequency/as5600_get_pwm_frequency test */
473 as5600_interface_debug_print("as5600: as5600_set_pwm_frequency/as5600_get_pwm_frequency test.\n");
474
475 /* 115Hz */
477 if (res != 0)
478 {
479 as5600_interface_debug_print("as5600: set pwm frequency failed.\n");
480 (void)as5600_deinit(&gs_handle);
481
482 return 1;
483 }
484 as5600_interface_debug_print("as5600: set pwm frequency 115Hz.\n");
485 res = as5600_get_pwm_frequency(&gs_handle, &freq);
486 if (res != 0)
487 {
488 as5600_interface_debug_print("as5600: get pwm frequency failed.\n");
489 (void)as5600_deinit(&gs_handle);
490
491 return 1;
492 }
493 as5600_interface_debug_print("as5600: check pwm frequency %s.\n", (freq == AS5600_PWM_FREQUENCY_115HZ) ? "ok" : "error");
494
495 /* 230Hz */
497 if (res != 0)
498 {
499 as5600_interface_debug_print("as5600: set pwm frequency failed.\n");
500 (void)as5600_deinit(&gs_handle);
501
502 return 1;
503 }
504 as5600_interface_debug_print("as5600: set pwm frequency 230Hz.\n");
505 res = as5600_get_pwm_frequency(&gs_handle, &freq);
506 if (res != 0)
507 {
508 as5600_interface_debug_print("as5600: get pwm frequency failed.\n");
509 (void)as5600_deinit(&gs_handle);
510
511 return 1;
512 }
513 as5600_interface_debug_print("as5600: check pwm frequency %s.\n", (freq == AS5600_PWM_FREQUENCY_230HZ) ? "ok" : "error");
514
515 /* 460Hz */
517 if (res != 0)
518 {
519 as5600_interface_debug_print("as5600: set pwm frequency failed.\n");
520 (void)as5600_deinit(&gs_handle);
521
522 return 1;
523 }
524 as5600_interface_debug_print("as5600: set pwm frequency 460Hz.\n");
525 res = as5600_get_pwm_frequency(&gs_handle, &freq);
526 if (res != 0)
527 {
528 as5600_interface_debug_print("as5600: get pwm frequency failed.\n");
529 (void)as5600_deinit(&gs_handle);
530
531 return 1;
532 }
533 as5600_interface_debug_print("as5600: check pwm frequency %s.\n", (freq == AS5600_PWM_FREQUENCY_460HZ) ? "ok" : "error");
534
535 /* 920Hz */
537 if (res != 0)
538 {
539 as5600_interface_debug_print("as5600: set pwm frequency failed.\n");
540 (void)as5600_deinit(&gs_handle);
541
542 return 1;
543 }
544 as5600_interface_debug_print("as5600: set pwm frequency 920Hz.\n");
545 res = as5600_get_pwm_frequency(&gs_handle, &freq);
546 if (res != 0)
547 {
548 as5600_interface_debug_print("as5600: get pwm frequency failed.\n");
549 (void)as5600_deinit(&gs_handle);
550
551 return 1;
552 }
553 as5600_interface_debug_print("as5600: check pwm frequency %s.\n", (freq == AS5600_PWM_FREQUENCY_920HZ) ? "ok" : "error");
554
555 /* as5600_set_output_stage/as5600_get_output_stage test */
556 as5600_interface_debug_print("as5600: as5600_set_output_stage/as5600_get_output_stage test.\n");
557
558 /* full range */
560 if (res != 0)
561 {
562 as5600_interface_debug_print("as5600: set output stage failed.\n");
563 (void)as5600_deinit(&gs_handle);
564
565 return 1;
566 }
567 as5600_interface_debug_print("as5600: set output stage full range.\n");
568 res = as5600_get_output_stage(&gs_handle, &stage);
569 if (res != 0)
570 {
571 as5600_interface_debug_print("as5600: get output stage failed.\n");
572 (void)as5600_deinit(&gs_handle);
573
574 return 1;
575 }
576 as5600_interface_debug_print("as5600: check output stage %s.\n", (stage == AS5600_OUTPUT_STAGE_ANALOG_FULL) ? "ok" : "error");
577
578 /* reduced */
580 if (res != 0)
581 {
582 as5600_interface_debug_print("as5600: set output stage failed.\n");
583 (void)as5600_deinit(&gs_handle);
584
585 return 1;
586 }
587 as5600_interface_debug_print("as5600: set output stage reduced.\n");
588 res = as5600_get_output_stage(&gs_handle, &stage);
589 if (res != 0)
590 {
591 as5600_interface_debug_print("as5600: get output stage failed.\n");
592 (void)as5600_deinit(&gs_handle);
593
594 return 1;
595 }
596 as5600_interface_debug_print("as5600: check output stage %s.\n", (stage == AS5600_OUTPUT_STAGE_ANALOG_REDUCED) ? "ok" : "error");
597
598 /* digital pwm */
600 if (res != 0)
601 {
602 as5600_interface_debug_print("as5600: set output stage failed.\n");
603 (void)as5600_deinit(&gs_handle);
604
605 return 1;
606 }
607 as5600_interface_debug_print("as5600: set output stage digital pwm.\n");
608 res = as5600_get_output_stage(&gs_handle, &stage);
609 if (res != 0)
610 {
611 as5600_interface_debug_print("as5600: get output stage failed.\n");
612 (void)as5600_deinit(&gs_handle);
613
614 return 1;
615 }
616 as5600_interface_debug_print("as5600: check output stage %s.\n", (stage == AS5600_OUTPUT_STAGE_PWM) ? "ok" : "error");
617
618 /* as5600_set_hysteresis/as5600_get_hysteresis test */
619 as5600_interface_debug_print("as5600: as5600_set_hysteresis/as5600_get_hysteresis test.\n");
620
621 /* hysteresis off */
623 if (res != 0)
624 {
625 as5600_interface_debug_print("as5600: set hysteresis failed.\n");
626 (void)as5600_deinit(&gs_handle);
627
628 return 1;
629 }
630 as5600_interface_debug_print("as5600: set hysteresis off.\n");
631 res = as5600_get_hysteresis(&gs_handle, &hysteresis);
632 if (res != 0)
633 {
634 as5600_interface_debug_print("as5600: get hysteresis failed.\n");
635 (void)as5600_deinit(&gs_handle);
636
637 return 1;
638 }
639 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (hysteresis == AS5600_HYSTERESIS_OFF) ? "ok" : "error");
640
641 /* hysteresis 1 lsb */
643 if (res != 0)
644 {
645 as5600_interface_debug_print("as5600: set hysteresis failed.\n");
646 (void)as5600_deinit(&gs_handle);
647
648 return 1;
649 }
650 as5600_interface_debug_print("as5600: set hysteresis 1 lsb.\n");
651 res = as5600_get_hysteresis(&gs_handle, &hysteresis);
652 if (res != 0)
653 {
654 as5600_interface_debug_print("as5600: get hysteresis failed.\n");
655 (void)as5600_deinit(&gs_handle);
656
657 return 1;
658 }
659 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (hysteresis == AS5600_HYSTERESIS_1LSB) ? "ok" : "error");
660
661 /* hysteresis 2 lsb */
663 if (res != 0)
664 {
665 as5600_interface_debug_print("as5600: set hysteresis failed.\n");
666 (void)as5600_deinit(&gs_handle);
667
668 return 1;
669 }
670 as5600_interface_debug_print("as5600: set hysteresis 2 lsb.\n");
671 res = as5600_get_hysteresis(&gs_handle, &hysteresis);
672 if (res != 0)
673 {
674 as5600_interface_debug_print("as5600: get hysteresis failed.\n");
675 (void)as5600_deinit(&gs_handle);
676
677 return 1;
678 }
679 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (hysteresis == AS5600_HYSTERESIS_2LSB) ? "ok" : "error");
680
681 /* hysteresis 3 lsb */
683 if (res != 0)
684 {
685 as5600_interface_debug_print("as5600: set hysteresis failed.\n");
686 (void)as5600_deinit(&gs_handle);
687
688 return 1;
689 }
690 as5600_interface_debug_print("as5600: set hysteresis 3 lsb.\n");
691 res = as5600_get_hysteresis(&gs_handle, &hysteresis);
692 if (res != 0)
693 {
694 as5600_interface_debug_print("as5600: get hysteresis failed.\n");
695 (void)as5600_deinit(&gs_handle);
696
697 return 1;
698 }
699 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (hysteresis == AS5600_HYSTERESIS_3LSB) ? "ok" : "error");
700
701 /* as5600_set_power_mode/as5600_get_power_mode test */
702 as5600_interface_debug_print("as5600: as5600_set_power_mode/as5600_get_power_mode test.\n");
703
704 /* nom */
706 if (res != 0)
707 {
708 as5600_interface_debug_print("as5600: set power mode failed.\n");
709 (void)as5600_deinit(&gs_handle);
710
711 return 1;
712 }
713 as5600_interface_debug_print("as5600: set power mode nom.\n");
714 res = as5600_get_power_mode(&gs_handle, &mode);
715 if (res != 0)
716 {
717 as5600_interface_debug_print("as5600: get power mode failed.\n");
718 (void)as5600_deinit(&gs_handle);
719
720 return 1;
721 }
722 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (mode == AS5600_POWER_MODE_NOM) ? "ok" : "error");
723
724 /* lpm1 */
726 if (res != 0)
727 {
728 as5600_interface_debug_print("as5600: set power mode failed.\n");
729 (void)as5600_deinit(&gs_handle);
730
731 return 1;
732 }
733 as5600_interface_debug_print("as5600: set power mode lpm1.\n");
734 res = as5600_get_power_mode(&gs_handle, &mode);
735 if (res != 0)
736 {
737 as5600_interface_debug_print("as5600: get power mode failed.\n");
738 (void)as5600_deinit(&gs_handle);
739
740 return 1;
741 }
742 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (mode == AS5600_POWER_MODE_LPM1) ? "ok" : "error");
743
744 /* lpm2 */
746 if (res != 0)
747 {
748 as5600_interface_debug_print("as5600: set power mode failed.\n");
749 (void)as5600_deinit(&gs_handle);
750
751 return 1;
752 }
753 as5600_interface_debug_print("as5600: set power mode lpm2.\n");
754 res = as5600_get_power_mode(&gs_handle, &mode);
755 if (res != 0)
756 {
757 as5600_interface_debug_print("as5600: get power mode failed.\n");
758 (void)as5600_deinit(&gs_handle);
759
760 return 1;
761 }
762 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (mode == AS5600_POWER_MODE_LPM2) ? "ok" : "error");
763
764 /* lpm3 */
766 if (res != 0)
767 {
768 as5600_interface_debug_print("as5600: set power mode failed.\n");
769 (void)as5600_deinit(&gs_handle);
770
771 return 1;
772 }
773 as5600_interface_debug_print("as5600: set power mode lpm3.\n");
774 res = as5600_get_power_mode(&gs_handle, &mode);
775 if (res != 0)
776 {
777 as5600_interface_debug_print("as5600: get power mode failed.\n");
778 (void)as5600_deinit(&gs_handle);
779
780 return 1;
781 }
782 as5600_interface_debug_print("as5600: check hysteresis %s.\n", (mode == AS5600_POWER_MODE_LPM3) ? "ok" : "error");
783
784 /* as5600_get_raw_angle test */
785 as5600_interface_debug_print("as5600: as5600_get_raw_angle test.\n");
786
787 /* get raw angle */
788 res = as5600_get_raw_angle(&gs_handle, &ang);
789 if (res != 0)
790 {
791 as5600_interface_debug_print("as5600: get raw angle failed.\n");
792 (void)as5600_deinit(&gs_handle);
793
794 return 1;
795 }
796 as5600_interface_debug_print("as5600: get raw angle %d.\n", ang);
797
798 /* as5600_get_angle test */
799 as5600_interface_debug_print("as5600: as5600_get_angle test.\n");
800
801 /* get angle */
802 res = as5600_get_angle(&gs_handle, &ang);
803 if (res != 0)
804 {
805 as5600_interface_debug_print("as5600: get angle failed.\n");
806 (void)as5600_deinit(&gs_handle);
807
808 return 1;
809 }
810 as5600_interface_debug_print("as5600: get angle %d.\n", ang);
811
812 /* as5600_get_status test */
813 as5600_interface_debug_print("as5600: as5600_get_status test.\n");
814
815 /* get status */
816 res = as5600_get_status(&gs_handle, &status);
817 if (res != 0)
818 {
819 as5600_interface_debug_print("as5600: get status failed.\n");
820 (void)as5600_deinit(&gs_handle);
821
822 return 1;
823 }
824 as5600_interface_debug_print("as5600: get status 0x%02X.\n", status);
825
826 /* as5600_get_agc test */
827 as5600_interface_debug_print("as5600: as5600_get_agc test.\n");
828
829 /* get agc */
830 res = as5600_get_agc(&gs_handle, &agc);
831 if (res != 0)
832 {
833 as5600_interface_debug_print("as5600: get agc failed.\n");
834 (void)as5600_deinit(&gs_handle);
835
836 return 1;
837 }
838 as5600_interface_debug_print("as5600: get agc 0x%02X.\n", agc);
839
840 /* as5600_get_magnitude test */
841 as5600_interface_debug_print("as5600: as5600_get_magnitude test.\n");
842
843 /* get magnitude */
844 res = as5600_get_magnitude(&gs_handle, &magnitude);
845 if (res != 0)
846 {
847 as5600_interface_debug_print("as5600: get magnitude failed.\n");
848 (void)as5600_deinit(&gs_handle);
849
850 return 1;
851 }
852 as5600_interface_debug_print("as5600: get magnitude %d.\n", magnitude);
853
854 /* as5600_angle_convert_to_data test */
855 as5600_interface_debug_print("as5600: as5600_angle_convert_to_register/as5600_angle_convert_to_data test.\n");
856
857 /* set the deg */
858 deg = (float)(rand() % 36000) / 10.0f;
859
860 /* convert to register */
861 res = as5600_angle_convert_to_register(&gs_handle, deg, &reg);
862 if (res != 0)
863 {
864 as5600_interface_debug_print("as5600: angle convert to register failed.\n");
865 (void)as5600_deinit(&gs_handle);
866
867 return 1;
868 }
869
870 /* output */
871 as5600_interface_debug_print("as5600: set angle %0.2f.\n", deg);
872
873 /* convert to data */
874 res = as5600_angle_convert_to_data(&gs_handle, reg, &deg_check);
875 if (res != 0)
876 {
877 as5600_interface_debug_print("as5600: angle convert to data failed.\n");
878 (void)as5600_deinit(&gs_handle);
879
880 return 1;
881 }
882 as5600_interface_debug_print("as5600: check angle %0.2f.\n", deg_check);
883
884 /* finish register test */
885 as5600_interface_debug_print("as5600: finish register test.\n");
886 (void)as5600_deinit(&gs_handle);
887
888 return 0;
889}
driver as5600 register test header file
as5600_bool_t
as5600 bool enumeration definition
uint8_t as5600_get_fast_filter_threshold(as5600_handle_t *handle, as5600_fast_filter_threshold_t *threshold)
get the fast filter threshold
uint8_t as5600_get_status(as5600_handle_t *handle, uint8_t *status)
get the status
as5600_output_stage_t
as5600 output stage enumeration definition
uint8_t as5600_info(as5600_info_t *info)
get chip's information
uint8_t as5600_get_watch_dog(as5600_handle_t *handle, as5600_bool_t *enable)
get the watch dog status
uint8_t as5600_get_start_position(as5600_handle_t *handle, uint16_t *pos)
get the start position
as5600_pwm_frequency_t
as5600 pwm frequency enumeration definition
struct as5600_handle_s as5600_handle_t
as5600 handle structure definition
uint8_t as5600_set_fast_filter_threshold(as5600_handle_t *handle, as5600_fast_filter_threshold_t threshold)
set the fast filter threshold
uint8_t as5600_angle_convert_to_register(as5600_handle_t *handle, float deg, uint16_t *reg)
convert the angle to the register raw data
struct as5600_info_s as5600_info_t
as5600 information structure definition
as5600_power_mode_t
as5600 power mode enumeration definition
uint8_t as5600_get_pwm_frequency(as5600_handle_t *handle, as5600_pwm_frequency_t *freq)
get the pwm frequency
uint8_t as5600_angle_convert_to_data(as5600_handle_t *handle, uint16_t reg, float *deg)
convert the register raw data to the angle
uint8_t as5600_set_slow_filter(as5600_handle_t *handle, as5600_slow_filter_t filter)
set the slow filter
uint8_t as5600_get_slow_filter(as5600_handle_t *handle, as5600_slow_filter_t *filter)
get the slow filter
uint8_t as5600_get_power_mode(as5600_handle_t *handle, as5600_power_mode_t *mode)
get the power mode
uint8_t as5600_get_magnitude(as5600_handle_t *handle, uint16_t *magnitude)
get the magnitude
uint8_t as5600_set_hysteresis(as5600_handle_t *handle, as5600_hysteresis_t hysteresis)
set the hysteresis
uint8_t as5600_set_power_mode(as5600_handle_t *handle, as5600_power_mode_t mode)
set the power mode
as5600_slow_filter_t
as5600 slow filter enumeration definition
uint8_t as5600_set_stop_position(as5600_handle_t *handle, uint16_t pos)
set the stop position
uint8_t as5600_get_agc(as5600_handle_t *handle, uint8_t *agc)
get the automatic gain control
uint8_t as5600_set_start_position(as5600_handle_t *handle, uint16_t pos)
set the start position
uint8_t as5600_set_pwm_frequency(as5600_handle_t *handle, as5600_pwm_frequency_t freq)
set the pwm frequency
uint8_t as5600_set_max_angle(as5600_handle_t *handle, uint16_t ang)
set the max angle
uint8_t as5600_init(as5600_handle_t *handle)
initialize the chip
uint8_t as5600_get_max_angle(as5600_handle_t *handle, uint16_t *ang)
get the max angle
uint8_t as5600_set_watch_dog(as5600_handle_t *handle, as5600_bool_t enable)
enable or disable the watch dog
uint8_t as5600_get_angle(as5600_handle_t *handle, uint16_t *ang)
get the angle
uint8_t as5600_get_stop_position(as5600_handle_t *handle, uint16_t *pos)
get the stop position
uint8_t as5600_get_raw_angle(as5600_handle_t *handle, uint16_t *ang)
get the raw angle
uint8_t as5600_deinit(as5600_handle_t *handle)
close the chip
as5600_fast_filter_threshold_t
as5600 fast filter threshold enumeration definition
uint8_t as5600_set_output_stage(as5600_handle_t *handle, as5600_output_stage_t stage)
set the output stage
uint8_t as5600_get_hysteresis(as5600_handle_t *handle, as5600_hysteresis_t *hysteresis)
get the hysteresis
uint8_t as5600_get_output_stage(as5600_handle_t *handle, as5600_output_stage_t *stage)
get the output stage
as5600_hysteresis_t
as5600 hysteresis enumeration definition
@ AS5600_BOOL_TRUE
@ AS5600_BOOL_FALSE
@ AS5600_OUTPUT_STAGE_PWM
@ AS5600_OUTPUT_STAGE_ANALOG_FULL
@ AS5600_OUTPUT_STAGE_ANALOG_REDUCED
@ AS5600_PWM_FREQUENCY_230HZ
@ AS5600_PWM_FREQUENCY_115HZ
@ AS5600_PWM_FREQUENCY_460HZ
@ AS5600_PWM_FREQUENCY_920HZ
@ AS5600_POWER_MODE_LPM1
@ AS5600_POWER_MODE_LPM2
@ AS5600_POWER_MODE_LPM3
@ AS5600_POWER_MODE_NOM
@ AS5600_SLOW_FILTER_8X
@ AS5600_SLOW_FILTER_2X
@ AS5600_SLOW_FILTER_16X
@ AS5600_SLOW_FILTER_4X
@ AS5600_FAST_FILTER_THRESHOLD_7LSB
@ AS5600_FAST_FILTER_THRESHOLD_24LSB
@ AS5600_FAST_FILTER_THRESHOLD_21LSB
@ AS5600_FAST_FILTER_THRESHOLD_9LSB
@ AS5600_FAST_FILTER_THRESHOLD_6LSB
@ AS5600_FAST_FILTER_THRESHOLD_10LSB
@ AS5600_FAST_FILTER_THRESHOLD_18LSB
@ AS5600_FAST_FILTER_THRESHOLD_SLOW_FILTER_ONLY
@ AS5600_HYSTERESIS_2LSB
@ AS5600_HYSTERESIS_OFF
@ AS5600_HYSTERESIS_1LSB
@ AS5600_HYSTERESIS_3LSB
uint8_t as5600_interface_iic_deinit(void)
interface iic bus deinit
uint8_t as5600_interface_iic_init(void)
interface iic bus init
void as5600_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t as5600_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void as5600_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t as5600_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t as5600_register_test(void)
register test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]