Rev 265 | Rev 267 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 265 | Rev 266 | ||
---|---|---|---|
Line 322... | Line 322... | ||
322 | 322 | ||
323 | case 5: |
323 | case 5: |
324 | // Save values |
324 | // Save values |
325 | if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
325 | if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
326 | { |
326 | { |
327 | #define MIN_CALIBRATION 350 |
327 | #define MIN_CALIBRATION 512 |
328 | Calibration.MagX.Range = Xmax - Xmin; |
328 | Calibration.MagX.Range = Xmax - Xmin; |
329 | Calibration.MagX.Offset = (Xmin + Xmax) / 2; |
329 | Calibration.MagX.Offset = (Xmin + Xmax) / 2; |
330 | Calibration.MagY.Range = Ymax - Ymin; |
330 | Calibration.MagY.Range = Ymax - Ymin; |
331 | Calibration.MagY.Offset = (Ymin + Ymax) / 2; |
331 | Calibration.MagY.Offset = (Ymin + Ymax) / 2; |
Line 605... | Line 605... | ||
605 | } |
605 | } |
Line 606... | Line 606... | ||
606 | 606 | ||
607 | // -------------------------------------------------------- |
607 | // -------------------------------------------------------- |
608 | u8 NCMAG_SelfTest(void) |
608 | u8 NCMAG_SelfTest(void) |
- | 609 | { |
|
- | 610 | u8 msg[64]; |
|
609 | { |
611 | |
610 | #define LIMITS(value, min, max) {min = (90 * value)/100; max = (110 * value)/100;} |
612 | #define LIMITS(value, min, max) {min = (90 * value)/100; max = (110 * value)/100;} |
611 | u32 time; |
613 | u32 time; |
612 | s32 XMin = 0, XMax = 0, YMin = 0, YMax = 0, ZMin = 0, ZMax = 0; |
614 | s32 XMin = 0, XMax = 0, YMin = 0, YMax = 0, ZMin = 0, ZMax = 0; |
613 | s16 xscale, yscale, zscale, scale_min, scale_max; |
615 | s16 xscale, yscale, zscale, scale_min, scale_max; |
Line 673... | Line 675... | ||
673 | } |
675 | } |
674 | // setup final configuration |
676 | // setup final configuration |
675 | MagConfig.cra = cra_rate|CRA_MODE_NORMAL; |
677 | MagConfig.cra = cra_rate|CRA_MODE_NORMAL; |
676 | // activate positive bias field |
678 | // activate positive bias field |
677 | NCMAG_SetMagConfig(); |
679 | NCMAG_SetMagConfig(); |
678 | // prepare scale limits |
- | |
679 | LIMITS(xscale, scale_min, scale_max); |
- | |
680 | // check scale for all axes |
680 | // check scale for all axes |
681 | xscale = (XMax - XMin)/(2*AVERAGE); |
681 | xscale = (XMax - XMin)/(2*AVERAGE); |
682 | if((xscale > scale_max) || (xscale < scale_min)) retval = 0; |
682 | // prepare scale limits |
683 | LIMITS(yscale, scale_min, scale_max); |
683 | LIMITS(xscale, scale_min, scale_max); |
- | 684 | if((xscale > scale_max) || (xscale < scale_min)) |
|
- | 685 | { |
|
- | 686 | retval = 0; |
|
- | 687 | sprintf(msg, "\r\n Value X: %d not %d-%d !", xscale, scale_min,scale_max); |
|
- | 688 | UART1_PutString(msg); |
|
- | 689 | } |
|
684 | yscale = (YMax - YMin)/(2*AVERAGE); |
690 | yscale = (YMax - YMin)/(2*AVERAGE); |
- | 691 | LIMITS(yscale, scale_min, scale_max); |
|
685 | if((yscale > scale_max) || (yscale < scale_min)) retval = 0; |
692 | if((yscale > scale_max) || (yscale < scale_min)) |
- | 693 | { |
|
- | 694 | retval = 0; |
|
686 | LIMITS(zscale, scale_min, scale_max); |
695 | sprintf(msg, "\r\n Value Y: %d not %d-%d !", yscale, scale_min,scale_max); |
- | 696 | UART1_PutString(msg); |
|
- | 697 | } |
|
687 | zscale = (ZMax - ZMin)/(2*AVERAGE); |
698 | zscale = (ZMax - ZMin)/(2*AVERAGE); |
- | 699 | LIMITS(zscale, scale_min, scale_max); |
|
688 | if((zscale > scale_max) || (zscale < scale_min)) retval = 0; |
700 | if((zscale > scale_max) || (zscale < scale_min)) |
- | 701 | { |
|
- | 702 | retval = 0; |
|
- | 703 | sprintf(msg, "\r\n Value Z: %d not %d-%d !", zscale, scale_min,scale_max); |
|
- | 704 | UART1_PutString(msg); |
|
- | 705 | } |
|
689 | return(retval); |
706 | return(retval); |
690 | } |
707 | } |
Line 691... | Line 708... | ||
691 | 708 |