/beta/Code Redesign killagreg/capacity.c |
---|
0,0 → 1,118 |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Copyright (c) Holger Buss, Ingo Busker |
// + Thanks to Marcel Haller (Lion) for the nice idea and first implementation |
// + Nur für den privaten Gebrauch |
// + www.MikroKopter.com |
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
// + bzgl. der Nutzungsbedingungen aufzunehmen. |
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
// + Verkauf von Luftbildaufnahmen, usw. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
// + eindeutig als Ursprung verlinkt werden |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
// + Benutzung auf eigene Gefahr |
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
// + mit unserer Zustimmung zulässig |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
// + this list of conditions and the following disclaimer. |
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
// + from this software without specific prior written permission. |
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
// + for non-commercial use (directly or indirectly) |
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
// + with our written permission |
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
// + clearly linked as origin |
// + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// + POSSIBILITY OF SUCH DAMAGE. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include "capacity.h" |
#include "twimaster.h" |
#include "fc.h" |
#include "timer0.h" |
#define CAPACITY_UPDATE_INTERVAL 10 // 10 ms |
// global varialbles |
uint16_t update_timer = 0; |
Capacity_t Capacity; |
// initialize capacity calculation |
void Capacity_Init(void) |
{ |
Capacity.ActualCurrent = 0; |
Capacity.UsedCapacity = 0; |
update_timer = SetDelay(CAPACITY_UPDATE_INTERVAL); |
} |
// called in main loop at a regular interval |
void Capacity_Update(void) |
{ |
static uint16_t SubCounter = 0; |
static uint16_t SumCurrentOffset = 0; |
uint16_t SumCurrent; // max value will be 255 * 12 = 3060 |
uint8_t i; |
if(CheckDelay(update_timer)) |
{ |
update_timer += CAPACITY_UPDATE_INTERVAL; // do not use SetDelay to avoid timing leaks |
// determine sum of all present BL currents |
SumCurrent = 0; |
for(i = 0; i < MAX_MOTORS; i++) |
{ |
if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
{ |
SumCurrent += (int16_t)(Motor[i].Current); |
} |
} |
if(FCFlags & FCFLAG_MOTOR_RUN) |
{ |
if(SumCurrent > SumCurrentOffset) Capacity.ActualCurrent -= SumCurrentOffset; |
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 |
} |
} |
else // motors are stopped |
{ // determine offsets of motor currents |
SumCurrentOffset = (15 * SumCurrentOffset + SumCurrent)/16; // 65535 / (12*255) = 21 for max averaging |
} |
} // EOF check delay update timer |
} |
/beta/Code Redesign killagreg/capacity.h |
---|
0,0 → 1,19 |
#ifndef _CAPACITY_H |
#define _CAPACITY_H |
#include <inttypes.h> |
typedef struct |
{ |
uint16_t ActualCurrent; // in 0.1A Steps |
uint16_t UsedCapacity; // in mAh |
} __attribute__((packed)) Capacity_t; |
extern Capacity_t Capacity; |
void Capacity_Init(void); |
void Capacity_Update(void); |
#endif //_CAPACITY_H |
/beta/Code Redesign killagreg/libfc.a |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/beta/Code Redesign killagreg/main.c |
---|
74,6 → 74,7 |
#include "twimaster.h" |
#include "eeprom.h" |
#include "libfc.h" |
#include "capacity.h" |
uint8_t BoardRelease = 10; |
uint8_t LowVoltageWarning = 94; |
189,7 → 190,7 |
#ifdef USE_MK3MAG |
MK3MAG_Init(); |
#endif |
Capacity_Init(); |
LIBFC_Init(); |
GRN_ON; |
408,6 → 409,7 |
}// EOF CheckDelay(timer) |
LED_Update(); |
Capacity_Update(); |
} |
#ifdef USE_NAVICTRL |
/beta/Code Redesign killagreg/makefile |
---|
110,7 → 110,7 |
########################################################################################################## |
# List C source files here. (C dependencies are automatically generated.) |
SRC = main.c uart0.c timer0.c timer2.c analog.c menu.c led.c |
SRC += twimaster.c rc.c fc.c eeprom.c mymath.c spektrum.c jetimenu.c |
SRC += twimaster.c rc.c fc.c eeprom.c mymath.c spektrum.c jetimenu.c capacity.c |
ifeq ($(EXT), MK3MAG) |
SRC += mk3mag.c |
/beta/Code Redesign killagreg/menu.c |
---|
60,9 → 60,10 |
#include "printf_P.h" |
#include "analog.h" |
#include "twimaster.h" |
#include "capacity.h" |
#include "menu.h" |
uint8_t MaxMenuItem = 15; |
uint8_t MaxMenuItem = 16; |
uint8_t MenuItem = 0; |
194,37 → 195,43 |
LCD_printfxy(0,2,"Roll %4i(%3i)",AdValueAccRoll/2, AdBiasAccRoll/2); // factor 2 because of adding 2 samples in ADC ISR |
LCD_printfxy(0,3,"Z %4i(%3i)",AdValueAccTop, (int16_t)AdBiasAccTop); |
break; |
case 7:// Accumulator Voltage / Remote Control Level |
LCD_printfxy(0,0,"Voltage&Receiver"); |
LCD_printfxy(0,1,"Voltage: %3i.%1iV",UBat/10, UBat%10); |
LCD_printfxy(0,2,"RC-Level: %4i", RC_Quality); |
case 7://Discharge |
LCD_printfxy(0,0,"Battery"); |
LCD_printfxy(0,1,"Voltage: %3i.%1iV",UBat/10, UBat%10); |
LCD_printfxy(0,2,"Current: %3i.%1iA",Capacity.ActualCurrent/10, Capacity.ActualCurrent%10); |
LCD_printfxy(0,3,"Discharge: %5imAh", Capacity.UsedCapacity); |
break; |
case 8:// Remote Control |
LCD_printfxy(0,0,"Receiver"); |
LCD_printfxy(0,1,"RC-RSSI: %4i", RC_RSSI); |
LCD_printfxy(0,2,"RC-Quality: %4i", RC_Quality); |
LCD_printfxy(0,3,"RC-Channels:%4i", RC_Channels); |
break; |
case 8:// Compass Menu Item |
case 9:// Compass Menu Item |
LCD_printfxy(0,0,"Compass"); |
LCD_printfxy(0,1,"Course: %5i",CompassCourse); |
LCD_printfxy(0,2,"Heading: %5i",CompassHeading); |
LCD_printfxy(0,3,"OffCourse: %5i",CompassOffCourse); |
break; |
case 9:// Poti Menu Item |
case 10:// Poti Menu Item |
LCD_printfxy(0,0,"Poti1: %3i" ,Poti[0]); |
LCD_printfxy(0,1,"Poti2: %3i" ,Poti[1]); |
LCD_printfxy(0,2,"Poti3: %3i" ,Poti[2]); |
LCD_printfxy(0,3,"Poti4: %3i" ,Poti[3]); |
break; |
case 10:// Poti Menu Item |
case 11:// Poti Menu Item |
LCD_printfxy(0,0,"Poti5: %3i" ,Poti[4]); |
LCD_printfxy(0,1,"Poti6: %3i" ,Poti[5]); |
LCD_printfxy(0,2,"Poti7: %3i" ,Poti[6]); |
LCD_printfxy(0,3,"Poti8: %3i" ,Poti[7]); |
break; |
case 11:// Servo Menu Item |
case 12:// Servo Menu Item |
LCD_printfxy(0,0,"Servo " ); |
LCD_printfxy(0,1,"Setpoint %3i",FCParam.ServoNickControl); |
LCD_printfxy(0,2,"Position: %3i",ServoNickValue); |
LCD_printfxy(0,3,"Range:%3i-%3i",ParamSet.ServoNickMin, ParamSet.ServoNickMax); |
break; |
case 12://Extern Control |
case 13://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 Ya:%4i ",ExternControl.Gas, ExternControl.Yaw); |
231,7 → 238,7 |
LCD_printfxy(0,3,"Hi:%4i Cf:%4i ",ExternControl.Height, ExternControl.Config); |
break; |
case 13://BL Communication errors |
case 14://BL Communication errors |
LCD_printfxy(0,0,"BL-Ctrl Errors " ); |
LCD_printfxy(0,1," %3d %3d %3d %3d ",Motor[0].State & MOTOR_STATE_ERROR_MASK,Motor[1].State & MOTOR_STATE_ERROR_MASK,Motor[2].State & MOTOR_STATE_ERROR_MASK,Motor[3].State & MOTOR_STATE_ERROR_MASK); |
LCD_printfxy(0,2," %3d %3d %3d %3d ",Motor[4].State & MOTOR_STATE_ERROR_MASK,Motor[5].State & MOTOR_STATE_ERROR_MASK,Motor[6].State & MOTOR_STATE_ERROR_MASK,Motor[7].State & MOTOR_STATE_ERROR_MASK); |
238,7 → 245,7 |
LCD_printfxy(0,3," %3d %3d %3d %3d ",Motor[8].State & MOTOR_STATE_ERROR_MASK,Motor[9].State & MOTOR_STATE_ERROR_MASK,Motor[10].State & MOTOR_STATE_ERROR_MASK,Motor[11].State & MOTOR_STATE_ERROR_MASK); |
break; |
case 14://BL Overview |
case 15://BL Overview |
LCD_printfxy(0,0,"BL-Ctrl found " ); |
LCD_printfxy(0,1," %c %c %c %c ",'-' + 4 * (Motor[0].State>>7),'-' + 5 * (Motor[1].State>>7),'-' + 6 * (Motor[2].State>>7),'-' + 7 * (Motor[3].State>>7)); |
LCD_printfxy(0,2," %c %c %c %c ",'-' + 8 * (Motor[4].State>>7),'-' + 9 * (Motor[5].State>>7),'-' + 10 * (Motor[6].State>>7),'-' + 11 * (Motor[7].State>>7)); |
248,7 → 255,7 |
if(Motor[11].State>>7) LCD_printfxy(12,3,"12"); |
break; |
case 15:// flight time counter |
case 16:// flight time counter |
LCD_printfxy(0,0,"Flight-Time " ); |
LCD_printfxy(0,1,"Total:%5u min",FlightMinutesTotal); |
LCD_printfxy(0,2,"Trip: %5u min",FlightMinutes); |