Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2132 → Rev 2133

/branches/dongfang_FC_fixedwing/analog.h
179,7 → 179,7
* This is really only for use for the ENC-03 code module, which needs to get the raw value
* for its calibration. The raw value should not be used for anything else.
*/
uint16_t rawGyroValue(uint8_t axis);
//uint16_t rawGyroValue(uint8_t axis);
 
/*
* Start the conversion cycle. It will stop automatically.
/branches/dongfang_FC_fixedwing/arduino_atmega328/analog.c
23,10 → 23,8
#define startADC() (ADCSRA |= (1<<ADEN)|(1<<ADSC)|(1<<ADIE))
 
const char* recal = ", recalibration needed.";
 
volatile uint16_t ADSensorInputs[8];
 
 
/*
* These 4 exported variables are zero-offset. The "PID" ones are used
* in the attitude control as rotation rates. The "ATT" ones are for
180,6 → 178,8
 
startAnalogConversionCycle();
 
twimaster_init();
 
// restore global interrupt flags
SREG = sreg;
}
187,8 → 187,8
/*
* Here the axes of the sensor can be shuffled around.
*/
uint16_t rawGyroValue(uint8_t axis) {
return IMU3200SensorInputs[axis+1]; // skip temperature mesaurement in any case..
int16_t rawGyroValue(uint8_t axis) {
return ITG3200SensorInputs[axis+1]; // skip temperature mesaurement in any case..
}
 
/*
350,8 → 350,8
 
if (gyroOffset_readFromEEProm()) {
printf("gyro offsets invalid%s",recal);
gyroOffset.offsets[PITCH] = gyroOffset.offsets[ROLL] = 512 * GYRO_OVERSAMPLING;
gyroOffset.offsets[YAW] = 512 * GYRO_OVERSAMPLING;
gyroOffset.offsets[PITCH] = gyroOffset.offsets[ROLL] = 0;
gyroOffset.offsets[YAW] = 0;
}
 
// Noise is relative to offset. So, reset noise measurements when changing offsets.
/branches/dongfang_FC_fixedwing/arduino_atmega328/analog.h
182,7 → 182,7
* This is really only for use for the ENC-03 code module, which needs to get the raw value
* for its calibration. The raw value should not be used for anything else.
*/
uint16_t rawGyroValue(uint8_t axis);
//int16_t rawGyroValue(uint8_t axis);
 
/*
* Start the conversion cycle. It will stop automatically.
/branches/dongfang_FC_fixedwing/arduino_atmega328/main.c
37,7 → 37,8
// disable interrupts global
cli();
 
wdt_enable(WDTO_120MS);
// wdt_enable(WDTO_2000MS);
wdt_disable();
 
// initalize modules
output_init();
68,9 → 69,11
if (runFlightControl) { // control interval
runFlightControl = 0; // reset Flag, is enabled every 2 ms by ISR of timer0
 
/*
if (!resetFlag) {
wdt_reset();
}
*/
 
if (sensorDataReady != ALL_DATA_READY) {
// Analog data should have been ready but is not!!
/branches/dongfang_FC_fixedwing/arduino_atmega328/makefile
1,8 → 1,8
#--------------------------------------------------------------------
# MCU name
MCU = atmega328
F_CPU = 8000000
QUARZ = 8MHZ
F_CPU = 16000000
QUARZ = 16MHZ
 
#-------------------------------------------------------------------
VERSION_MAJOR = 0
/branches/dongfang_FC_fixedwing/arduino_atmega328/timer2.c
31,8 → 31,8
volatile uint16_t servoValues[MAX_SERVOS];
volatile uint16_t previousManualValues[2];
 
#define HEF4017R_ON PORTD |= (1<<PORTD4)
#define HEF4017R_OFF PORTD &= ~(1<<PORTD4)
#define HEF4017R_ON PORTD |= (1<<PORTD3)
#define HEF4017R_OFF PORTD &= ~(1<<PORTD3)
 
/*****************************************************
* Initialize Timer 2
48,8 → 48,8
PORTB &= ~(1 << PORTB3); // set PD7 to low
 
// oc2b DDRD |= (1 << DDD4); // set PC6 as output (Reset for HEF4017)
DDRD |= (1 << DDD4); // set PC6 as output (Reset for HEF4017)
HEF4017R_ON; // enable reset
DDRD |= (1 << DDD3); // set PC6 as output (Reset for HEF4017)
HEF4017R_ON; // reset
 
// Timer/Counter 2 Control Register A
// Timer Mode is CTC (Bits: WGM22 = 0, WGM21 = 1, WGM20 = 0)
/branches/dongfang_FC_fixedwing/arduino_atmega328/twimaster.c
9,14 → 9,14
uint8_t twiTroubleSpot;
uint8_t twiGotStatus;
 
volatile uint16_t IMU3200SensorInputs[4];
volatile int16_t ITG3200SensorInputs[4];
 
void twimaster_init(void) {
// Set pullups
// Set pullups OFF
uint8_t sreg = SREG;
cli();
DDRC = 0;
PORTC = ((1 << 4) | (1 << 5));
PORTC &= ~((1<<4) | (1<<5));
TWBR = ((F_CPU / SCL_CLOCK) - 16) / 2;
twiState = TWI_STATE_INIT_0;
SREG = sreg;
140,14 → 140,14
I2CReceiveByte();
break;
default: // data bytes
((uint8_t*) IMU3200SensorInputs)[dataIndex] = TWDR;
if (twiState < TWI_STATE_LOOP_0 + 5 + sizeof(IMU3200SensorInputs) - 1)
((uint8_t*) ITG3200SensorInputs)[dataIndex] = TWDR;
if (twiState < TWI_STATE_LOOP_0 + 5 + sizeof(ITG3200SensorInputs) - 1)
I2CReceiveByte();
else
I2CReceiveLastByte();
break;
case TWI_STATE_LOOP_0 + 5 + sizeof(IMU3200SensorInputs) - 1: // last data byte
((uint8_t*) IMU3200SensorInputs)[dataIndex] = TWDR;
case TWI_STATE_LOOP_0 + 5 + sizeof(ITG3200SensorInputs) - 1: // last data byte
((uint8_t*) ITG3200SensorInputs)[dataIndex] = TWDR;
// Dont re-init the gyro but just restart the loop.
I2CStop();
sensorDataReady |= TWI_DATA_READY;
/branches/dongfang_FC_fixedwing/arduino_atmega328/twimaster.h
9,7 → 9,7
 
#define SCL_CLOCK 400000L
 
// This is for the IMU3200 sensor.
// This is for the ITG3200 sensor.
#define SLA 0b1101001
#define TWSR_FILTER (TWSR & 0b11111100)
 
28,10 → 28,10
/*
* We take the temperature measurement as well as gyro.
*/
extern volatile uint16_t IMU3200SensorInputs[4];
extern volatile int16_t ITG3200SensorInputs[4];
 
void twimaster_init(void);
void twimaster_setNeutral(void);
 
void twimaster_startCycle(void);
 
#endif
/branches/dongfang_FC_fixedwing/arduino_atmega328/uart0.c
121,7 → 121,7
/****************************************************************/
void usart0_init(void) {
uint8_t sreg = SREG;
uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK / (8 * USART0_BAUD) - 1);
uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU / (8 * USART0_BAUD) - 1);
 
// disable all interrupts before configuration
cli();