/branches/V0.68d Code Redesign killagreg/fc.c |
---|
64,7 → 64,12 |
#include "uart.h" |
#include "rc.h" |
#include "twimaster.h" |
#ifdef USE_MM3 |
#include "mm3.h" |
#endif |
#ifdef USE_CMPS03 |
#include "cmps03.h" |
#endif |
volatile uint16_t I2CTimeout = 100; |
// gyro readings |
94,8 → 99,8 |
volatile int32_t Reading_Integral_Top = 0; |
// compass course |
volatile int16_t CompassHeading = 0; |
volatile int16_t CompassCourse = 0; |
volatile int16_t CompassHeading = -1; // negative angle indicates invalid data. |
volatile int16_t CompassCourse = -1; |
volatile int16_t CompassOffCourse = 0; |
// flags |
1015,7 → 1020,13 |
{ |
updCompass = 49; // update only at 2ms*50 = 100ms (10Hz) |
// get current compass heading (angule between MK head and magnetic north) |
#ifdef USE_MM3 |
CompassHeading = MM3_Heading(); |
#endif |
#ifdef USE_CMPS03 |
CompassHeading = CMPS03_Heading(); |
#endif |
if (CompassHeading < 0) // no compass data available |
{ |
CompassOffCourse = 0; |
/branches/V0.68d Code Redesign killagreg/main.c |
---|
66,7 → 66,12 |
#include "analog.h" |
#include "printf_P.h" |
//#include "spi.h" |
#ifdef USE_MM3 |
#include "mm3.h" |
#endif |
#ifdef USE_CMPS03 |
#include "cmps03.h" |
#endif |
#include "twimaster.h" |
#include "eeprom.h" |
#include "_Settings.h" |
90,7 → 95,7 |
DDRB = 0x00; |
PORTB = 0x00; |
for(timer = 0; timer < 1000; timer++); // make some delay |
if(PINB & 0x01) BoardRelease = 11; |
if(PINB & (1<<PINB1)) BoardRelease = 11; |
else BoardRelease = 10; |
// set LED ports as output |
121,13 → 126,21 |
TIMER0_Init(); |
TIMER2_Init(); |
USART0_Init(); |
#if defined (__AVR_ATmega644p__) |
if (BoardRelease != 10) USART1_Init(); |
#endif |
#if defined (__AVR_ATmega644p__) |
if (BoardRelease == 11) USART1_Init(); |
#endif |
RC_Init(); |
ADC_Init(); |
I2C_Init(); |
#ifdef USE_MM3 |
MM3_Init(); |
#endif |
#ifdef USE_CMPS03 |
CMPS03_Init(); |
#endif |
//SPI_MasterInit(); |
// enable interrupts global |
153,6 → 166,9 |
timer = SetDelay(500); |
while(!CheckDelay(timer)); |
#ifdef USE_MM3 |
printf("\n\rSupport for Compass Module MM3"); |
//Compass calibration? |
if(PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 100 && PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 100) |
{ |
159,6 → 175,10 |
printf("\n\rCalibrating Compass"); |
MM3_Calibrate(); |
} |
#endif |
#ifdef USE_CMPS03 |
printf("\n\rSupport for Compass Module CMPS03"); |
#endif |
if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
/branches/V0.68d Code Redesign killagreg/makefile |
---|
1,6 → 1,7 |
#-------------------------------------------------------------------- |
# MCU name |
MCU = atmega644p |
#MCU = atmega644 |
MCU = atmega644p |
F_CPU = 20000000 |
#------------------------------------------------------------------- |
VERSION_MAJOR = 0 |
9,13 → 10,11 |
VERSION_COMPATIBLE = 7 # PC-Kompatibilität |
#------------------------------------------------------------------- |
#OPTIONS |
COMPASS = MM3 |
#COMPASS = CMPS03 |
#------------------------------------------------------------------- |
ifeq ($(MCU), atmega32) |
# FUSE_SETTINGS= -u -U lfuse:w:0xff:m -U hfuse:w:0xcf:m |
HEX_NAME = MEGA32 |
endif |
ifeq ($(MCU), atmega644) |
FUSE_SETTINGS = -u -U lfuse:w:0xff:m -U hfuse:w:0xdf:m |
#FUSE_SETTINGS = -U lfuse:w:0xff:m -U hfuse:w:0xdf:m |
37,7 → 36,16 |
QUARZ = 20MHZ |
endif |
ifeq ($(COMPASS), MM3) |
HEX_NAME +=MM3 |
CFLAGS += -DUSE_MM3 |
endif |
ifeq ($(COMPASS), CMPS03) |
HEX_NAME +=CMPS03 |
CFLAGS += -DUSE_CMPS03 |
endif |
# Output format. (can be srec, ihex, binary) |
FORMAT = ihex |
75,7 → 83,13 |
########################################################################################################## |
# List C source files here. (C dependencies are automatically generated.) |
SRC = main.c uart.c printf_P.c timer0.c timer2.c analog.c menu.c |
SRC += twimaster.c rc.c fc.c GPS.c spi.c eeprom.c mm3.c |
SRC += twimaster.c rc.c fc.c GPS.c spi.c eeprom.c |
ifeq ($(COMPASS), MM3) |
SRC +=mm3.c |
endif |
ifeq ($(COMPASS), CMPS03) |
SRC +=cmps03.c |
endif |
SRC += mymath.c ubx.c fifo.c |
ifeq ($(MCU), atmega644p) |
SRC += uart1.c |
123,7 → 137,15 |
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_COMPATIBLE=$(VERSION_COMPATIBLE) -DVERSION_INDEX=$(VERSION_INDEX) |
ifeq ($(COMPASS), MM3) |
CFLAGS += -DUSE_MM3 |
endif |
ifeq ($(COMPASS), CMPS03) |
CFLAGS += -DUSE_CMPS03 |
endif |
# Optional assembler flags. |
# -Wa,...: tell GCC to pass this to the assembler. |
# -ahlms: create listing |
/branches/V0.68d Code Redesign killagreg/menu.c |
---|
15,7 → 15,9 |
#include "uart.h" |
#include "printf_P.h" |
#include "analog.h" |
#ifdef USE_MM3 |
#include "mm3.h" |
#endif |
#include "ubx.h" |
#include "_Settings.h" |
49,8 → 51,13 |
// Display with 20 characters in 4 lines |
void LCD_PrintMenu(void) |
{ |
static uint8_t MaxMenuItem = 14, MenuItem=0; |
#ifdef USE_MM3 |
static uint8_t MaxMenuItem = 14; |
#else |
static uint8_t MaxMenuItem = 12; |
#endif |
static uint8_t MenuItem=0; |
// if KEY1 is activated goto previous menu item |
if(RemoteButtons & KEY1) |
{ |
171,19 → 178,7 |
LCD_printfxy(0,2,"Gs:%4i Ya:%4i ",ExternControl.Thrust, ExternControl.Yaw); |
LCD_printfxy(0,3,"Hi:%4i Cf:%4i ",ExternControl.Hight, ExternControl.Config); |
break; |
case 12:// MM3 Kompass |
LCD_printfxy(0,0,"MM3 Offset"); |
LCD_printfxy(0,1,"X_Offset: %3i",MM3_calib.X_off); |
LCD_printfxy(0,2,"Y_Offset: %3i",MM3_calib.Y_off); |
LCD_printfxy(0,3,"Z_Offset: %3i",MM3_calib.Z_off); |
break; |
case 13://MM3 Range |
LCD_printfxy(0,0,"MM3 Range"); |
LCD_printfxy(0,1,"X_Range: %4i",MM3_calib.X_range); |
LCD_printfxy(0,2,"Y_Range: %4i",MM3_calib.Y_range); |
LCD_printfxy(0,3,"Z_Range: %4i",MM3_calib.Z_range); |
break; |
case 14://GPS Lat/Lon coords |
case 12://GPS Lat/Lon coords |
if (GPSInfo.status == INVALID) |
{ |
LCD_printfxy(0,0,"No data available!"); |
210,6 → 205,20 |
LCD_printfxy(0,3,"Alt: %d.%d m",GPSInfo.altitude/1000L,GPSInfo.altitude%1000L); |
} |
break; |
#ifdef USE_MM3 |
case 13:// MM3 Kompass |
LCD_printfxy(0,0,"MM3 Offset"); |
LCD_printfxy(0,1,"X_Offset: %3i",MM3_calib.X_off); |
LCD_printfxy(0,2,"Y_Offset: %3i",MM3_calib.Y_off); |
LCD_printfxy(0,3,"Z_Offset: %3i",MM3_calib.Z_off); |
break; |
case 14://MM3 Range |
LCD_printfxy(0,0,"MM3 Range"); |
LCD_printfxy(0,1,"X_Range: %4i",MM3_calib.X_range); |
LCD_printfxy(0,2,"Y_Range: %4i",MM3_calib.Y_range); |
LCD_printfxy(0,3,"Z_Range: %4i",MM3_calib.Z_range); |
break; |
#endif |
default: MaxMenuItem = MenuItem - 1; |
MenuItem = 0; |
break; |
/branches/V0.68d Code Redesign killagreg/mm3.c |
---|
62,7 → 62,7 |
MM3_calib_t MM3_calib; |
volatile MM3_working_t MM3; |
static volatile uint8_t MM3_Timeout = 0; |
volatile uint8_t MM3_Timeout = 0; |
118,7 → 118,7 |
/*********************************************/ |
/* Get Data from MM3 */ |
/*********************************************/ |
void MM3_Update() // called every 102.4 µs by timer 0 ISR |
void MM3_Update(void) // called every 102.4 µs by timer 0 ISR |
{ |
switch (MM3.STATE) |
{ |
/branches/V0.68d Code Redesign killagreg/mm3.h |
---|
17,13 → 17,15 |
// Initialization of the MM3 communication |
void MM3_Init(void); |
// should be called cyclic to get actual compass reading |
void MM3_Update(void); |
// this function calibrates the MM3 |
// and returns immediately if the communication to the MM3-Board is broken. |
void MM3_Calibrate(void); |
// calculates the current compass heading in a range from 0 to 360 deg. |
// returns -1 of no compass data are available |
// returns -1 if no compass data are available |
int16_t MM3_Heading(void); |
#endif //_MM3_H |
/branches/V0.68d Code Redesign killagreg/timer0.c |
---|
5,7 → 5,12 |
#include "analog.h" |
#include "main.h" |
#include "fc.h" |
#ifdef USE_MM3 |
#include "mm3.h" |
#endif |
#ifdef USE_CMPS03 |
#include "cmps03.h" |
#endif |
volatile uint16_t CountMilliseconds = 0; |
volatile uint8_t UpdateMotor = 0; |
138,7 → 143,12 |
// update compass value if this option is enabled in the settings |
if(ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE) |
{ |
#ifdef USE_MM3 |
MM3_Update(); // read out mm3 board |
#endif |
#ifdef USE_CMPS03 |
CMPS03_Update(); // read out cmps03 pwm |
#endif |
} |
} |
/branches/V0.68d Code Redesign killagreg/uart.c |
---|
18,6 → 18,12 |
#include "_Settings.h" |
#include "rc.h" |
#if defined (__AVR_ATmega644__) |
#include "ubx.h" |
#endif |
#define FALSE 0 |
#define TRUE 1 |
180,6 → 186,11 |
c = UDR0; // catch the received byte |
// If the ATMEGA644 cpu is used the ublox module should be conneced to rxd of the 1st uart. |
// The ATMEGA644p cpu has a 2nd uart to which the ublox is connected. |
#if defined (__AVR_ATmega644__) |
ubx_parser(c); |
#endif |
if(rxd_buffer_locked) return; // if txd buffer is locked immediately return |