/branches/V0.68d Code Redesign killagreg/analog.c |
---|
4,8 → 4,11 |
// + www.MikroKopter.com |
// + see the File "License.txt" for further Informations |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include "analog.h" |
#include "main.h" |
#include "timer0.h" |
#include "fc.h" |
#include "printf_P.h" |
volatile int16_t Current_Nick = 0, Current_Roll = 0, Current_Gier = 0; |
volatile int16_t Current_AccX = 0, Current_AccY = 0, Current_AccZ = 0; |
115,19 → 118,19 |
break; |
case 6: |
// average over two samples to create current ADValueGier |
if(PlatinenVersion == 10) AdValueGyrGier = (ADC + gier1) / 2; |
if(BoardRelease == 10) AdValueGyrGier = (ADC + gier1) / 2; |
else AdValueGyrGier = ADC + gier1; // gain is 2 times lower on FC 1.1 |
adc_channel = 1; // set next channel to ADC7 = ROLL GYRO |
break; |
case 7: |
// average over two samples to create current ADValueRoll |
if(PlatinenVersion == 10) AdValueGyrRoll = (ADC + roll1) / 2; |
if(BoardRelease == 10) AdValueGyrRoll = (ADC + roll1) / 2; |
else AdValueGyrRoll = ADC + roll1; // gain is 2 times lower on FC 1.1 |
adc_channel = 2; // set next channel to ADC2 = NICK GYRO |
break; |
case 8: |
// average over two samples to create current ADValueNick |
if(PlatinenVersion == 10) AdValueGyrNick = (ADC + nick1) / 2; |
if(BoardRelease == 10) AdValueGyrNick = (ADC + nick1) / 2; |
else AdValueGyrNick = ADC + nick1; // gain is 2 times lower on FC 1.1 |
adc_channel = 5; // set next channel to ADC5 = ACC_Z |
break; |
/branches/V0.68d Code Redesign killagreg/analog.h |
---|
1,6 → 1,7 |
/*####################################################################################### |
#ifndef _ANALOG_H |
#define _ANALOG_H |
#######################################################################################*/ |
#include <inttypes.h> |
extern volatile int16_t UBat; |
extern volatile int16_t AdValueGyrNick, AdValueGyrRoll, AdValueGyrGier; |
15,9 → 16,9 |
extern volatile uint16_t MessLuftdruck; |
extern volatile int16_t StartLuftdruck; |
void SucheLuftruckOffset(void); |
extern void SucheLuftruckOffset(void); |
void ADC_Init(void); |
extern void ADC_Init(void); |
// clear ADC enable & ADC Start Conversion & ADC Interrupt Enable bit |
#define ADC_Disable() (ADCSRA &= ~((1<<ADEN)|(1<<ADSC)|(1<<ADIE))) |
24,3 → 25,7 |
// set ADC enable & ADC Start Conversion & ADC Interrupt Enable bit |
#define ADC_Enable() (ADCSRA |= (1<<ADEN)|(1<<ADSC)|(1<<ADIE)) |
#endif //_ANALOG_H |
/branches/V0.68d Code Redesign killagreg/eeprom.c |
---|
1,3 → 1,7 |
#include "fc.h" |
#include "_Settings.h" |
#include "main.h" |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Konstanten |
// + 0-250 -> normale Werte |
/branches/V0.68d Code Redesign killagreg/eeprom.h |
---|
0,0 → 1,8 |
#ifndef _EEPROM_H |
#define _EEPROM_H |
extern void DefaultKonstanten1(void); |
extern void DefaultKonstanten2(void); |
extern void DefaultKonstanten3(void); |
#endif //_EEPROM_H |
/branches/V0.68d Code Redesign killagreg/fc.c |
---|
52,8 → 52,17 |
// + POSSIBILITY OF SUCH DAMAGE. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include "main.h" |
#include "eeprom.c" |
#include "eeprom.h" |
#include "timer0.h" |
#include "_Settings.h" |
#include "analog.h" |
#include "fc.h" |
#include "gps.h" |
#include "uart.h" |
#include "rc.h" |
#include "twimaster.h" |
unsigned char h,m,s; |
volatile unsigned int I2CTimeout = 100; |
242,7 → 251,7 |
} |
if(AdValueGyrRoll < 15) MesswertRoll = -1000; |
if(AdValueGyrRoll < 7) MesswertRoll = -2000; |
if(PlatinenVersion == 10) |
if(BoardRelease == 10) |
{ |
if(AdValueGyrRoll > 1010) MesswertRoll = +1000; |
if(AdValueGyrRoll > 1017) MesswertRoll = +2000; |
269,7 → 278,7 |
} |
if(AdValueGyrNick < 15) MesswertNick = -1000; |
if(AdValueGyrNick < 7) MesswertNick = -2000; |
if(PlatinenVersion == 10) |
if(BoardRelease == 10) |
{ |
if(AdValueGyrNick > 1010) MesswertNick = +1000; |
if(AdValueGyrNick > 1017) MesswertNick = +2000; |
/branches/V0.68d Code Redesign killagreg/fc.h |
---|
34,8 → 34,6 |
void SetNeutral(void); |
void Piep(unsigned char Anzahl); |
extern void DefaultKonstanten(void); |
void DefaultKonstanten1(void); |
void DefaultKonstanten2(void); |
extern unsigned char h,m,s; |
extern volatile unsigned char Timeout ; |
53,8 → 51,6 |
extern volatile unsigned char SenderOkay; |
extern int StickNick,StickRoll,StickGier; |
extern char MotorenEin; |
extern void DefaultKonstanten1(void); |
extern void DefaultKonstanten2(void); |
#define STRUCT_PARAM_LAENGE 71 |
struct mk_param_struct |
/branches/V0.68d Code Redesign killagreg/main.c |
---|
50,10 → 50,24 |
// + POSSIBILITY OF SUCH DAMAGE. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include "main.h" |
#include "timer0.h" |
#include "timer2.h" |
#include "uart.h" |
#include "uart1.h" |
#include "menu.h" |
#include "fc.h" |
#include "rc.h" |
#include "analog.h" |
#include "printf_P.h" |
#include "spi.h" |
#include "twimaster.h" |
#include "eeprom.h" |
#include "_Settings.h" |
unsigned char EEPromArray[E2END+1] EEMEM; |
unsigned char PlatinenVersion = 10; |
uint8_t EEPromArray[E2END+1] EEMEM; |
uint8_t BoardRelease = 10; |
// -- Parametersatz aus EEPROM lesen --- |
// number [0..5] |
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
72,9 → 86,12 |
eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
} |
unsigned char GetActiveParamSetNumber(void) |
/***************************************************/ |
/* Get number of active parameter set */ |
/***************************************************/ |
uint8_t GetActiveParamSetNumber(void) |
{ |
unsigned char set; |
uint8_t set; |
set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
if(set > 5) |
{ |
97,7 → 114,11 |
DDRB = 0x00; |
PORTB = 0x00; |
for(timer = 0; timer < 1000; timer++); // make delay |
if(PINB & 0x01) PlatinenVersion = 11; else PlatinenVersion = 10; |
if(PINB & 0x01) BoardRelease = 11; |
else BoardRelease = 10; |
DDRC = 0x81; // SCL & Speaker |
PORTC = 0xff; // Pullup SDA |
DDRB = 0x1B; // LEDs und Druckoffset |
137,7 → 158,7 |
VersionInfo.Nebenversion = VERSION_NEBENVERSION; |
VersionInfo.PCKompatibel = VERSION_KOMPATIBEL; |
printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX + 'a'); |
printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX + 'a'); |
printf("\n\r=============================="); |
GRN_ON; |
189,7 → 210,7 |
printf("\n\n\r"); |
LcdClear(); |
LCD_Clear(); |
I2CTimeout = 5000; |
while (1) |
{ |
/branches/V0.68d Code Redesign killagreg/main.h |
---|
15,8 → 15,8 |
#endif |
// neue Hardware |
#define ROT_OFF {if(PlatinenVersion == 10) PORTB &=~0x01; else PORTB |= 0x01;} |
#define ROT_ON {if(PlatinenVersion == 10) PORTB |= 0x01; else PORTB &=~0x01;} |
#define ROT_OFF {if(BoardRelease == 10) PORTB &=~0x01; else PORTB |= 0x01;} |
#define ROT_ON {if(BoardRelease == 10) PORTB |= 0x01; else PORTB &=~0x01;} |
#define ROT_FLASH PORTB ^= 0x01 |
#define GRN_OFF PORTB &=~0x02 |
#define GRN_ON PORTB |= 0x02 |
54,18 → 54,7 |
#define CFG_LOOP_LINKS 0x04 |
#define CFG_LOOP_RECHTS 0x08 |
//#define SYSCLK |
//extern unsigned long SYSCLK; |
extern volatile int i_Nick[20],i_Roll[20],DiffNick,DiffRoll; |
extern volatile unsigned char SenderOkay; |
extern unsigned char CosinusNickWinkel, CosinusRollWinkel; |
extern unsigned char PlatinenVersion; |
void ReadParameterSet (unsigned char number, unsigned char *buffer, unsigned char length); |
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length); |
extern unsigned char GetActiveParamSetNumber(void); |
extern unsigned char EEPromArray[]; |
#include <stdlib.h> |
#include <string.h> |
#include <avr/io.h> |
75,23 → 64,20 |
#include <avr/boot.h> |
#include <avr/wdt.h> |
#include "old_macros.h" |
#include "_Settings.h" |
#include "printf_P.h" |
#include "timer0.h" |
#include "timer2.h" |
#include "uart.h" |
#include "uart1.h" |
#include "analog.h" |
#include "twimaster.h" |
#include "menu.h" |
#include "rc.h" |
#include "fc.h" |
#include "gps.h" |
#include "spi.h" |
//#define SYSCLK |
//extern unsigned long SYSCLK; |
extern volatile int i_Nick[20],i_Roll[20],DiffNick,DiffRoll; |
extern volatile unsigned char SenderOkay; |
extern unsigned char CosinusNickWinkel, CosinusRollWinkel; |
extern uint8_t BoardRelease; |
void ReadParameterSet (unsigned char number, unsigned char *buffer, unsigned char length); |
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length); |
extern uint8_t GetActiveParamSetNumber(void); |
extern uint8_t EEPromArray[]; |
#ifndef EEMEM |
#define EEMEM __attribute__ ((section (".eeprom"))) |
#endif |
/branches/V0.68d Code Redesign killagreg/makefile |
---|
75,7 → 75,7 |
########################################################################################################## |
# 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 |
SRC += twimaster.c rc.c fc.c GPS.c spi.c eeprom.c |
SRC += mymath.c ubx.c fifo.c uart1.c |
########################################################################################################## |
/branches/V0.68d Code Redesign killagreg/menu.c |
---|
4,14 → 4,25 |
// + www.MikroKopter.com |
// + see the File "License.txt" for further Informations |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include <inttypes.h> |
#include "main.h" |
#include "timer2.h" |
#include "fc.h" |
#include "rc.h" |
#include "uart.h" |
#include "printf_P.h" |
#include "analog.h" |
#include "_Settings.h" |
unsigned int TestInt = 0; |
#define ARRAYGROESSE 10 |
unsigned char Array[ARRAYGROESSE] = {1,2,3,4,5,6,7,8,9,10}; |
char DisplayBuff[80] = "Hallo Welt"; |
unsigned char DispPtr = 0; |
unsigned char RemoteTasten = 0; |
uint16_t TestInt = 0; |
#define ARRAYSIZE 10 |
uint8_t Array[ARRAYSIZE] = {1,2,3,4,5,6,7,8,9,10}; |
#define DISPLAYBUFFSIZE 80 |
int8_t DisplayBuff[DISPLAYBUFFSIZE] = "Hello World"; |
uint8_t DispPtr = 0; |
uint8_t RemoteButtons = 0; |
#define KEY1 0x01 |
#define KEY2 0x02 |
19,31 → 30,63 |
#define KEY4 0x08 |
#define KEY5 0x10 |
void LcdClear(void) |
/************************************/ |
/* Clear LCD Buffer */ |
/************************************/ |
void LCD_Clear(void) |
{ |
unsigned char i; |
for(i=0;i<80;i++) DisplayBuff[i] = ' '; |
uint8_t i; |
for( i = 0; i < DISPLAYBUFFSIZE; i++) DisplayBuff[i] = ' '; |
} |
void Menu(void) |
/************************************/ |
/* Update Menu on LCD */ |
/************************************/ |
// Display with 20 characters in 4 lines |
void LCD_PrintMenu(void) |
{ |
static unsigned char MaxMenue = 11,MenuePunkt=0; |
static uint8_t MaxMenuItem = 11, MenuItem=0; |
if(RemoteTasten & KEY1) { if(MenuePunkt) MenuePunkt--; else MenuePunkt = MaxMenue; LcdClear(); RemotePollDisplayLine = -1; } |
if(RemoteTasten & KEY2) { MenuePunkt++; LcdClear(); RemotePollDisplayLine = -1;} |
if((RemoteTasten & KEY1) && (RemoteTasten & KEY2)) MenuePunkt = 0; |
if(MenuePunkt < 10) {LCD_printfxy(17,0,"[%i]",MenuePunkt);} else {LCD_printfxy(16,0,"[%i]",MenuePunkt);}; |
switch(MenuePunkt) |
// if KEY1 is activated goto previous menu item |
if(RemoteButtons & KEY1) |
{ |
case 0: |
if(MenuItem) MenuItem--; |
else MenuItem = MaxMenuItem; |
LCD_Clear(); |
RemotePollDisplayLine = -1; |
} |
// if KEY2 is activated goto next menu item |
if(RemoteButtons & KEY2) |
{ |
if (MenuItem == MaxMenuItem) MenuItem = 0; |
else MenuItem++; |
LCD_Clear(); |
RemotePollDisplayLine = -1; |
} |
// if KEY1 and KEY2 is activated goto initial menu item |
if((RemoteButtons & KEY1) && (RemoteButtons & KEY2)) MenuItem = 0; |
// print menu item number in the upper right corner |
if(MenuItem < 10) |
{ |
LCD_printfxy(17,0,"[%i]",MenuItem); |
} |
else |
{ |
LCD_printfxy(16,0,"[%i]",MenuItem); |
} |
switch(MenuItem) |
{ |
case 0:// Version Info Menu Item |
LCD_printfxy(0,0,"+ MikroKopter +"); |
LCD_printfxy(0,1,"HW:V%d.%d SW:%d.%d%c",PlatinenVersion/10,PlatinenVersion%10,VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX+'a'); |
LCD_printfxy(0,1,"HW:V%d.%d SW:%d.%d%c",BoardRelease/10,BoardRelease%10,VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX+'a'); |
LCD_printfxy(0,2,"Setting: %d ",GetActiveParamSetNumber()); |
LCD_printfxy(0,3,"(c) Holger Buss"); |
// if(RemoteTasten & KEY3) TestInt--; |
// if(RemoteTasten & KEY4) TestInt++; |
break; |
case 1: |
case 1:// Hight Control Menu Item |
if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
{ |
LCD_printfxy(0,0,"Hoehe: %5i",HoehenWert); |
58,27 → 101,27 |
} |
break; |
case 2: |
case 2:// Attitude Menu Item |
LCD_printfxy(0,0,"akt. Lage"); |
LCD_printfxy(0,1,"Nick: %5i",IntegralNick/1024); |
LCD_printfxy(0,2,"Roll: %5i",IntegralRoll/1024); |
LCD_printfxy(0,3,"Kompass: %5i",KompassValue); |
break; |
case 3: |
case 3:// Remote Control Channel Menu Item |
LCD_printfxy(0,0,"K1:%4i K2:%4i ",PPM_in[1],PPM_in[2]); |
LCD_printfxy(0,1,"K3:%4i K4:%4i ",PPM_in[3],PPM_in[4]); |
LCD_printfxy(0,2,"K5:%4i K6:%4i ",PPM_in[5],PPM_in[6]); |
LCD_printfxy(0,3,"K7:%4i K8:%4i ",PPM_in[7],PPM_in[8]); |
break; |
case 4: |
case 4:// Remote Control Mapping Menu Item |
LCD_printfxy(0,0,"Ni:%4i Ro:%4i ",PPM_in[EE_Parameter.Kanalbelegung[K_NICK]],PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); |
LCD_printfxy(0,1,"Gs:%4i Gi:%4i ",PPM_in[EE_Parameter.Kanalbelegung[K_GAS]],PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]); |
LCD_printfxy(0,2,"P1:%4i P2:%4i ",PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]],PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]]); |
LCD_printfxy(0,3,"P3:%4i P4:%4i ",PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]],PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]]); |
break; |
case 5: |
case 5:// Gyro Sensor Menu Item |
LCD_printfxy(0,0,"Gyro - Sensor"); |
if(PlatinenVersion == 10) |
if(BoardRelease == 10) |
{ |
LCD_printfxy(0,1,"Nick %4i (%3i)",AdValueGyrNick - AdNeutralNick, AdNeutralNick); |
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueGyrRoll - AdNeutralRoll, AdNeutralRoll); |
91,43 → 134,43 |
LCD_printfxy(0,3,"Gier %4i (%3i)",MesswertGier, AdNeutralGier/2); |
} |
break; |
case 6: |
case 6:// Acceleration Sensor Menu Item |
LCD_printfxy(0,0,"ACC - Sensor"); |
LCD_printfxy(0,1,"Nick %4i (%3i)",AdValueAccNick,NeutralAccX); |
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueAccRoll,NeutralAccY); |
LCD_printfxy(0,3,"Hoch %4i (%3i)",Mittelwert_AccHoch/*accumulate_AccHoch / messanzahl_AccHoch*/,(int)NeutralAccZ); |
break; |
case 7: |
case 7:// Accumulator Voltage / Remote Control Level |
LCD_printfxy(0,1,"Spannung: %5i",UBat); |
LCD_printfxy(0,2,"Empf.Pegel:%5i",SenderOkay); |
break; |
case 8: |
case 8:// Compass Menu Item |
LCD_printfxy(0,0,"Kompass "); |
LCD_printfxy(0,1,"Richtung: %5i",KompassRichtung); |
LCD_printfxy(0,2,"Messwert: %5i",KompassValue); |
LCD_printfxy(0,3,"Start: %5i",KompassStartwert); |
break; |
case 9: |
case 9:// Poti Menu Item |
LCD_printfxy(0,0,"Poti1: %3i",Poti1); |
LCD_printfxy(0,1,"Poti2: %3i",Poti2); |
LCD_printfxy(0,2,"Poti3: %3i",Poti3); |
LCD_printfxy(0,3,"Poti4: %3i",Poti4); |
break; |
case 10: |
case 10:// Servo Menu Item |
LCD_printfxy(0,0,"Servo " ); |
LCD_printfxy(0,1,"Setpoint %3i",Parameter_ServoNickControl); |
LCD_printfxy(0,2,"Stellung: %3i",ServoValue); |
LCD_printfxy(0,3,"Range:%3i-%3i",EE_Parameter.ServoNickMin,EE_Parameter.ServoNickMax); |
break; |
case 11: |
case 11://Extern Control |
LCD_printfxy(0,0,"ExternControl " ); |
LCD_printfxy(0,1,"Ni:%4i Ro:%4i ",ExternControl.Nick,ExternControl.Roll); |
LCD_printfxy(0,2,"Gs:%4i Gi:%4i ",ExternControl.Gas,ExternControl.Gier); |
LCD_printfxy(0,3,"Hi:%4i Cf:%4i ",ExternControl.Hight,ExternControl.Config); |
break; |
default: MaxMenue = MenuePunkt - 1; |
MenuePunkt = 0; |
default: MaxMenuItem = MenuItem - 1; |
MenuItem = 0; |
break; |
} |
RemoteTasten = 0; |
RemoteButtons = 0; |
} |
/branches/V0.68d Code Redesign killagreg/menu.h |
---|
1,6 → 1,16 |
extern void Menu(void); |
extern void LcdClear(void); |
extern char DisplayBuff[80]; |
extern unsigned char DispPtr; |
extern unsigned char RemoteTasten; |
#ifndef _MENU_H |
#define _MENU_H |
#include <inttypes.h> |
#define DISPLAYBUFFSIZE 80 |
extern void LCD_PrintMenu(void); |
extern void LCD_Clear(void); |
extern int8_t DisplayBuff[DISPLAYBUFFSIZE]; |
extern uint8_t DispPtr; |
extern uint8_t RemoteButtons; |
#endif //_MENU_H |
/branches/V0.68d Code Redesign killagreg/printf_P.c |
---|
86,7 → 86,10 |
#include <varargs.h> |
#endif |
#include "main.h" |
#include "old_macros.h" |
#include "printf_P.h" |
#include "menu.h" |
#include "uart.h" |
//#define LIGHTPRINTF |
/branches/V0.68d Code Redesign killagreg/rc.c |
---|
8,8 → 8,11 |
// + see the File "License.txt" for further Informations |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include "rc.h" |
#include "main.h" |
#include "fc.h" |
volatile int PPM_in[11]; |
volatile int PPM_diff[11]; // das diffenzierte Stick-Signal |
/branches/V0.68d Code Redesign killagreg/spi.c |
---|
1,5 → 1,6 |
// ######################## SPI - FlightCtrl ################### |
#include "main.h" |
#include "spi.h" |
struct str_ToNaviCtrl ToNaviCtrl; |
/branches/V0.68d Code Redesign killagreg/timer0.c |
---|
1,3 → 1,8 |
#include <inttypes.h> |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include "fc.h" |
#include "analog.h" |
#include "main.h" |
volatile uint16_t CountMilliseconds = 0; |
4,7 → 9,7 |
volatile uint8_t UpdateMotor = 0; |
volatile uint16_t cntKompass = 0; |
volatile uint16_t BeepTime = 0; |
uint16_t BeepModulation = 0xFFFF; |
volatile uint16_t BeepModulation = 0xFFFF; |
94,13 → 99,13 |
if(Beeper_On) |
{ |
// set speaker port to high |
if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker at PD2 |
if(BoardRelease == 10) PORTD |= (1<<2); // Speaker at PD2 |
else PORTC |= (1<<7); // Speaker at PC7 |
} |
else // beeper is off |
{ |
// set speaker port to low |
if(PlatinenVersion == 10) PORTD &= ~(1<<2);// Speaker at PD2 |
if(BoardRelease == 10) PORTD &= ~(1<<2);// Speaker at PD2 |
else PORTC &= ~(1<<7);// Speaker at PC7 |
} |
/branches/V0.68d Code Redesign killagreg/timer0.h |
---|
1,19 → 1,19 |
#ifndef _TIMER0_H |
#define _TIMER0_H |
#include <inttypes.h> |
extern volatile uint16_t CountMilliseconds; |
extern volatile uint8_t UpdateMotor; |
extern volatile uint16_t cntKompass; |
extern uint16_t BeepModulation; |
extern volatile uint16_t BeepModulation; |
extern volatile uint16_t BeepTime; |
void TIMER0_Init(void); |
void Delay_ms(uint16_t w); |
void Delay_ms_Mess(uint16_t w); |
uint16_t SetDelay (uint16_t t); |
int8_t CheckDelay (uint16_t t); |
extern void TIMER0_Init(void); |
extern void Delay_ms(uint16_t w); |
extern void Delay_ms_Mess(uint16_t w); |
extern uint16_t SetDelay (uint16_t t); |
extern int8_t CheckDelay (uint16_t t); |
#endif //_TIMER0_H |
/branches/V0.68d Code Redesign killagreg/timer2.c |
---|
1,14 → 1,15 |
#include "main.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include "fc.h" |
volatile int16_t ServoValue = 0; |
int16_t ServoValue = 0; |
/*****************************************************/ |
/* Initialize Timer 2 */ |
/*****************************************************/ |
// The timer 2 is used to generate the PWM at PD7 (J7) |
// to control a camera servo for nick compensation |
// to control a camera servo for nick compensation. |
void TIMER2_Init(void) |
{ |
uint8_t sreg = SREG; |
23,30 → 24,30 |
// Timer/Counter 2 Control Register A |
// Waveform Generation Mode is Fast PWM (Bits WGM22 = 0, WGM21 = 1, WGM20 = 1) |
// PD7: Clear OC2B on Compare Match, set OC2B at BOTTOM, noninverting PWM (Bits COM2A1 = 1, COM2A0 = 0) |
// PD6: Normal port operation, OC2B disconnected, (Bits COM2B1 = 0, COM2B0 = 0) |
// Waveform Generation Mode is Fast PWM (Bits: WGM22 = 0, WGM21 = 1, WGM20 = 1) |
// PD7: Clear OC2B on Compare Match, set OC2B at BOTTOM, noninverting PWM (Bits: COM2A1 = 1, COM2A0 = 0) |
// PD6: Normal port operation, OC2B disconnected, (Bits: COM2B1 = 0, COM2B0 = 0) |
TCCR2A &= ~((1<<COM2B1)|(1<<COM2B0)|(1<<COM2A0)); |
TCCR2A |= (1<<COM2A1)|(1<<WGM21)|(1<<WGM20); |
// Timer/Counter 2 Control Register B |
// set clock devider for timer 2 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz |
// i.e. the timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz |
// Set clock divider for timer 2 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz. |
// The timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz, |
// hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz |
// devider 8 (Bits CS022 = 0, CS21 = 1, CS20 = 0) |
// divider 8 (Bits: CS022 = 0, CS21 = 1, CS20 = 0) |
TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<WGM22)); |
TCCR2B = (TCCR2B & 0xF8)|(0<<CS22)|(1<<CS21)|(0<<CS20); |
// initialize the Output Compare Register A used for PWM generation on port PD7 |
// Initialize the Output Compare Register A used for PWM generation on port PD7. |
OCR2A = 10; |
// init Timer/Counter 2 Register |
// Initialize the Timer/Counter 2 Register |
TCNT2 = 0; |
// Timer/Counter 2 Interrupt Mask Register |
// enable timer output compare match A Interrupt only |
// Enable timer output compare match A Interrupt only |
TIMSK2 &= ~((1<<OCIE2B)|(1<<TOIE2)); |
TIMSK2 |= (1<<OCIE2A); |
57,7 → 58,7 |
/*****************************************************/ |
/* Control Servo Position */ |
/*****************************************************/ |
ISR(TIMER2_COMPA_vect) // 9,765 kHz |
ISR(TIMER2_COMPA_vect) // 9.765 kHz |
{ |
static uint8_t timer = 10; |
72,7 → 73,7 |
{ |
ServoValue += ((int32_t) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
} |
else // non inverting movment of servo |
else // non inverting movement of servo |
{ |
ServoValue -= ((int32_t) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
} |
95,7 → 96,7 |
{ |
// disable PWM at PD7 |
TCCR2A &= ~((1<<COM2A1)|(1<<COM2A0)); |
// set PD7 to GND |
// set PD7 to low |
PORTD &= ~(1<<PORTD7); |
} |
} |
/branches/V0.68d Code Redesign killagreg/timer2.h |
---|
1,9 → 1,10 |
#ifndef _TIMER2_H |
#define _TIMER2_H |
extern int16_t ServoValue; |
#include <inttypes.h> |
void TIMER2_Init(void); |
extern volatile int16_t ServoValue; |
extern void TIMER2_Init(void); |
/branches/V0.68d Code Redesign killagreg/twimaster.c |
---|
2,6 → 2,8 |
############################################################################*/ |
#include "main.h" |
#include "twimaster.h" |
#include "fc.h" |
unsigned char twi_state = 0; |
unsigned char motor = 0; |
/branches/V0.68d Code Redesign killagreg/twimaster.h |
---|
1,5 → 1,3 |
/*############################################################################ |
############################################################################*/ |
#ifndef _I2C_MASTER_H |
#define _I2C_MASTER_H |
/branches/V0.68d Code Redesign killagreg/uart.c |
---|
6,8 → 6,14 |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include "main.h" |
#include "menu.h" |
#include "timer0.h" |
#include "uart.h" |
#include "fc.h" |
#include "_Settings.h" |
#include "rc.h" |
unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
unsigned volatile char SioTmp = 0; |
unsigned volatile char txd_buffer[TXD_BUFFER_LEN]; |
295,18 → 301,18 |
break; |
case 'b': |
Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
RemoteTasten |= ExternControl.RemoteTasten; |
RemoteButtons |= ExternControl.RemoteButtons; |
ConfirmFrame = ExternControl.Frame; |
break; |
case 'c': |
Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
RemoteTasten |= ExternControl.RemoteTasten; |
RemoteButtons |= ExternControl.RemoteButtons; |
ConfirmFrame = ExternControl.Frame; |
DebugDataAnforderung = 1; |
break; |
case 'h':// x-1 Displayzeilen |
Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
RemoteTasten |= tmp_char_arr2[0]; |
RemoteButtons |= tmp_char_arr2[0]; |
if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
DebugDisplayAnforderung = 1; |
break; |
415,7 → 421,7 |
} |
if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
{ |
Menu(); |
LCD_PrintMenu(); |
DebugDisplayAnforderung = 0; |
if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
{ |
/branches/V0.68d Code Redesign killagreg/uart.h |
---|
10,6 → 10,8 |
#define DUB_KEY_LEFT 16 |
#define DUB_KEY_FIRE 64 |
#include <inttypes.h> |
void BearbeiteRxDaten(void); |
extern unsigned char DebugGetAnforderung; |
49,7 → 51,7 |
struct str_ExternControl |
{ |
unsigned char Digital[2]; |
unsigned char RemoteTasten; |
unsigned char RemoteButtons; |
signed char Nick; |
signed char Roll; |
signed char Gier; |