Subversion Repositories MK3Mag

Compare Revisions

Ignore whitespace Rev 22 → Rev 21

/branches/MK3Mag V0.14 Code Redesign Killagreg/main.c
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,12 → 104,9
UncalMagnetY = (1 * UncalMagnetY + (RawMagnet3a - RawMagnet3b)) / 2;
UncalMagnetZ = (1 * UncalMagnetZ + (RawMagnet2a - RawMagnet2b)) / 2;
 
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;
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);
}
 
 
162,12 → 159,13
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;*/
 
DebugOut.Analog[30] = cal;
cal = ExternData.CalState;
 
// blink code for current calibration state
if(cal)
{
282,7 → 280,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;
}
 
289,23 → 286,21
 
int main (void)
{
// reset input pullup
DDRC &=~((1<<DDC6));
PORTC |= (1<<PORTC6);
 
LED_Init();
Led_Init();
LED_GRN_ON;
TIMER0_Init();
USART0_Init();
ADC_Init();
I2C_Init();
 
sei(); // enable globale interrupts
 
LED_GRN_ON;
sei(); //Globale Interrupts Einschalten
 
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));
 
313,13 → 308,9
ExternData.CalState = 0;
I2C_WriteCal.CalByte = 0;
 
Heading = 101;
 
// main loop
while (1)
{
 
 
FLIP_LOW;
Delay_ms(2);
RawMagnet1a = ADC_GetValue(ADC0);
337,7 → 328,8
 
CalcFields();
 
if(ExternData.CalState || I2C_WriteCal.CalByte) Calibrate();
//if(ExternData.CalState || I2C_WriteCal.CalByte) Calibrate();
if(ExternData.CalState) Calibrate();
else CalcHeading();
 
// check data from USART