73,21 → 73,21 |
|
uint16_t Led_Timer = 0; |
|
struct Scaling_t |
typedef struct |
{ |
int16_t Range; |
int16_t Offset; |
} ; |
} Scaling_t; |
|
struct Calibration_t |
typedef struct |
{ |
struct Scaling_t X; |
struct Scaling_t Y; |
struct Scaling_t Z; |
} ; |
Scaling_t X; |
Scaling_t Y; |
Scaling_t Z; |
} Calibration_t; |
|
struct Calibration_t eeCalibration EEMEM; // calibration data in EEProm |
struct Calibration_t Calibration; // calibration data in RAM |
Calibration_t eeCalibration EEMEM; // calibration data in EEProm |
Calibration_t Calibration; // calibration data in RAM |
|
|
int16_t UncalMagnetX, UncalMagnetY, UncalMagnetZ; // sensor signal difference without Scaling |
125,6 → 125,7 |
Led_Timer = SetDelay(500); |
} |
|
|
Cx = MagnetX; |
Cy = MagnetY; |
Cz = MagnetZ; |
166,8 → 167,7 |
if(I2C_WriteCal.CalByte) cal = I2C_WriteCal.CalByte; |
else cal = ExternData.CalState; |
|
|
if(cal > 5) cal = 0; |
DebugOut.Analog[30] = cal; |
// blink code for current calibration state |
if(cal) |
{ |
194,6 → 194,7 |
LED_GRN_OFF; |
} |
|
|
// calibration state machine |
switch(cal) |
{ |
243,7 → 244,7 |
{ |
// indicate write process by setting the led |
LED_GRN_ON; |
eeprom_write_block(&Calibration, &eeCalibration, sizeof(Calibration)); |
eeprom_write_block(&Calibration, &eeCalibration, sizeof(Calibration_t)); |
Delay_ms(2000); |
// reset led state |
LED_GRN_OFF; |
281,6 → 282,8 |
DebugOut.Analog[15] = Heading; |
DebugOut.Analog[16] = ExternData.UserParam[0]; |
DebugOut.Analog[17] = ExternData.UserParam[1]; |
DebugOut.Analog[30] = I2C_WriteCal.CalByte; |
DebugOut.Analog[31] = PC_Connected; |
} |
|
|
304,16 → 307,19 |
Led_Timer = SetDelay(200); |
|
// read calibration info from eeprom |
eeprom_read_block(&Calibration, &eeCalibration, sizeof(Calibration)); |
eeprom_read_block(&Calibration, &eeCalibration, sizeof(Calibration_t)); |
|
ExternData.Orientation = 0; |
ExternData.CalState = 0; |
I2C_WriteCal.CalByte = 0; |
|
Heading = 101; |
|
// main loop |
while (1) |
{ |
|
|
FLIP_LOW; |
Delay_ms(2); |
RawMagnet1a = ADC_GetValue(ADC0); |
336,7 → 342,6 |
|
// check data from USART |
USART0_ProcessRxData(); |
USART0_TransmitTxData(); |
|
if(PC_Connected) |
{ |