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