15,8 → 15,7 |
#include "printf_P.h" |
#include "eeprom.h" |
|
volatile int16_t Current_Pitch = 0, Current_Roll = 0, Current_Yaw = 0; |
volatile int16_t Current_AccX = 0, Current_AccY = 0, Current_AccZ = 0; |
volatile int16_t Current_AccZ = 0; |
volatile int16_t UBat = 100; |
volatile int16_t AdValueGyrPitch = 0, AdValueGyrRoll = 0, AdValueGyrYaw = 0; |
volatile int16_t AdValueAccRoll = 0, AdValueAccPitch = 0, AdValueAccTop = 0; |
25,7 → 24,6 |
volatile uint16_t ReadingAirPressure = 1023; |
uint8_t PressureSensorOffset; |
volatile int16_t HightD = 0; |
volatile int16_t tmpAirPressure; |
volatile uint16_t MeasurementCounter = 0; |
|
/*****************************************************/ |
61,7 → 59,7 |
void SearchAirPressureOffset(void) |
{ |
uint8_t off; |
off = GetParamByte(PID_LAST_OFFSET); |
off = GetParamByte(PID_PRESSURE_OFFSET); |
if(off > 20) off -= 10; |
OCR0A = off; |
Delay_ms_Mess(100); |
73,7 → 71,7 |
printf("."); |
if(ReadingAirPressure < 900) break; |
} |
SetParamByte(PID_LAST_OFFSET, off); |
SetParamByte(PID_PRESSURE_OFFSET, off); |
PressureSensorOffset = off; |
Delay_ms_Mess(300); |
} |
82,11 → 80,26 |
/*****************************************************/ |
/* Interrupt Service Routine for ADC */ |
/*****************************************************/ |
// The routine changes the ADC input muxer running |
// thru the state machine by the following order. |
// state 0: ch0 (yaw gyro) |
// state 1: ch1 (roll gyro) |
// state 2: ch2 (pitch gyro) |
// state 3: ch4 (battery voltage -> UBat) |
// state 4: ch6 (acc y -> Current_AccY) |
// state 5: ch7 (acc x -> Current_AccX) |
// state 6: ch0 (yaw gyro average with first reading -> AdValueGyrYaw) |
// state 7: ch1 (roll gyro average with first reading -> AdValueGyrRoll) |
// state 8: ch2 (pitch gyro average with first reading -> AdValueGyrPitch) |
// state 9: ch5 (acc z add also 4th part of acc x and acc y to reading) |
// state10: ch3 (air pressure averaging over 5 single readings -> tmpAirPressure) |
|
ISR(ADC_vect) |
{ |
static uint8_t adc_channel = 0, state = 0; |
static uint16_t yaw1, roll1, pitch1; |
static uint8_t average_pressure = 0; |
static int16_t tmpAirPressure = 0; |
// disable further AD conversion |
ADC_Disable(); |
// state machine |
111,13 → 124,11 |
adc_channel = 6; // set next channel to ADC6 = ACC_Y |
break; |
case 4: |
Current_AccY = NeutralAccY - ADC; // get acceleration in Y direction |
AdValueAccRoll = Current_AccY; |
AdValueAccRoll = NeutralAccY - ADC; // get acceleration in Y direction |
adc_channel = 7; // set next channel to ADC7 = ACC_X |
break; |
case 5: |
Current_AccX = ADC - NeutralAccX; // get acceleration in X direction |
AdValueAccPitch = Current_AccX; |
AdValueAccPitch = ADC - NeutralAccX; // get acceleration in X direction |
adc_channel = 0; // set next channel to ADC7 = YAW GYRO |
break; |
case 6: |
141,7 → 152,7 |
case 9: |
// get z acceleration |
AdValueAccTop = (int16_t) ADC - NeutralAccZ; // get plain acceleration in Z direction |
AdValueAccTop += abs(Current_AccY) / 4 + abs(Current_AccX) / 4; |
AdValueAccTop += abs(AdValueAccPitch) / 4 + abs(AdValueAccRoll) / 4; |
if(AdValueAccTop > 1) |
{ |
if(NeutralAccZ < 800) NeutralAccZ+= 0.02; |
160,14 → 171,14 |
if(++average_pressure >= 5) // if 5 values are summerized for averaging |
{ |
ReadingAirPressure = ADC; // update measured air pressure |
average_pressure = 0; // reset air pressure measurement counter |
HightD = (int16_t)(StartAirPressure - tmpAirPressure - ReadingHight); // D-Anteil = neuerWert - AlterWert |
AirPressure = (tmpAirPressure + 3 * AirPressure) / 4; // averaging using history |
ReadingHight = StartAirPressure - AirPressure; |
average_pressure = 0; // reset air pressure measurement counter |
tmpAirPressure = 0; |
} |
adc_channel = 0; // set next channel to ADC0 = GIER GYRO |
state = 0; // reset state |
state = 0; // reset state machine |
break; |
default: |
adc_channel = 0; |
176,6 → 187,6 |
} |
// set adc muxer to next adc_channel |
ADMUX = (ADMUX & 0xE0) | adc_channel; |
// ?? |
// after full cycle stop further interrupts |
if(state != 0) ADC_Enable(); |
} |