Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1505 → Rev 1506

/trunk/Spektrum.c
4,8 → 4,15
 
#include "Spektrum.h"
#include "main.h"
//#define RECEIVER_SPEKTRUM_EXP
 
unsigned char SpektrumTimer = 0;
 
#ifdef RECEIVER_SPEKTRUM_EXP
unsigned char sexcnt; // Counter for Spektrum-Expander
unsigned char sexparity; // Parity Bit for Spektrum-Expander
signed char sexdata[7]; // Data for Spektrum-Expander
#endif
//--------------------------------------------------------------//
//--------------------------------------------------------------//
void SpektrumBinding(void)
299,13 → 306,17
 
index++;
if(index < 13)
{
// Stabiles Signal
if(abs(signal - PPM_in[index]) < 6)
{
if(SenderOkay < 200) SenderOkay += 10;
else
{
{
// Stabiles Signal
#ifdef RECEIVER_SPEKTRUM_EXP
if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4)
else if (index == 4) index = 2;
#endif
if(abs(signal - PPM_in[index]) < 6)
{
if(SenderOkay < 200) SenderOkay += 10;
else
{
SenderOkay = 200;
TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input
}
313,11 → 324,57
tmp = (3 * (PPM_in[index]) + signal) / 4;
if(tmp > signal+1) tmp--; else
if(tmp < signal-1) tmp++;
if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
#ifdef RECEIVER_SPEKTRUM_EXP
if(index == 6) // FLIGHT-MODE - The channel used for our data uplink
{
if (signal > 100) // SYNC received
{
sexcnt = 0; // Reset bitcounter
sexparity = 0; // Reset parity bit
}
if (signal < 10)
{
sexcnt++; // Increase counter only for non-sync bits
sexdata[sexcnt] = -113; // Bit = 0 -> value = -113 (min)
}
 
if (sexcnt == 7) sexcnt = 0; // Overflow protection
 
if (signal < -100)
{
sexdata[sexcnt] = 114; // Bit = 1 -> value = 114 (max)
if (sexcnt < 6) sexparity = ~sexparity; // Bit = 1 -> Invert parity bit (without itself)
}
if (sexcnt == 6) // Wait for complete frame
{
if ((sexparity != 0 && sexdata[6] == -113) || (sexparity == 0 && sexdata[6] == 114)) // Parity check
{
if (sexdata[1] == 114 && sexdata[2] == -113) PPM_in[5] = -113;// Reconstruct tripole Flight-Mode value (CH5)
if (sexdata[1] == -113 && sexdata[2] == -113) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5)
if (sexdata[1] == -113 && sexdata[2] == 114) PPM_in[5] = 114; // Reconstruct tripole Flight-Mode value (CH5)
PPM_in[6] = sexdata[3]; // Elevator (CH6)
PPM_in[9] = sexdata[4]; // Aileron (CH9)
PPM_in[10] = sexdata[5]; // Rudder (CH10)
}
}
}
#endif
if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
 
else PPM_diff[index] = 0;
PPM_in[index] = tmp;
#ifdef RECEIVER_SPEKTRUM_EXP
if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4)
if (index == 5) PPM_in[7] = signal; // Gear (CH7)
if (index == 7) PPM_in[8] = signal; // AUX2 (CH8)
#else
PPM_in[index] = tmp;
#endif
}
else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren
else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren
}
else
{
/trunk/capacity.c
56,8 → 56,9
#include "timer0.h"
 
#define CAPACITY_UPDATE_INTERVAL 10 // 10 ms
#define OFFSET_CURRENT 4 // always calculate with a Current of 0,4A
unsigned char OwnConsumptionCurrent; // always calculate with a Current of 0,xA
 
 
// global varialbles
unsigned short update_timer = 0;
Capacity_t Capacity;
75,7 → 76,7
// called in main loop at a regular interval
void Capacity_Update(void)
{
unsigned short Current, SetSum; // max value will be 255 * 12 = 3060
unsigned short Current; // max value will be 255 * 12 = 3060
static unsigned short SubCounter = 0;
static unsigned short CurrentOffset = 0;
static unsigned long SumCurrentOffset = 0;
84,47 → 85,32
if(CheckDelay(update_timer))
{
update_timer += CAPACITY_UPDATE_INTERVAL; // do not use SetDelay to avoid timing leaks
 
// determine sum of all present BL currents and setpoints
Current = 0;
SetSum = 0;
for(i = 0; i < MAX_MOTORS; i++)
{
if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
{
Current += (int16_t)(Motor[i].Current);
SetSum += (int16_t)(Motor[i].SetPoint);
}
}
 
if(SetSum != 0) // if one of the present motors has a setpoint > 0
if(MotorenEin) // if one of the present motors has a setpoint > 0
{
if(Current > CurrentOffset) Capacity.ActualCurrent = Current - CurrentOffset;
else Capacity.ActualCurrent = 0;
// update used capacity
SubCounter += Capacity.ActualCurrent;
 
/*
// 100mA * 1ms * CAPACITY_UPDATE_INTERVAL = 1 mA * 100 ms * CAPACITY_UPDATE_INTERVAL
// = 1mA * 0.1s * CAPACITY_UPDATE_INTERVAL = 1mA * 1min / (600 / CAPACITY_UPDATE_INTERVAL)
// = 1mAh / (36000 / CAPACITY_UPDATE_INTERVAL)
#define SUB_COUNTER_LIMIT (36000 / CAPACITY_UPDATE_INTERVAL)
if(SubCounter > SUB_COUNTER_LIMIT)
{
Capacity.UsedCapacity++; // we have one mAh more
SubCounter -= SUB_COUNTER_LIMIT; // keep the remaining sub part
}
*/
Capacity.ActualCurrent += OwnConsumptionCurrent;
// SubCounter += Capacity.ActualCurrent;
}
else // motors are stopped
{ // determine offsets of motor currents
Capacity.ActualCurrent = 0;
Capacity.ActualCurrent = STATIC_CURRENT;
#define CURRENT_AVERAGE 256L // 256 * 10 ms = 2.56s average time
CurrentOffset = (unsigned short)(SumCurrentOffset/CURRENT_AVERAGE);
SumCurrentOffset -= CurrentOffset;
SumCurrentOffset += Current;
}
SubCounter += OFFSET_CURRENT;
// update used capacity
SubCounter += Capacity.ActualCurrent;
// 100mA * 1ms * CAPACITY_UPDATE_INTERVAL = 1 mA * 100 ms * CAPACITY_UPDATE_INTERVAL
// = 1mA * 0.1s * CAPACITY_UPDATE_INTERVAL = 1mA * 1min / (600 / CAPACITY_UPDATE_INTERVAL)
// = 1mAh / (36000 / CAPACITY_UPDATE_INTERVAL)
/trunk/capacity.h
1,6 → 1,9
#ifndef _CAPACITY_H
#define _CAPACITY_H
 
#define STATIC_CURRENT 4 // always calculate with a Current of 0,xA
extern unsigned char OwnConsumptionCurrent; // always calculate with a Current of 0,xA
 
typedef struct
{
unsigned short ActualCurrent; // in 0.1A Steps
12,6 → 15,5
void Capacity_Init(void);
void Capacity_Update(void);
 
 
#endif //_CAPACITY_H
 
/trunk/libfc.a
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/main.c
231,9 → 231,8
eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
}
printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors);
OwnConsumptionCurrent = 2 * RequiredMotors + STATIC_CURRENT;
 
 
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Check connected BL-Ctrls
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++