91,7 → 91,7 |
|
|
int16_t UncalMagnetX, UncalMagnetY, UncalMagnetZ; // sensor signal difference without Scaling |
int16_t MagnetX, MagnetY, MagnetZ; // rescaled magnetic field readings |
int16_t MagnetX, MagnetY, MagnetZ; // rescaled magnetic field readings |
|
uint8_t PC_Connected = 0; |
|
104,9 → 104,12 |
UncalMagnetY = (1 * UncalMagnetY + (RawMagnet3a - RawMagnet3b)) / 2; |
UncalMagnetZ = (1 * UncalMagnetZ + (RawMagnet2a - RawMagnet2b)) / 2; |
|
MagnetX = (1024L * (int32_t)(UncalMagnetX - Calibration.X.Offset)) / (Calibration.X.Range); |
MagnetY = (1024L * (int32_t)(UncalMagnetY - Calibration.Y.Offset)) / (Calibration.Y.Range); |
MagnetZ = (1024L * (int32_t)(UncalMagnetZ - Calibration.Z.Offset)) / (Calibration.Z.Range); |
if(Calibration.X.Range != 0) MagnetX = (1024L * (int32_t)(UncalMagnetX - Calibration.X.Offset)) / (Calibration.X.Range); |
else MagnetX = 0; |
if(Calibration.Y.Range != 0) MagnetY = (1024L * (int32_t)(UncalMagnetY - Calibration.Y.Offset)) / (Calibration.Y.Range); |
else MagnetY = 0; |
if(Calibration.Y.Range != 0) MagnetZ = (1024L * (int32_t)(UncalMagnetZ - Calibration.Z.Offset)) / (Calibration.Z.Range); |
else MagnetZ = 0; |
} |
|
|
159,13 → 162,12 |
static uint8_t calold = 0; |
static int16_t Xmin = 0, Xmax = 0, Ymin = 0, Ymax = 0, Zmin = 0, Zmax = 0; |
static uint8_t blinkcount = 0; |
/* |
|
// check both sources of communication for calibration request |
if(I2C_WriteCal.CalByte) cal = I2C_WriteCal.CalByte; |
else cal = ExternData.CalState;*/ |
else cal = ExternData.CalState; |
|
cal = ExternData.CalState; |
|
DebugOut.Analog[30] = cal; |
// blink code for current calibration state |
if(cal) |
{ |
280,6 → 282,7 |
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; |
} |
|
286,21 → 289,23 |
|
int main (void) |
{ |
Led_Init(); |
LED_GRN_ON; |
// reset input pullup |
DDRC &=~((1<<DDC6)); |
PORTC |= (1<<PORTC6); |
|
LED_Init(); |
TIMER0_Init(); |
USART0_Init(); |
ADC_Init(); |
I2C_Init(); |
|
sei(); // enable globale interrupts |
|
sei(); //Globale Interrupts Einschalten |
LED_GRN_ON; |
|
Debug_Timer = SetDelay(200); |
Led_Timer = SetDelay(200); |
|
|
Debug_Timer = SetDelay(100); // Sendeintervall |
Led_Timer = SetDelay(100); |
|
// read calibration info from eeprom |
eeprom_read_block(&Calibration, &eeCalibration, sizeof(Calibration_t)); |
|
308,9 → 313,13 |
ExternData.CalState = 0; |
I2C_WriteCal.CalByte = 0; |
|
Heading = 101; |
|
// main loop |
while (1) |
{ |
|
|
FLIP_LOW; |
Delay_ms(2); |
RawMagnet1a = ADC_GetValue(ADC0); |
328,8 → 337,7 |
|
CalcFields(); |
|
//if(ExternData.CalState || I2C_WriteCal.CalByte) Calibrate(); |
if(ExternData.CalState) Calibrate(); |
if(ExternData.CalState || I2C_WriteCal.CalByte) Calibrate(); |
else CalcHeading(); |
|
// check data from USART |