/branches/v0.60_MicroMag3_Nick666/trunc/analog.c |
---|
34,18 → 34,25 |
void SucheLuftruckOffset(void) |
{ |
unsigned int off; |
for(off=0; off < 250;off++) |
off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
if(off > 20) off -= 10; |
OCR0A = off; |
Delay_ms_Mess(100); |
if(MessLuftdruck < 850) off = 0; |
for(; off < 250;off++) |
{ |
OCR0A = off; |
Delay_ms(50); |
Delay_ms_Mess(50); |
printf("."); |
if(MessLuftdruck < 900) break; |
} |
DruckOffsetSetting = off; |
Delay_ms(200); |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
DruckOffsetSetting = off; |
Delay_ms_Mess(300); |
} |
//####################################################################################### |
// |
SIGNAL(SIG_ADC) |
/branches/v0.60_MicroMag3_Nick666/trunc/compass.c |
---|
26,8 → 26,8 |
void init_MM3(void) |
//############################################################################ |
{ |
SPCR = (1<<SPIE)|(1<<SPE)|(1<<MSTR)|(1<<SPR1); //Interrupt an, Master, 625 kHz Oszillator |
SPSR = (1<<SPI2X); |
SPCR = (1<<SPIE)|(1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0); //Interrupt an, Master, 156 kHz Oszillator |
//SPSR = (1<<SPI2X); |
DDRB |= (1<<PB7)|(1<<PB5)|(1<<PB2); // J8, MOSI, SCK Ausgang |
60,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(5); // Laut Datenblatt max. Zeit bis Messung fertig (bei PS 256 eigentlich 4 ms) |
MM3.DRDY = SetDelay(8); // Laut Datenblatt max. Zeit bis Messung fertig (bei PS 256 eigentlich 4 ms) |
MM3.STATE = MM3_WAIT_DRDY; |
return; |
/branches/v0.60_MicroMag3_Nick666/trunc/fc.c |
---|
71,6 → 71,7 |
volatile int KompassValue = 0; |
volatile int KompassStartwert = 0; |
volatile int KompassRichtung = 0; |
uint8_t updKompass=0; |
unsigned char MAX_GAS,MIN_GAS; |
unsigned char Notlandung = 0; |
unsigned char HoehenReglerAktiv = 0; |
130,9 → 131,9 |
acc_neutral.X = 0; |
acc_neutral.Y = 0; |
acc_neutral.Z = 0; |
CalibrierMittelwert(); |
timer = SetDelay(5); |
while (!CheckDelay(timer)); |
Delay_ms_Mess(100); |
CalibrierMittelwert(); |
acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
154,10 → 155,11 |
AdNeutralNick = 0; |
AdNeutralRoll = 0; |
AdNeutralGier = 0; |
CalibrierMittelwert(); |
timer = SetDelay(5); |
while (!CheckDelay(timer)); |
Delay_ms_Mess(100); |
CalibrierMittelwert(); |
if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
{ |
if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
437,6 → 439,7 |
static int hoehenregler = 0; |
static char TimerWerteausgabe = 0; |
static char NeueKompassRichtungMerken = 0; |
Mittelwert(); |
GRN_ON; |
656,7 → 659,15 |
if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
{ |
int w,v; |
static int SignalSchlecht = 0; |
static uint8_t SignalSchlecht = 0; |
if (!updKompass--) // Aufruf mit ~10 Hz |
{ |
KompassValue = heading_MM3(); |
KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
updKompass = 50; |
} |
w = abs(IntegralNick /1024); // mit zunehmender Neigung den Einfluss drosseln |
v = abs(IntegralRoll /1024); |
if(v > w) w = v; // grösste Neigung ermitteln |
674,7 → 685,7 |
ANALOG_ON; // ADC einschalten |
if(SignalSchlecht) SignalSchlecht--; |
} |
else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
else SignalSchlecht = 250; // so lange das Signal taub stellen --> ca. 1/2 sek |
} |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
/branches/v0.60_MicroMag3_Nick666/trunc/main.h |
---|
30,6 → 30,7 |
#define EEPROM_ADR_VALID 1 |
#define EEPROM_ADR_ACTIVE_SET 2 |
#define EEPROM_ADR_LAST_OFFSET 3 |
#define CFG_HOEHENREGELUNG 0x01 |
#define CFG_HOEHEN_SCHALTER 0x02 |
/branches/v0.60_MicroMag3_Nick666/trunc/timer0.c |
---|
4,7 → 4,6 |
volatile static unsigned int tim_main; |
volatile unsigned char UpdateMotor = 0; |
volatile unsigned int beeptime = 0; |
volatile unsigned int cntKompass = 800; |
int ServoValue = 0; |
enum { |
42,17 → 41,7 |
else |
PORTD &= ~(1<<PD2); |
if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
{ |
timer0_MM3(); // Kompass auslesen |
if (!cntKompass--) // Aufruf mit 10 Hz |
{ |
KompassValue = heading_MM3(); |
KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
cntKompass = 980; |
} |
} |
if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) timer0_MM3(); // Kompass auslesen |
} |
82,17 → 71,13 |
unsigned int SetDelay (unsigned int t) |
{ |
// TIMSK0 &= ~_BV(TOIE0); |
return(CountMilliseconds + t + 1); |
// TIMSK0 |= _BV(TOIE0); |
} |
// ----------------------------------------------------------------------- |
char CheckDelay(unsigned int t) |
{ |
// TIMSK0 &= ~_BV(TOIE0); |
return(((t - CountMilliseconds) & 0x8000) >> 9); |
// TIMSK0 |= _BV(TOIE0); |
} |
// ----------------------------------------------------------------------- |
103,6 → 88,13 |
while (!CheckDelay(akt)); |
} |
void Delay_ms_Mess(unsigned int w) |
{ |
unsigned int akt; |
akt = SetDelay(w); |
while (!CheckDelay(akt)) ANALOG_ON; |
} |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// Servo ansteuern |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
/branches/v0.60_MicroMag3_Nick666/trunc/timer0.h |
---|
4,6 → 4,7 |
void Timer_Init(void); |
void Delay_ms(unsigned int); |
void Delay_ms_Mess(unsigned int w); |
unsigned int SetDelay (unsigned int t); |
char CheckDelay (unsigned int t); |
10,5 → 11,4 |
extern volatile unsigned int CountMilliseconds; |
extern volatile unsigned char UpdateMotor; |
extern volatile unsigned int beeptime; |
extern volatile unsigned int cntKompass; |
extern int ServoValue; |