Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 410 → Rev 412

/branches/v0.60_MicroMag3_Nick666/trunc/compass.c
33,7 → 33,6
PORTD &= ~(1<<PD3); // J5 auf Low
// Init Statemachine
MM3.AXIS = MM3_X;
MM3.STATE = MM3_RESET;
61,7 → 60,7
else if (MM3.AXIS == MM3_Y) SPDR = 0x32; // Micromag Period Select ist auf 256 (0x30)
else if (MM3.AXIS == MM3_Z) SPDR = 0x33; // 1: x-Achse, 2: Y-Achse, 3: Z-Achse
MM3.DRDY = SetDelay(8); // Laut Datenblatt max. Zeit bis Messung fertig (bei PS 256 eigentlich 4 ms)
MM3.DRDY = SetDelay(5); // Laut Datenblatt max. Zeit bis Messung fertig (bei PS 256 eigentlich 4 ms)
MM3.STATE = MM3_WAIT_DRDY;
return;
76,58 → 75,38
// SPI byte ready
SIGNAL (SIG_SPI)
//############################################################################
{
switch (MM3.STATE)
{
case MM3_DRDY: // 1. Byte ist da, abspeichern, an die MSB-Stelle rücken
if (MM3.AXIS == MM3_X)
{
MM3.x_axis = SPDR;
MM3.x_axis <<= 8;
}
else if (MM3.AXIS == MM3_Y)
{
MM3.y_axis = SPDR;
MM3.y_axis <<= 8;
}
else // if (MM3.AXIS == MM3_Z)
{
MM3.z_axis = SPDR;
MM3.z_axis <<= 8;
}
SPDR=0x00; // Übertragung von 2. Byte auslösen
MM3.STATE=MM3_BYTE2;
{
static char tmp;
int wert;
 
if (MM3.STATE == MM3_DRDY) // 1. Byte ist da, zwischenspeichern
{
tmp = SPDR;
SPDR = 0x00; // Übertragung von 2. Byte auslösen
MM3.STATE = MM3_BYTE2;
return;
}
else //if (MM3.STATE == MM3_BYTE2) // 2. Byte der entsprechenden Achse ist da
{
wert = SPDR | tmp << 8; // 1. Byte an MSB-Stelle rücken und 2. Byte dranpappen
case MM3_BYTE2: // 2. Byte der entsprechenden Achse ist da
if (MM3.AXIS == MM3_X)
if(abs(wert) < Max_Axis_Value) // Spikes filtern. Zuweisung nur, wenn Max-Wert nicht überschritten
switch(MM3.AXIS)
{
MM3.x_axis |= SPDR;
// Spikes filtern
if (abs(MM3.x_axis) < Max_Axis_Value) MM3.x_axis_old = MM3.x_axis;
else MM3.x_axis = MM3.x_axis_old;
case MM3_X:
MM3.x_axis = wert;
MM3.AXIS = MM3_Y;
MM3.STATE = MM3_RESET;
}
else if (MM3.AXIS == MM3_Y)
{
MM3.y_axis |= SPDR;
if (abs(MM3.y_axis) < Max_Axis_Value) MM3.y_axis_old = MM3.y_axis;
else MM3.y_axis = MM3.y_axis_old;
break;
case MM3_Y:
MM3.y_axis = wert;
MM3.AXIS = MM3_Z;
MM3.STATE = MM3_RESET;
}
else // if (MM3.AXIS == MM3_Z)
{
MM3.z_axis |= SPDR;
if (abs(MM3.z_axis) < Max_Axis_Value) MM3.z_axis_old = MM3.z_axis;
else MM3.z_axis = MM3.z_axis_old;
break;
default:
MM3.z_axis = wert;
MM3.AXIS = MM3_X;
MM3.STATE = MM3_RESET;
}
return;
MM3.STATE = MM3_RESET;
}
}
 
196,7 → 175,7
float sin_nick, cos_nick, sin_roll, cos_roll;
float x_corr, y_corr;
signed int x_axis,y_axis,z_axis, heading;
uint16_t div_faktor;
unsigned int div_faktor;
div_faktor = (uint16_t)EE_Parameter.UserParam1 * 8;
/branches/v0.60_MicroMag3_Nick666/trunc/compass.h
6,11 → 6,8
unsigned int DRDY;
uint8_t AXIS;
signed int x_axis;
signed int x_axis_old;
signed int y_axis;
signed int y_axis_old;
signed int z_axis;
signed int z_axis_old;
signed int NickGrad;
signed int RollGrad;
};