324,7 → 324,7 |
// Save values |
if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
{ |
#define MIN_CALIBRATION 350 |
#define MIN_CALIBRATION 512 |
Calibration.MagX.Range = Xmax - Xmin; |
Calibration.MagX.Offset = (Xmin + Xmax) / 2; |
Calibration.MagY.Range = Ymax - Ymin; |
607,6 → 607,8 |
// -------------------------------------------------------- |
u8 NCMAG_SelfTest(void) |
{ |
u8 msg[64]; |
|
#define LIMITS(value, min, max) {min = (90 * value)/100; max = (110 * value)/100;} |
u32 time; |
s32 XMin = 0, XMax = 0, YMin = 0, YMax = 0, ZMin = 0, ZMax = 0; |
675,17 → 677,32 |
MagConfig.cra = cra_rate|CRA_MODE_NORMAL; |
// activate positive bias field |
NCMAG_SetMagConfig(); |
// check scale for all axes |
xscale = (XMax - XMin)/(2*AVERAGE); |
// prepare scale limits |
LIMITS(xscale, scale_min, scale_max); |
// check scale for all axes |
xscale = (XMax - XMin)/(2*AVERAGE); |
if((xscale > scale_max) || (xscale < scale_min)) retval = 0; |
if((xscale > scale_max) || (xscale < scale_min)) |
{ |
retval = 0; |
sprintf(msg, "\r\n Value X: %d not %d-%d !", xscale, scale_min,scale_max); |
UART1_PutString(msg); |
} |
yscale = (YMax - YMin)/(2*AVERAGE); |
LIMITS(yscale, scale_min, scale_max); |
yscale = (YMax - YMin)/(2*AVERAGE); |
if((yscale > scale_max) || (yscale < scale_min)) retval = 0; |
if((yscale > scale_max) || (yscale < scale_min)) |
{ |
retval = 0; |
sprintf(msg, "\r\n Value Y: %d not %d-%d !", yscale, scale_min,scale_max); |
UART1_PutString(msg); |
} |
zscale = (ZMax - ZMin)/(2*AVERAGE); |
LIMITS(zscale, scale_min, scale_max); |
zscale = (ZMax - ZMin)/(2*AVERAGE); |
if((zscale > scale_max) || (zscale < scale_min)) retval = 0; |
if((zscale > scale_max) || (zscale < scale_min)) |
{ |
retval = 0; |
sprintf(msg, "\r\n Value Z: %d not %d-%d !", zscale, scale_min,scale_max); |
UART1_PutString(msg); |
} |
return(retval); |
} |
|