Battery config updated and started with Doxygen added

This commit is contained in:
Martin Jaeger
2019-03-10 18:34:05 +01:00
parent e9c45702c8
commit e4a20fba85
26 changed files with 3234 additions and 1020 deletions
+8
View File
@@ -26,3 +26,11 @@ script:
- cp src/config.h_template src/config.h
# - platformio ci --lib="lib/Adafruit_GFX" --lib="lib/ThingSet" --project-conf=platformio.ini -e libresolar_0_10,libresolar_0_05
- platformio run -e libresolar_0_10 -e libresolar_0_05 -e cloudsolar_0_2 -e cloudsolar_0_4
deploy:
provider: pages
skip-cleanup: true
github-token: $GH_REPO_TOKEN
keep-history: true
on:
branch: master
+2536
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -14,8 +14,8 @@
* limitations under the License.
*/
#include "adc_dma.h"
#include "mbed.h"
#include "adc_dma.h"
#include "pcb.h" // contains defines for pins
#include <math.h> // log for thermistor calculation
#include "log.h"
@@ -61,7 +61,7 @@ void calibrate_current_sensors(dcdc_t *dcdc, load_output_t *load)
}
//----------------------------------------------------------------------------
void update_measurements(dcdc_t *dcdc, battery_t *bat, load_output_t *load, power_port_t *hs, power_port_t *ls)
void update_measurements(dcdc_t *dcdc, battery_state_t *bat, load_output_t *load, power_port_t *hs, power_port_t *ls)
{
//int v_temp, rts;
+24 -4
View File
@@ -1,5 +1,5 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,15 +17,35 @@
#ifndef ADC_DMA_H
#define ADC_DMA_H
/** @file
*
* @brief Reads ADC via DMA and stores data into necessary structs
*/
#include "dcdc.h"
#include "load.h"
#include "battery.h"
/** Sets offset to actual measured value, i.e. sets zero current point.
*
* All input/output switches and consumers should be switched off before calling this function
*/
void calibrate_current_sensors(dcdc_t *dcdc, load_output_t *load);
void update_measurements(dcdc_t *dcdc, battery_t *bat, load_output_t *load, power_port_t *hs, power_port_t *ls);
/** Updates structures with data read from ADC
*/
void update_measurements(dcdc_t *dcdc, battery_state_t *bat, load_output_t *load, power_port_t *hs, power_port_t *ls);
/** Initializes registers and starts ADC timer
*/
void adc_timer_start(int freq_Hz);
/** Sets necessary ADC registers
*/
void adc_setup(void);
/** Sets necessary DMA registers
*/
void dma_setup(void);
#endif // ADC_DMA
#endif /* ADC_DMA */
+82 -92
View File
@@ -14,7 +14,6 @@
* limitations under the License.
*/
#include "mbed.h"
#include "battery.h"
#include "config.h"
#include "pcb.h"
@@ -31,14 +30,9 @@ extern power_port_t hs_port;
extern load_output_t load;
extern log_data_t log_data;
void battery_init(battery_t *bat, battery_user_settings_t *bat_user)
void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float nominal_capacity)
{
// core battery pack specification (set in config.h)
bat->type = BATTERY_TYPE;
bat->num_cells = BATTERY_NUM_CELLS;
bat->nominal_capacity = BATTERY_CAPACITY;
bat->num_batteries = 1; // initialize with only one battery in series
bat->soh = 100; // assume new battery
bat->nominal_capacity = nominal_capacity;
// common values for all batteries
bat->charge_current_max = bat->nominal_capacity; // 1C should be safe for all batteries
@@ -46,20 +40,20 @@ void battery_init(battery_t *bat, battery_user_settings_t *bat_user)
bat->time_limit_recharge = 60; // sec
bat->time_limit_CV = 120*60; // sec
switch (bat->type)
switch (type)
{
case BAT_TYPE_FLOODED:
case BAT_TYPE_AGM:
case BAT_TYPE_GEL:
bat->cell_voltage_max = 2.4;
bat->cell_voltage_recharge = 2.3;
bat->voltage_max = num_cells * 2.4;
bat->voltage_recharge = num_cells * 2.3;
bat->cell_voltage_load_disconnect = 1.95;
bat->cell_voltage_load_reconnect = 2.1;
bat->cell_voltage_absolute_min = 1.8;
bat->voltage_load_disconnect = num_cells * 1.95;
bat->voltage_load_reconnect = num_cells * 2.1;
bat->voltage_absolute_min = num_cells * 1.8;
bat->cell_ocv_full = 2.2;
bat->cell_ocv_empty = 1.9;
bat->ocv_full = num_cells * 2.2;
bat->ocv_empty = num_cells * 1.9;
// https://batteryuniversity.com/learn/article/charging_the_lead_acid_battery
bat->current_cutoff_CV = bat->nominal_capacity * 0.04; // 3-5 % of C/1
@@ -67,12 +61,12 @@ void battery_init(battery_t *bat, battery_user_settings_t *bat_user)
bat->trickle_enabled = true;
bat->time_trickle_recharge = 30*60;
// http://batteryuniversity.com/learn/article/charging_the_lead_acid_battery
bat->cell_voltage_trickle = (bat->type == BAT_TYPE_FLOODED) ? 2.25 : 2.3;
bat->voltage_trickle = num_cells * ((type == BAT_TYPE_FLOODED) ? 2.25 : 2.3);
bat->equalization_enabled = false;
bat->cell_voltage_equalization = 2.5;
bat->voltage_equalization = num_cells * 2.5;
bat->time_limit_equalization = 60*60;
bat->current_limit_equalization = (1.0 /7.0) * bat->nominal_capacity;
bat->current_limit_equalization = (1.0 / 7.0) * bat->nominal_capacity;
bat->equalization_trigger_time = 8; // weeks
bat->equalization_trigger_deep_cycles = 10; // times
@@ -81,15 +75,15 @@ void battery_init(battery_t *bat, battery_user_settings_t *bat_user)
break;
case BAT_TYPE_LFP:
bat->cell_voltage_max = 3.55; // CV voltage
bat->cell_voltage_recharge = 3.35;
bat->voltage_max = num_cells * 3.55; // CV voltage
bat->voltage_recharge = num_cells * 3.35;
bat->cell_voltage_load_disconnect = 3.0;
bat->cell_voltage_load_reconnect = 3.15;
bat->cell_voltage_absolute_min = 2.0;
bat->voltage_load_disconnect = num_cells * 3.0;
bat->voltage_load_reconnect = num_cells * 3.15;
bat->voltage_absolute_min = num_cells * 2.0;
bat->cell_ocv_full = 3.4; // will give really bad SOC calculation
bat->cell_ocv_empty = 3.0; // because of flat OCV of LFP cells...
bat->ocv_full = num_cells * 3.4; // will give really bad SOC calculation
bat->ocv_empty = num_cells * 3.0; // because of flat OCV of LFP cells...
bat->current_cutoff_CV = bat->nominal_capacity / 10; // C/10 cut-off at end of CV phase by default
@@ -100,15 +94,15 @@ void battery_init(battery_t *bat, battery_user_settings_t *bat_user)
case BAT_TYPE_NMC:
case BAT_TYPE_NMC_HV:
bat->cell_voltage_max = (bat->type == BAT_TYPE_NMC_HV) ? 4.35 : 4.20;
bat->cell_voltage_recharge = 3.9;
bat->voltage_max = (type == BAT_TYPE_NMC_HV) ? 4.35 : 4.20;
bat->voltage_recharge = num_cells * 3.9;
bat->cell_voltage_load_disconnect = 3.3;
bat->cell_voltage_load_reconnect = 3.6;
bat->cell_voltage_absolute_min = 2.5;
bat->voltage_load_disconnect = num_cells * 3.3;
bat->voltage_load_reconnect = num_cells * 3.6;
bat->voltage_absolute_min = num_cells * 2.5;
bat->cell_ocv_full = 4.0;
bat->cell_ocv_empty = 3.0;
bat->ocv_full = num_cells * 4.0;
bat->ocv_empty = num_cells * 3.0;
bat->current_cutoff_CV = bat->nominal_capacity / 10; // C/10 cut-off at end of CV phase by default
@@ -118,82 +112,78 @@ void battery_init(battery_t *bat, battery_user_settings_t *bat_user)
break;
case BAT_TYPE_NONE:
case BAT_TYPE_CUSTOM:
break;
}
// initialize bat_user
bat_user->nominal_capacity = bat->nominal_capacity;
bat_user->voltage_max = bat->num_cells * bat->cell_voltage_max;
bat_user->voltage_recharge = bat->num_cells * bat->cell_voltage_recharge;
bat_user->voltage_load_reconnect = bat->num_cells * bat->cell_voltage_load_reconnect;
bat_user->voltage_load_disconnect = bat->num_cells * bat->cell_voltage_load_disconnect;
bat_user->voltage_absolute_min = bat->num_cells * bat->cell_voltage_absolute_min;
bat_user->charge_current_max = bat->charge_current_max;
bat_user->current_cutoff_CV = bat->current_cutoff_CV;
bat_user->time_limit_CV = bat->time_limit_CV;
bat_user->trickle_enabled = bat->trickle_enabled;
bat_user->time_trickle_recharge = bat->time_trickle_recharge;
bat_user->temperature_compensation = bat->temperature_compensation;
// call user function (defined in config.cpp to overwrite above initializations)
battery_init_user(bat, bat_user);
}
// weak function to be overridden by user in config.cpp
WEAK void battery_init_user(battery_t *bat, battery_user_settings_t *bat_user) {;}
// checks settings in bat_user for plausibility and writes them to bat if everything is fine
bool battery_user_settings(battery_t *bat, battery_user_settings_t *bat_user)
// checks settings in bat_conf for plausibility
bool battery_conf_check(battery_conf_t *bat_conf)
{
// things to check:
// - cell_voltage_XXX in the range of what the charger can handle?
// - load_disconnect/reconnect hysteresis makes sense?
// - cutoff current not extremely low/high
// - capacity plausible
if (bat_user->voltage_max > LOW_SIDE_VOLTAGE_MAX &&
bat_user->voltage_load_reconnect > (bat_user->voltage_load_disconnect + 0.8) &&
bat_user->voltage_recharge < (bat_user->voltage_max - 0.6) &&
bat_user->voltage_recharge > (bat_user->voltage_load_disconnect + 1) &&
bat_user->voltage_load_disconnect > (bat_user->voltage_absolute_min + 0.5) &&
bat_user->current_cutoff_CV < (bat_user->nominal_capacity / 9.0) && // C/10 or lower allowed
bat_user->current_cutoff_CV > 0.01 &&
(bat_user->trickle_enabled == false ||
(bat_user->voltage_trickle < bat_user->voltage_max &&
bat_user->voltage_trickle > bat_user->voltage_load_disconnect))
) {
/*
printf("battery_conf_check: %d %d %d %d %d %d %d\n",
bat_conf->voltage_load_reconnect > (bat_conf->voltage_load_disconnect + 0.6),
bat_conf->voltage_recharge < (bat_conf->voltage_max - 0.4),
bat_conf->voltage_recharge > (bat_conf->voltage_load_disconnect + 1),
bat_conf->voltage_load_disconnect > (bat_conf->voltage_absolute_min + 0.4),
bat_conf->current_cutoff_CV < (bat_conf->nominal_capacity / 10.0), // C/10 or lower allowed
bat_conf->current_cutoff_CV > 0.01,
(bat_conf->trickle_enabled == false ||
(bat_conf->voltage_trickle < bat_conf->voltage_max &&
bat_conf->voltage_trickle > bat_conf->voltage_load_disconnect))
);
*/
// TODO: stop DC/DC
return
(bat_conf->voltage_load_reconnect > (bat_conf->voltage_load_disconnect + 0.6) &&
bat_conf->voltage_recharge < (bat_conf->voltage_max - 0.4) &&
bat_conf->voltage_recharge > (bat_conf->voltage_load_disconnect + 1) &&
bat_conf->voltage_load_disconnect > (bat_conf->voltage_absolute_min + 0.4) &&
bat_conf->current_cutoff_CV < (bat_conf->nominal_capacity / 10.0) && // C/10 or lower allowed
bat_conf->current_cutoff_CV > 0.01 &&
(bat_conf->trickle_enabled == false ||
(bat_conf->voltage_trickle < bat_conf->voltage_max &&
bat_conf->voltage_trickle > bat_conf->voltage_load_disconnect))
);
}
bat->type = BAT_TYPE_CUSTOM;
bat->num_cells = 1; // custom battery defines voltages on battery level
bat->nominal_capacity = bat_user->nominal_capacity;
bat->cell_voltage_max = bat_user->voltage_max;
bat->cell_voltage_recharge = bat_user->voltage_recharge;
bat->cell_voltage_load_reconnect = bat_user->voltage_load_reconnect;
bat->cell_voltage_load_disconnect = bat_user->voltage_load_disconnect;
bat->cell_voltage_absolute_min = bat_user->voltage_absolute_min;
bat->charge_current_max = bat_user->charge_current_max;
bat->current_cutoff_CV = bat_user->current_cutoff_CV;
bat->time_limit_CV = bat_user->time_limit_CV;
bat->trickle_enabled = bat_user->trickle_enabled;
bat->time_trickle_recharge = bat_user->time_trickle_recharge;
bat->temperature_compensation = bat_user->temperature_compensation;
void battery_conf_overwrite(battery_conf_t *source, battery_conf_t *destination)
{
// TODO: stop DC/DC
// TODO:
// - update also DC/DC etc. (now this function only works at system startup)
// - restart DC/DC
destination->nominal_capacity = source->nominal_capacity;
destination->voltage_max = source->voltage_max;
destination->voltage_recharge = source->voltage_recharge;
destination->voltage_load_reconnect = source->voltage_load_reconnect;
destination->voltage_load_disconnect = source->voltage_load_disconnect;
destination->voltage_absolute_min = source->voltage_absolute_min;
destination->charge_current_max = source->charge_current_max;
destination->current_cutoff_CV = source->current_cutoff_CV;
destination->time_limit_CV = source->time_limit_CV;
destination->trickle_enabled = source->trickle_enabled;
destination->voltage_trickle = source->voltage_trickle;
destination->time_trickle_recharge = source->time_trickle_recharge;
destination->temperature_compensation = source->temperature_compensation;
return true;
}
// TODO:
// - update also DC/DC etc. (now this function only works at system startup)
// - restart DC/DC
}
return false;
void battery_state_init(battery_state_t *bat_state)
{
bat_state->num_batteries = 1; // initialize with only one battery in series
bat_state->soh = 100; // assume new battery
}
//----------------------------------------------------------------------------
// must be called exactly once per second, otherwise energy calculation gets wrong
void battery_update_energy(battery_t *bat, float voltage, float current)
void battery_update_energy(battery_conf_t *bat_conf, battery_state_t *bat, float voltage, float current)
{
// static variables so that the are not reset during each function call
static int seconds_zero_solar = 0;
@@ -228,8 +218,8 @@ void battery_update_energy(battery_t *bat, float voltage, float current)
bat->discharged_Ah += (load.current - current) / 3600.0;
if (fabs(current) < 0.2) {
int soc_new = (int)((voltage / bat->num_cells - bat->cell_ocv_empty) /
(bat->cell_ocv_full - bat->cell_ocv_empty) * 10000.0);
int soc_new = (int)((voltage - bat_conf->ocv_empty) /
(bat_conf->ocv_full - bat_conf->ocv_empty) * 10000.0);
if (soc_new > 10000) {
soc_new = 10000;
+121 -102
View File
@@ -1,91 +1,140 @@
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BATTERY_H_
#define __BATTERY_H_
#ifndef BATTERY_H
#define BATTERY_H
/** @file
*
* @brief Battery configuration and functions
*/
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ToDo: change to int values
* Power: W/10 = 100 mW --> int16_t max. 3276.8 W
* Current: W/100 = 10 mA --> int16_t max. 327.68 A
* Voltage: V/100 = 10 mV --> int16_t max. 327.68 V
/** Battery cell types
*/
// battery types
enum bat_type {
BAT_TYPE_NONE = 0, // safe standard settings
BAT_TYPE_FLOODED, // old flooded (wet) lead-acid batteries
BAT_TYPE_GEL, // VRLA gel batteries (maintainance-free)
BAT_TYPE_AGM, // AGM batteries (maintainance-free)
BAT_TYPE_LFP, // LiFePO4 Li-ion batteries (3.3V nominal)
BAT_TYPE_NMC, // NMC/Graphite Li-ion batteries (3.7V nominal)
BAT_TYPE_NMC_HV, // NMC/Graphite High Voltage Li-ion batteries (3.7V nominal, 4.35 max)
BAT_TYPE_CUSTOM // user configurable
BAT_TYPE_NONE = 0, ///< Safe standard settings
BAT_TYPE_FLOODED, ///< Old flooded (wet) lead-acid batteries
BAT_TYPE_GEL, ///< VRLA gel batteries (maintainance-free)
BAT_TYPE_AGM, ///< AGM batteries (maintainance-free)
BAT_TYPE_LFP, ///< LiFePO4 Li-ion batteries (3.3V nominal)
BAT_TYPE_NMC, ///< NMC/Graphite Li-ion batteries (3.7V nominal)
BAT_TYPE_NMC_HV ///< NMC/Graphite High Voltage Li-ion batteries (3.7V nominal, 4.35 max)
};
/** Battery configuration data
*
* Data will be initialized in battery_init depending on configured cell type in config.h.
*/
typedef struct
{
/* Configuration data
/** Nominal battery capacity or sum of parallel cells capacity (Ah)
*
* Data will is initialized in battery_int depending on configured cell type in config.h. It can
* be customized by overloading the weak function battery_init_user.
* The nominal capacity is used for SOC calculation and definition of current limits.
*/
float nominal_capacity;
// Core battery information
bat_type type; // - see above for allowed types
unsigned int num_cells; // - number of cells in series
float nominal_capacity; // Ah cell capacity or sum of parallel cells capacity
// Capacity is currently mainly used to define current limits, but might
// become important for improved SOC calculation algorithms
float useable_capacity; // Ah estimated useable capacity based on coulomb counting
/** Recharge voltage (V)
*
* Start charging again if voltage of fully charged battery drops below this threshold.
*
* Remark: Setting the value too close to the max voltage will cause more charging stress on lithium based batteries.
*/
float voltage_recharge;
// State: Standby
float cell_voltage_recharge; // V below this voltage start charging again after battery has been fully charged
// Remark: setting the value too close to the max voltage will cause more
// charging stress on lithium based batteries
int time_limit_recharge; // sec
/** Recharge time limit (sec)
*
* Start charging of previously fully charged battery earliest after this period of time.
*/
int time_limit_recharge;
float cell_voltage_absolute_min; // V below this voltage the battery is considered damaged
//float cell_voltage_absolute_max; // V above this voltage the battery can be damaged
/** Absolute minimum voltage (V)
*
* Below this voltage the battery is considered damaged.
*/
float voltage_absolute_min;
// State: CC/bulk
float charge_current_max; // A limits the current if PCB allows more than the battery
/** Maximum charge current in *CC/bulk* phase (A)
*
* Limits the current if the PCB allows more than the battery.
*/
float charge_current_max;
// State: CV/absorption
float cell_voltage_max; // V charger target voltage per cell, switching from CC to CV at this voltage
float current_cutoff_CV; // A constant voltage charging phase stopped if current is below this value
int time_limit_CV; // sec after this time limit, CV charging is stopped independent of current
/** Maximum voltage in CV/absorption phase (V)
*
* Charger target voltage, switching from CC to CV at this voltage threshold.
*/
float voltage_max;
/** CV phase cut-off current limit (A)
*
* Constant voltage charging phase stopped if current is below this value.
*/
float current_cutoff_CV;
/** CV phase cut-off time limit (s)
*
* After this time, CV charging is stopped independent of current.
*/
int time_limit_CV;
// State: float/trickle
/** Enable float/trickle charging
*
* Caution: Do not enable trickle charging for lithium-ion batteries
*/
bool trickle_enabled;
float cell_voltage_trickle; // V charger target voltage for trickle charging of lead-acid batteries
int time_trickle_recharge; // sec
/** Trickle voltage (V)
*
* Charger target voltage for trickle charging of lead-acid batteries
*/
float voltage_trickle;
/** Trickle recharge time (s)
*
* If the trickle voltage is not reached anymore (e.g. because of lack of solar
* input power) for this period of time, the charger state machine goes back
* into CC/bulk charging mode.
*/
int time_trickle_recharge;
// State: equalization
bool equalization_enabled;
float cell_voltage_equalization; // V
float voltage_equalization; // V
int time_limit_equalization; // sec
float current_limit_equalization; // A
int equalization_trigger_time; // weeks
int equalization_trigger_deep_cycles; // times
float cell_voltage_load_disconnect; // V when discharging, stop power to load if battery voltage drops below this value
float cell_voltage_load_reconnect; // V re-enable the load only after charged beyond this value
float voltage_load_disconnect; // V when discharging, stop power to load if battery voltage drops below this value
float voltage_load_reconnect; // V re-enable the load only after charged beyond this value
// used to calculate state of charge information
float cell_ocv_full;
float cell_ocv_empty;
float ocv_full;
float ocv_empty;
float temperature_compensation; // voltage compensation (suggested: -3 mV/°C/cell)
/* Operational data (updated during operation)
*/
} battery_conf_t;
typedef struct
{
int num_batteries; // used for automatic 12V/24V battery detection at start-up
// can be 1 or 2 only.
@@ -96,6 +145,8 @@ typedef struct
uint32_t input_Wh_total;
uint32_t output_Wh_total;
float useable_capacity; // Ah estimated useable capacity based on coulomb counting
float discharged_Ah; // coloumb counter for SOH calculation
uint16_t num_full_charges;
@@ -103,75 +154,43 @@ typedef struct
uint16_t soc;
uint16_t soh;
unsigned int state; // valid states: enum charger_states
unsigned int chg_state; // valid states: enum charger_states
int time_state_changed; // timestamp of last state change
int time_voltage_limit_reached; // last time the CV limit was reached
bool full;
} battery_t;
} battery_state_t;
// these voltages are defined on BATTERY level, NOT CELL!
typedef struct
{
float nominal_capacity; // Ah cell capacity or sum of parallel cells capacity
// Capacity is currently mainly used to define current limits, but might
// become important for improved SOC calculation algorithms
// State: Standby
float voltage_recharge; // V below this voltage start charging again after battery has been fully charged
// Remark: setting the value too close to the max voltage will cause more
// charging stress on lithium based batteries
float voltage_absolute_min; // V below this voltage the battery is considered damaged
// State: CC/bulk
float charge_current_max; // A limits the current if PCB allows more than the battery
// State: CV/absorption
float voltage_max; // V charger target voltage per cell, switching from CC to CV at this voltage
float current_cutoff_CV; // A constant voltage charging phase stopped if current is below this value
int time_limit_CV; // sec after this time limit, CV charging is stopped independent of current
// State: float/trickle
bool trickle_enabled;
float voltage_trickle; // V charger target voltage for trickle charging of lead-acid batteries
int time_trickle_recharge; // sec
float voltage_load_disconnect; // V when discharging, stop power to load if battery voltage drops below this value
float voltage_load_reconnect; // V re-enable the load only after charged beyond this value
float temperature_compensation; // voltage compensation (suggested: -3 mV/°C/cell)
} battery_user_settings_t;
/* Basic initialization of battery
/** Basic initialization of battery configuration
*
* Configures battery based on settings defined in config.h and initializes
* bat_user with same values
*/
void battery_init(battery_t *bat, battery_user_settings_t *bat_user);
void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float nominal_capacity);
/* User settings of battery
/** Checks battery user settings
*
* This function should be implemented in config.cpp
*/
void battery_init_user(battery_t *bat, battery_user_settings_t *bat_user);
bool battery_conf_check(battery_conf_t *bat);
/* Update battery settings
/** Overwrites battery settings (config should be checked first)
*
* Settings specified in bat_user will be copied to actual battery_t,
* if suggested updates are valid (includes plausibility check!)
*/
bool battery_user_settings(battery_t *bat, battery_user_settings_t *bat_user);
void battery_conf_overwrite(battery_conf_t *source, battery_conf_t *destination);
void battery_update_energy(battery_t *bat, float voltage, float current);
/** Basic initialization of battery state (e.g. SOC)
*/
void battery_state_init(battery_state_t *bat_state);
/** Energy calculation and SOC estimation
*
* Must be called exactly once per second, otherwise energy calculation gets wrong.
*/
void battery_update_energy(battery_conf_t *bat_conf, battery_state_t *bat, float voltage, float current);
#ifdef __cplusplus
}
#endif
#endif // __BATTERY_H_
#endif /* BATTERY_H */
+41 -41
View File
@@ -21,11 +21,11 @@
#include "log.h"
// private function
void _enter_state(battery_t* bat, int next_state)
void _enter_state(battery_state_t* bat_state, int next_state)
{
//printf("Enter State: %d\n", next_state);
bat->time_state_changed = time(NULL);
bat->state = next_state;
bat_state->time_state_changed = time(NULL);
bat_state->chg_state = next_state;
}
/*****************************************************************************
@@ -58,96 +58,96 @@ void _enter_state(battery_t* bat, int next_state)
enabled in the software)
*/
void charger_state_machine(power_port_t *port, battery_t *bat, float voltage, float current)
void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery_state_t *bat_state, float voltage, float current)
{
//printf("time_state_change = %d, time = %d, v_bat = %f, i_bat = %f\n", bat->time_state_changed, time(NULL), voltage, current);
//printf("time_state_change = %d, time = %d, v_bat = %f, i_bat = %f\n", bat_state->time_state_changed, time(NULL), voltage, current);
// Load management
// battery port input state (i.e. battery discharging direction) defines load state
if (port->input_allowed == true &&
voltage < bat->cell_voltage_load_disconnect * bat->num_cells)
voltage < bat_conf->voltage_load_disconnect)
{
port->input_allowed = false;
bat->num_deep_discharges++;
bat_state->num_deep_discharges++;
if (bat->useable_capacity < 0.1) {
bat->useable_capacity = bat->discharged_Ah;
if (bat_state->useable_capacity < 0.1) {
bat_state->useable_capacity = bat_state->discharged_Ah;
} else {
// slowly adapt new measurements with low-pass filter
bat->useable_capacity = 0.8 * bat->useable_capacity + 0.2 * bat->discharged_Ah;
bat_state->useable_capacity = 0.8 * bat_state->useable_capacity + 0.2 * bat_state->discharged_Ah;
}
// simple SOH estimation
bat->soh = bat->useable_capacity / bat->nominal_capacity;
bat_state->soh = bat_state->useable_capacity / bat_conf->nominal_capacity;
}
if (voltage >= bat->cell_voltage_load_reconnect * bat->num_cells) {
if (voltage >= bat_conf->voltage_load_reconnect) {
port->input_allowed = true;
}
// state machine
switch (bat->state) {
switch (bat_state->chg_state) {
case CHG_STATE_IDLE: {
if (voltage < bat->num_cells * bat->cell_voltage_recharge
&& (time(NULL) - bat->time_state_changed) > bat->time_limit_recharge)
if (voltage < bat_conf->voltage_recharge
&& (time(NULL) - bat_state->time_state_changed) > bat_conf->time_limit_recharge)
{
port->voltage_output_target = bat->num_cells * bat->cell_voltage_max;
port->current_output_max = bat->charge_current_max;
port->voltage_output_target = bat_conf->voltage_max;
port->current_output_max = bat_conf->charge_current_max;
port->output_allowed = true;
bat->full = false;
_enter_state(bat, CHG_STATE_CC);
bat_state->full = false;
_enter_state(bat_state, CHG_STATE_CC);
}
break;
}
case CHG_STATE_CC: {
if (voltage > port->voltage_output_target) {
port->voltage_output_target = bat->num_cells * bat->cell_voltage_max;
_enter_state(bat, CHG_STATE_CV);
port->voltage_output_target = bat_conf->voltage_max;
_enter_state(bat_state, CHG_STATE_CV);
}
break;
}
case CHG_STATE_CV: {
if (voltage >= port->voltage_output_target) {
bat->time_voltage_limit_reached = time(NULL);
bat_state->time_voltage_limit_reached = time(NULL);
}
// cut-off limit reached because battery full (i.e. CV mode still
// reached by available solar power within last 2s) or CV period long enough?
if ((current < bat->current_cutoff_CV && (time(NULL) - bat->time_voltage_limit_reached) < 2)
|| (time(NULL) - bat->time_state_changed) > bat->time_limit_CV)
if ((current < bat_conf->current_cutoff_CV && (time(NULL) - bat_state->time_voltage_limit_reached) < 2)
|| (time(NULL) - bat_state->time_state_changed) > bat_conf->time_limit_CV)
{
bat->full = true;
bat->num_full_charges++;
bat->discharged_Ah = 0; // reset coulomb counter
bat_state->full = true;
bat_state->num_full_charges++;
bat_state->discharged_Ah = 0; // reset coulomb counter
if (bat->equalization_enabled) {
if (bat_conf->equalization_enabled) {
// TODO: additional conditions!
port->voltage_output_target = bat->num_cells * bat->cell_voltage_equalization;
port->current_output_max = bat->current_limit_equalization;
_enter_state(bat, CHG_STATE_EQUALIZATION);
port->voltage_output_target = bat_conf->voltage_equalization;
port->current_output_max = bat_conf->current_limit_equalization;
_enter_state(bat_state, CHG_STATE_EQUALIZATION);
}
else if (bat->trickle_enabled) {
port->voltage_output_target = bat->num_cells * bat->cell_voltage_trickle;
_enter_state(bat, CHG_STATE_TRICKLE);
else if (bat_conf->trickle_enabled) {
port->voltage_output_target = bat_conf->voltage_trickle;
_enter_state(bat_state, CHG_STATE_TRICKLE);
}
else {
port->current_output_max = 0;
port->output_allowed = false;
_enter_state(bat, CHG_STATE_IDLE);
_enter_state(bat_state, CHG_STATE_IDLE);
}
}
break;
}
case CHG_STATE_TRICKLE: {
if (voltage >= port->voltage_output_target) {
bat->time_voltage_limit_reached = time(NULL);
bat_state->time_voltage_limit_reached = time(NULL);
}
if (time(NULL) - bat->time_voltage_limit_reached > bat->time_trickle_recharge)
if (time(NULL) - bat_state->time_voltage_limit_reached > bat_conf->time_trickle_recharge)
{
port->current_output_max = bat->charge_current_max;
port->voltage_output_target = bat->num_cells * bat->cell_voltage_max;
bat->full = false;
_enter_state(bat, CHG_STATE_CC);
port->current_output_max = bat_conf->charge_current_max;
port->voltage_output_target = bat_conf->voltage_max;
bat_state->full = false;
_enter_state(bat_state, CHG_STATE_CC);
}
// assumption: trickle does not harm the battery --> never go back to idle
// (for Li-ion battery: disable trickle!)
+40 -15
View File
@@ -1,5 +1,5 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,13 @@
* limitations under the License.
*/
#ifndef __CHARGER_H_
#define __CHARGER_H_
/** @file
*
* @brief Battery charger state machine.
*/
#ifndef CHARGER_H
#define CHARGER_H
#include <stdbool.h>
#include <stdint.h>
@@ -23,11 +28,35 @@
#include "dcdc.h"
#include "power_port.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Possible charger states
// possible charger states
## Idle
Initial state of the charge controller. If the solar voltage is high enough
and the battery is not full, charging in CC mode is started.
## CC / bulk charging
The battery is charged with maximum possible current (MPPT algorithm is
active) until the CV voltage limit is reached.
## CV / absorption charging
Lead-acid batteries are charged for some time using a slightly higher charge
voltage. After a current cutoff limit or a time limit is reached, the charger
goes into trickle or equalization mode for lead-acid batteries or back into
Standby for Li-ion batteries.
## Trickle charging
This mode is kept forever for a lead-acid battery and keeps the battery at
full state of charge. If too much power is drawn from the battery, the
charger switches back into CC / bulk charging mode.
## Equalization charging
This mode is only used for lead-acid batteries after several deep-discharge
cycles or a very long period of time with no equalization. Voltage is
increased to 15V or above, so care must be taken for the other system
components attached to the battery. (currently, no equalization charging is
enabled in the software)
*/
enum charger_state {
CHG_STATE_IDLE,
CHG_STATE_CC,
@@ -36,12 +65,8 @@ enum charger_state {
CHG_STATE_EQUALIZATION
};
/* Charger state machine update, should be called exactly once per second
/** Charger state machine update, should be called once per second
*/
void charger_state_machine(power_port_t *port, battery_t *bat, float voltage, float current);
void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery_state_t *bat_state, float voltage, float current);
#ifdef __cplusplus
}
#endif
#endif // CHARGER_H
#endif /* CHARGER_H */
+11 -9
View File
@@ -1,5 +1,5 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,11 +14,13 @@
* limitations under the License.
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
#ifndef CONFIG_H
#define CONFIG_H
/* This file is used to define personal settings, e.g. which type of interface
* at the UEXT port should be used.
/** @file
*
* @brief
* Used to define personal settings, e.g. which type of interface at the UEXT port should be used.
*/
#define DCDC_MODE_INIT MODE_MPPT_BUCK
@@ -62,13 +64,13 @@
#define WIFI_PASS "pass"
// OpenEnergyMonitor emoncms configuration (used in WiFi interface)
#define EMONCMS_ENABLED true
#define EMONCMS_ENABLED
#define EMONCMS_HOST ""
#define EMONCMS_APIKEY "" // get from emoncms webinterface
#define EMONCMS_NODE "mppt" // name of your device
// MQTT server configuration (used in GSM or WiFi interface)
#define MQTT_ENABLED false
#define MQTT_ENABLED
#define MQTT_HOST "your-host-or-ip"
#define MQTT_PORT "1883"
#define MQTT_USER "you"
@@ -76,4 +78,4 @@
#define MQTT_PUBLISH_TOPIC "nodes2server/report"
#define MQTT_SUBSCRIBE_TOPIC "server2node/state-req"
#endif /* _CONFIG_H_ */
#endif /* CONFIG_H */
+61 -29
View File
@@ -27,12 +27,13 @@
#include "eeprom.h"
extern log_data_t log_data;
extern battery_t bat;
extern battery_state_t bat_state;
extern battery_conf_t bat_conf;
extern battery_conf_t bat_conf_user;
extern dcdc_t dcdc;
extern load_output_t load;
extern power_port_t hs_port;
extern power_port_t ls_port;
extern battery_user_settings_t bat_user;
const char* manufacturer = "Libre Solar";
const char* deviceName = "MPPT Solar Charge Controller";
@@ -51,12 +52,12 @@ const data_object_t data_objects[] = {
{0x04, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(load.usb_enabled_target), "USBEnDefault"},
{0x05, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_INT32, 0, (void*) &(load.state), "LoadState"},
{0x06, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_INT32, 0, (void*) &(load.usb_state), "USBState"},
{0x07, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT32, 0, (void*) &(bat.input_Wh_total), "InputTotal_Wh"},
{0x08, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT32, 0, (void*) &(bat.output_Wh_total), "OutputTotal_Wh"},
{0x09, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.soc), "SOC_%"}, // output will be uint8_t
{0x0A, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.useable_capacity), "BatUse_Ah"}, // useable battery capacity
{0x10, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.num_full_charges), "NumFullChg"},
{0x11, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.num_deep_discharges), "NumDeepDis"},
{0x07, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT32, 0, (void*) &(bat_state.input_Wh_total), "InputTotal_Wh"},
{0x08, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT32, 0, (void*) &(bat_state.output_Wh_total), "OutputTotal_Wh"},
{0x09, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.soc), "SOC_%"}, // output will be uint8_t
{0x0A, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.useable_capacity), "BatUse_Ah"}, // useable battery capacity
{0x10, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.num_full_charges), "NumFullChg"},
{0x11, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.num_deep_discharges), "NumDeepDis"},
// normal priority data objects (IDs > 23 = 0x17)
{0x18, TS_CAT_INFO, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_UINT32, 0, (void*) &(deviceID), "DeviceID"},
@@ -64,19 +65,19 @@ const data_object_t data_objects[] = {
{0x1A, TS_CAT_INFO, TS_ACCESS_READ, TS_T_STRING, 0, (void*) &(deviceName), "DeviceName"},
// config
{0x20, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_user.nominal_capacity), "BatNom_Ah"},
{0x21, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_user.voltage_recharge), "BatRecharge_V"},
{0x22, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_user.voltage_absolute_min), "BatAbsMin_V"},
{0x23, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_user.charge_current_max), "BatChgMax_A"},
{0x24, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_user.voltage_max), "BatTarget_V"},
{0x25, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_user.current_cutoff_CV), "BatCutoff_A"},
{0x26, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_user.time_limit_CV), "BatCutoff_s"},
{0x27, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(bat_user.trickle_enabled), "TrickleEn"},
{0x28, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 0, (void*) &(bat_user.voltage_trickle), "Trickle_V"},
{0x29, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_user.time_trickle_recharge), "TrickleRecharge_s"},
{0x2A, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_user.voltage_load_disconnect), "LoadDisconnect_V"},
{0x2B, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_user.voltage_load_reconnect), "LoadReconnect_V"},
{0x2C, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_user.temperature_compensation), "TempFactor"},
{0x20, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.nominal_capacity), "BatNom_Ah"},
{0x21, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_recharge), "BatRecharge_V"},
{0x22, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_absolute_min), "BatAbsMin_V"},
{0x23, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.charge_current_max), "BatChgMax_A"},
{0x24, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_max), "BatTarget_V"},
{0x25, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.current_cutoff_CV), "BatCutoff_A"},
{0x26, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_conf_user.time_limit_CV), "BatCutoff_s"},
{0x27, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(bat_conf_user.trickle_enabled), "TrickleEn"},
{0x28, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 0, (void*) &(bat_conf_user.voltage_trickle), "Trickle_V"},
{0x29, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_conf_user.time_trickle_recharge), "TrickleRecharge_s"},
{0x2A, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_disconnect), "LoadDisconnect_V"},
{0x2B, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_reconnect), "LoadReconnect_V"},
{0x2C, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.temperature_compensation), "TempFactor"},
// input data
{0x31, TS_CAT_INPUT, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(load.enabled_target), "LoadEnTarget"},
@@ -91,16 +92,16 @@ const data_object_t data_objects[] = {
{0x46, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(log_data.dcdc_current_max), "BatMax_A"},
{0x47, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(load.current), "Load_A"},
{0x48, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(log_data.load_current_max), "LoadMax_A"},
{0x49, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 1, (void*) &(bat.temperature), "Bat_°C"},
{0x49, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 1, (void*) &(bat_state.temperature), "Bat_°C"},
{0x4A, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 1, (void*) &(dcdc.temp_mosfets), "Internal_°C"},
{0x4B, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 1, (void*) &(log_data.temp_mosfets_max), "InternalMax_°C"},
{0x4D, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(bat.input_Wh_day), "InputDay_Wh"},
{0x4E, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(bat.output_Wh_day), "OutputDay_Wh"},
{0x50, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.state), "ChgState"},
{0x4D, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(bat_state.input_Wh_day), "InputDay_Wh"},
{0x4E, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_FLOAT32, 2, (void*) &(bat_state.output_Wh_day), "OutputDay_Wh"},
{0x50, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.chg_state), "ChgState"},
{0x51, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_INT32, 0, (void*) &(log_data.day_counter), "DayCount"},
{0x52, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.soh), "SOH_%"}, // output will be uint8_t
{0x53, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.discharged_Ah), "Dis_Ah"}, // coulomb counter
{0x54, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat.useable_capacity), "BatUse_Ah"}, // useable battery capacity
{0x52, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.soh), "SOH_%"}, // output will be uint8_t
{0x53, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.discharged_Ah), "Dis_Ah"}, // coulomb counter
{0x54, TS_CAT_OUTPUT, TS_ACCESS_READ, TS_T_UINT16, 0, (void*) &(bat_state.useable_capacity), "BatUse_Ah"}, // useable battery capacity
// ToDo: GPS position (latitude / longitude), see here: https://github.com/allthingstalk/cbor/blob/master/CBOR-Tag103-Geographic-Coordinates.md
// calibration data (write only after authentication)
@@ -135,4 +136,35 @@ volatile const int PUB_CHANNEL_SERIAL = 0;
ThingSet ts(
data_objects, sizeof(data_objects)/sizeof(data_object_t),
pub_channels, sizeof(pub_channels)/sizeof(ts_pub_channel_t)
);
);
void data_objects_update_conf()
{
bool changed = false;
if (battery_conf_check(&bat_conf_user)) {
printf("New config valid and activated.\n");
battery_conf_overwrite(&bat_conf_user, &bat_conf);
changed = true;
}
else {
printf("Check not passed, getting back old config.\n");
battery_conf_overwrite(&bat_conf, &bat_conf_user);
}
// TODO: check also for changes in Load/USB EnDefault
changed = true; // temporary hack
if (changed)
eeprom_store_data();
}
void data_objects_read_eeprom()
{
eeprom_restore_data();
if (battery_conf_check(&bat_conf_user)) {
battery_conf_overwrite(&bat_conf_user, &bat_conf);
}
else {
battery_conf_overwrite(&bat_conf, &bat_conf_user);
}
}
+11 -52
View File
@@ -1,5 +1,5 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,56 +17,15 @@
#ifndef DATA_OBJECTS_H
#define DATA_OBJECTS_H
#include <stdint.h>
/** @file
*
* @brief Handling of ThingSet data objects
*/
#include <stdbool.h>
#include <stdint.h>
#include "thingset.h"
#include "pcb.h"
#include "structs.h"
#include "load.h"
void data_objects_update_conf();
void data_objects_read_eeprom();
extern log_data_t log_data;
extern battery_t bat;
extern dcdc_t dcdc;
extern load_output_t load;
extern dcdc_port_t hs_port;
extern dcdc_port_t ls_port;
extern battery_user_settings_t bat_user;
extern const dcdc_control_mode dcdc_mode; // we leave it fixed for the runtime for now
extern const data_object_t dataObjects[];
extern const size_t dataObjectsCount;
// stores object-ids of values to be stored in EEPROM
static const uint16_t eeprom_data_objects[] = {
0x4002, 0x4004, 0x4006, 0x4008, 0x400B, // V, I, T max
0x400F, 0x4010, // energy throughput
0x4011, 0x4012, // num full charge / deep-discharge
0x3001, 0x3002 // switch targets
};
/*
// stores object-ids of values to be published via GSM
static uint16_t pub_gsm_data_objects[] = {
0x1003, // deviceID
//0x2013, // time
0x4002, 0x4004, 0x4006, 0x4008, 0x400B, // V, I, T max
0x400C, // loadEn
0x400F, 0x4010, // total energy throughput
0x4011, 0x4012, // nFullChg, nDeepDis
0x4013 // SOC
};
// stores object-ids of values to be published via LoRa
static uint16_t pub_lora_data_objects[] = {
0x1003, // deviceID
0x4002, 0x4004, 0x4006, 0x4008, 0x400B, // V, I, T max
0x400C, // loadEn
0x400F, 0x4010, // total energy throughput
0x4011, 0x4012, // nFullChg, nDeepDis
0x4013 // SOC
};
*/
#endif
#endif /* DATA_OBJECTS_H */
+34 -29
View File
@@ -1,5 +1,5 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,32 +14,33 @@
* limitations under the License.
*/
#ifndef __DCDC_H_
#define __DCDC_H_
#ifndef DCDC_H
#define DCDC_H
/** @file
*
* @brief DC/DC buck/boost control functions
*/
#include <stdbool.h>
#include "battery.h"
#include "power_port.h"
#ifdef __cplusplus
extern "C" {
#endif
/* DC/DC basic operation mode
/** DC/DC basic operation mode
*
* Defines which type of device is connected to the high side and low side ports
*/
enum dcdc_control_mode
{
MODE_MPPT_BUCK, // solar panel at high side port, battery / load at low side port (typical MPPT)
MODE_MPPT_BOOST, // battery at high side port, solar panel at low side (e.g. e-bike charging)
MODE_NANOGRID // accept input power (if available and need for charging) or provide output power
// (if no other power source on the grid and battery charged) on the high side port
// and dis/charge battery on the low side port, battery voltage must be lower than
// nano grid voltage.
MODE_MPPT_BUCK, ///< solar panel at high side port, battery / load at low side port (typical MPPT)
MODE_MPPT_BOOST, ///< battery at high side port, solar panel at low side (e.g. e-bike charging)
MODE_NANOGRID ///< accept input power (if available and need for charging) or provide output power
///< (if no other power source on the grid and battery charged) on the high side port
///< and dis/charge battery on the low side port, battery voltage must be lower than
///< nano grid voltage.
};
/* DC/DC type
/** DC/DC type
*
* Contains all data belonging to the DC/DC sub-component of the PCB, incl.
* actual measurements and calibration parameters.
@@ -48,37 +49,41 @@ typedef struct {
dcdc_control_mode mode;
// actual measurements
float ls_current; // inductor current
float ls_current; ///< Low-side (inductor) current
float temp_mosfets;
// current state
float power; // power at low-side (calculated by dcdc controller)
int pwm_delta; // direction of PWM change for MPPT
int off_timestamp; // time when DC/DC was switched off last time
float power; ///< Power at low-side (calculated by dcdc controller)
int pwm_delta; ///< Direction of PWM change for MPPT
int off_timestamp; ///< Time when DC/DC was switched off last time
// maximum allowed values
float ls_current_max; // PCB inductor maximum
float ls_current_min; // --> if lower, charger is switched off
float ls_current_max; ///< Maximum low-side (inductor) current
float ls_current_min; ///< Minimum low-side current (if lower, charger is switched off)
float hs_voltage_max;
float ls_voltage_max;
// calibration parameters
//float offset_voltage_start; // V charging switched on if Vsolar > Vbat + offset
//float offset_voltage_stop; // V charging switched off if Vsolar < Vbat + offset
int restart_interval; // s --> when should we retry to start charging after low solar power cut-off?
int restart_interval; ///< Restart interval (s): When should we retry to start charging after low solar power cut-off?
} dcdc_t;
/* Initialize DC/DC and DC/DC port structs
/** Initialize DC/DC and DC/DC port structs
*
* See http://libre.solar/docs/dcdc_control for detailed information
*
* @param dcdc DC/DC type description
*/
void dcdc_init(dcdc_t *dcdc);
/** Main control function for the DC/DC converter
*
* @param dcdc DC/DC type description
* @param high_side High-side power port (e.g. solar input for typical MPPT charge controller application)
* @param low_side Low-side power port (e.g. battery output for typical MPPT charge controller application)
*/
void dcdc_control(dcdc_t *dcdc, power_port_t *high_side, power_port_t *low_side);
#ifdef __cplusplus
}
#endif
#endif // DCDC_H
#endif /* DCDC_H */
-23
View File
@@ -1,23 +0,0 @@
#ifndef DISPLAY_H
#define DISPLAY_H
const unsigned char bmp_load [] = {
0x20, 0x22, 0x04, 0x70, 0x88, 0x8B, 0x88, 0x70, 0x04, 0x22, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char bmp_arrow_right [] = {
0x41, 0x63, 0x36, 0x1C
};
const unsigned char bmp_pv_panel [] = {
0x60, 0x98, 0x86, 0xC9, 0x31, 0x19, 0x96, 0x62, 0x32, 0x2C, 0xC4, 0x64, 0x98, 0x08, 0xC8, 0x30,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00
};
const unsigned char bmp_disconnected [] = {
0x08, 0x08, 0x08, 0x08, 0x00, 0x41, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x41, 0x00, 0x08, 0x08,
0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#endif // DISPLAY_H
+43 -5
View File
@@ -1,13 +1,51 @@
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef EEPROM_H
#define EEPROM_H
/** @file
*
* @brief Handling of internal or external EEPROM to store device configuration
*/
#include "mbed.h"
void eeprom_init(int address);
/** Write data to EEPROM address
*
* @returns 0 for success
*/
int eeprom_write(unsigned int addr, uint8_t* data, int len);
// return values: 0 for success
int eeprom_write (unsigned int, char *, int);
int eeprom_read (unsigned int, char *, int);
/** Read data from EEPROM address
*
* @returns 0 for success
*/
int eeprom_read(unsigned int addr, uint8_t* ret, int len);
/** Store current charge controller data to EEPROM
*/
void eeprom_store_data();
/** Restore charge controller data from EEPROM and write to variables in RAM
*/
void eeprom_restore_data();
void eeprom_update();
/** Stores data to EEPROM every 6 hours (can be called regularly)
*/
void eeprom_update();
#endif /* EEPROM_H */
-501
View File
@@ -1,501 +0,0 @@
// CREDITS TO MIKE RANKIN
// ADAPTED DANBICKS
const char myFont[][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};
const char WIFI1[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF8,
0xF8, 0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFE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x0F, 0x1F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const char locked[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
0x3F, 0x1F, 0x1F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x1F, 0x1F, 0x3F,
0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0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00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const char rfwaves[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xC0,
0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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0F, 0x1F,
0x1F, 0x3F, 0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x07, 0x0F, 0x0F, 0x1F, 0x1F, 0x3F,
0x3F, 0x1F, 0x1F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x1F, 0x1F, 0x1F,
0x3F, 0x3F, 0x1F, 0x1F, 0x0F, 0x0F, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x06, 0x0E, 0x0E, 0x0E, 0x1E, 0x1E, 0x3F,
0x3F, 0x3E, 0x1E, 0x1E, 0x0E, 0x0E, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/* Standard ASCII 6x8 font
const char PROGMEM font6x8[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
};
*/
/* Standard ASCII 8x16 font */
const char font8X16[] ={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};
+20 -18
View File
@@ -1,5 +1,5 @@
/* mbed library for half bridge driver PWM generation
* Copyright (c) 2016-2017 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,22 +14,27 @@
* limitations under the License.
*/
#ifndef __HALF_BRIDGE_H_
#define __HALF_BRIDGE_H_
#ifndef HALF_BRIDGE_H
#define HALF_BRIDGE_H
/** @file
*
* @brief PWM timer functions for half bridge of DC/DC converter
*/
/** Initiatializes the registers to generate the PWM signal and sets duty
* cycle limits
*
* @param freq Switching frequency in kHz
* @param deadtime Deadtime in ns between switching the two FETs on/off
* @param min_duty Minimum duty cycle (e.g. 0.5 for limiting input voltage)
* @param max_duty Maximum duty cycle (e.g. 0.97 for charge pump)
* @param freq_kHz Switching frequency in kHz
* @param deadtime_ns Deadtime in ns between switching the two FETs on/off
* @param min_duty Minimum duty cycle (e.g. 0.5 for limiting input voltage)
* @param max_duty Maximum duty cycle (e.g. 0.97 for charge pump)
*/
void half_bridge_init(int freq_kHz, int deadtime_ns, float min_duty, float max_duty);
/** Start the PWM generation
*
* @param pwm_duty Duty cycle between 0.0 and 1.0
* @param pwm_duty Duty cycle between 0.0 and 1.0
*/
void half_bridge_start(float pwm_duty);
@@ -39,29 +44,26 @@ void half_bridge_stop();
/** Get status of the PWM output
*
* @returns
* True if PWM output enabled
* @returns True if PWM output enabled
*/
bool half_bridge_enabled();
/** Set the duty cycle of the PWM signal between 0.0 and 1.0
/** Set the duty cycle of the PWM signal
*
* @param duty Duty cycle between 0.0 and 1.0
* @param duty Duty cycle between 0.0 and 1.0
*/
void half_bridge_set_duty_cycle(float duty);
/** Adjust the duty cycle with minimum step size
*
* @param delta Number of steps (positive or negative)
* @param delta Number of steps (positive or negative)
*/
void half_bridge_duty_cycle_step(int delta);
/** Read the currently set duty cycle
*
* @returns
* Duty cycle between 0.0 and 1.0
* @returns Duty cycle between 0.0 and 1.0
*/
float half_bridge_get_duty_cycle();
#endif // HALFB_RIDGE_H
#endif /* HALF_BRIDGE_H */
+48 -4
View File
@@ -1,18 +1,62 @@
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HARDWARE_H
#define HARDWARE_H
#ifndef __HARDWARE_H_
#define __HARDWARE_H_
/** @file
*
* @brief
* Hardware-specific functions like timers, output switches, bootloader
*/
/** Initialize load and USB output control pins
*/
void init_load();
/** Enable/disable load switch
*/
void hw_load_switch(bool enabled);
/** Enable/disable USB output
*/
void hw_usb_out(bool enabled);
void init_watchdog(float timeout); // timeout in seconds
/** Initialization of IWDG
*
* @param timeout Timeout in seconds
*/
void init_watchdog(float timeout);
/** Feeds/kicks the watchdog
*/
void feed_the_dog();
/** Timer for system control (main DC/DC or PWM control loop) is started
*
* @param freq_Hz Frequency in Hz (10 Hz suggested)
*/
void control_timer_start(int freq_Hz);
void system_control(); // is implemented in main.cpp
/** DC/DC or PWM control loop (implemented in main.cpp)
*/
void system_control();
/** Reset device and go into USB DFU mode bootloader
*/
void start_dfu_bootloader();
#endif /* HARDWARE_H */
+34 -14
View File
@@ -1,5 +1,27 @@
#ifndef _INTERFACE_H_
#define _INTERFACE_H_
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INTERFACE_H
#define INTERFACE_H
/** @file
*
* @brief
* Communication interfaces connected to UEXT port
*/
#include "mbed.h"
#include <stdint.h>
@@ -8,24 +30,23 @@
#include "battery.h"
#include "load.h"
/* OLED display based on SSD1306 IC, connected to UEXT port via I2C
/** OLED display based on SSD1306 IC, connected to UEXT port via I2C
*/
void oled_output(dcdc_t *dcdc, power_port_t *solar_port, power_port_t *bat_port, battery_t *bat, load_output_t *load);
void oled_output(dcdc_t *dcdc, power_port_t *solar_port, power_port_t *bat_port, battery_state_t *bat, load_output_t *load);
/* UART serial interface (either in UEXT connector or from additional SWD serial)
/** UART serial interface (either in UEXT connector or from additional SWD serial)
*/
void uart_serial_init(Serial* s);
void uart_serial_process();
void uart_serial_pub();
void output_serial(dcdc_t *dcdc, battery_t *bat, load_output_t *load);
/* Serial interface via USB CDC device class (currently only supported with STM32F0)
/** Serial interface via USB CDC device class (currently only supported with STM32F0)
*/
void usb_serial_init();
void usb_serial_process();
void usb_serial_pub();
/* CAN bus interface
/** CAN bus interface
*/
void can_send_data();
void can_receive();
@@ -33,26 +54,25 @@ void can_process_outbox();
void can_process_inbox();
void can_send_object_name(int obj_id, uint8_t can_dest_id);
/* GSM mobile interface via UEXT connector serial interface
/** GSM mobile interface via UEXT connector serial interface
*/
void gsm_init();
void gsm_process();
/* LoRa interface via UEXT connector SPI interface
/** LoRa interface via UEXT connector SPI interface
*/
void lora_init();
void lora_process();
/* GSM mobile interface via UEXT connector serial interface
/** GSM mobile interface via UEXT connector serial interface
*/
void wifi_init();
void wifi_process();
/* SD card connected to UEXT connector (e.g. via Olimex adapter)
/** SD card connected to UEXT connector (e.g. via Olimex adapter)
*
* The new mbed implementation of SD cards require RTOS --> currently not supported
*/
void output_sdcard();
#endif /* _INTERFACE_H_ */
#endif /* INTERFACE_H */
+3 -3
View File
@@ -49,7 +49,7 @@ const unsigned char bmp_disconnected [] = {
I2C i2c(PIN_UEXT_SDA, PIN_UEXT_SCL);
Adafruit_SSD1306_I2c oled(i2c, PIN_UEXT_SSEL, 0x78, 64, 128);
void oled_output(dcdc_t *dcdc, power_port_t *solar_port, power_port_t *bat_port, battery_t *bat, load_output_t *load)
void oled_output(dcdc_t *dcdc, power_port_t *solar_port, power_port_t *bat_port, battery_state_t *bat, load_output_t *load)
{
float tmp;
@@ -90,10 +90,10 @@ void oled_output(dcdc_t *dcdc, power_port_t *solar_port, power_port_t *bat_port
oled.setTextCursor(8, 18);
oled.printf("n/a");
}
if (solar_port->voltage > bat_port->voltage) {
//if (solar_port->voltage > bat_port->voltage) {
oled.setTextCursor(0, 26);
oled.printf("%4.1fV", solar_port->voltage);
}
//}
// battey data
tmp = bat_port->voltage * (bat_port->current - load->current);
+4 -4
View File
@@ -28,7 +28,7 @@ extern log_data_t log_data;
extern power_port_t hs_port;
extern power_port_t ls_port;
extern load_output_t load;
extern battery_t bat;
extern battery_state_t bat_state;
extern dcdc_t dcdc;
extern uint32_t deviceID;
@@ -114,8 +114,8 @@ int wifi_send_emoncms_data()
"dcdcEn:%d,loadEn:%d,chgState:%d,tempInt:%.1f,nFullChg:%d,nDeepDis:%d,"
"eInputDay_Wh:%.2f,eOutputDay_Wh:%.2f,SOC:%d,day:%d,SOH:%d,qDis_Ah:%.3f,qBatUse_Ah:%.2f}",
EMONCMS_NODE, hs_port.voltage, ls_port.voltage, ls_port.current, load.current,
half_bridge_enabled(), load.enabled, bat.state, dcdc.temp_mosfets, bat.num_full_charges, bat.num_deep_discharges,
bat.input_Wh_day, bat.output_Wh_day, bat.soc, log_data.day_counter, bat.soh, bat.discharged_Ah, bat.useable_capacity);
half_bridge_enabled(), load.enabled, bat_state.chg_state, dcdc.temp_mosfets, bat_state.num_full_charges, bat_state.num_deep_discharges,
bat_state.input_Wh_day, bat_state.output_Wh_day, bat_state.soc, log_data.day_counter, bat_state.soh, bat_state.discharged_Ah, bat_state.useable_capacity);
strcat(url, "&apikey=" EMONCMS_APIKEY);
//printf("%s\n", url);
@@ -191,7 +191,7 @@ void wifi_process()
break;
case STATE_INTERNET_CONN:
if (wifi_check_internet_connected()) {
#if EMONCMS_ENABLED == true
#ifdef EMONCMS_ENABLED
wifi_send_emoncms_data();
#endif
}
+23 -3
View File
@@ -1,7 +1,27 @@
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LEDS_H
#define LEDS_H
#ifndef __LEDS_H__
#define __LEDS_H__
/** @file
*
* @brief
* Control of status LEDs with charlieplexing
*/
void leds_init();
void led_timer_start(int freq_Hz);
@@ -14,4 +34,4 @@ void trigger_rx_led();
void update_soc_led(int soc);
void toggle_led_blink();
#endif /* __LEDS_H__ */
#endif /* LEDS_H */
+26 -21
View File
@@ -1,5 +1,5 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,41 +14,46 @@
* limitations under the License.
*/
#ifndef __LOAD_H_
#define __LOAD_H_
#ifndef LOAD_H
#define LOAD_H
/** @file
*
* @brief
* Load output functions and data types
*/
#include <stdbool.h>
enum load_state_t {
LOAD_STATE_DISABLED = 0, // Load actively disabled
LOAD_STATE_ON, // Normal state: Load on
LOAD_STATE_OFF_LOW_SOC, // Load off to protect battery (overrules remote setting)
LOAD_STATE_OFF_OVERCURRENT // Load off to protect charge controller (overrules remote setting)
LOAD_STATE_DISABLED = 0, ///< Load actively disabled
LOAD_STATE_ON, ///< Normal state: Load on
LOAD_STATE_OFF_LOW_SOC, ///< Load off to protect battery (overrules remote setting)
LOAD_STATE_OFF_OVERCURRENT ///< Load off to protect charge controller (overrules remote setting)
};
enum usb_state_t {
USB_STATE_DISABLED = 0, // USB port actively disabled
USB_STATE_ON, // Normal state: USB on
USB_STATE_OFF_LOW_SOC, // USB off to protect battery (overrules target setting)
USB_STATE_OFF_OVERCURRENT // USB off to protect charge controller (overrules target setting)
USB_STATE_DISABLED = 0, ///< USB port actively disabled
USB_STATE_ON, ///< Normal state: USB on
USB_STATE_OFF_LOW_SOC, ///< USB off to protect battery (overrules target setting)
USB_STATE_OFF_OVERCURRENT ///< USB off to protect charge controller (overrules target setting)
};
/* Load Output type
/** Load Output type
*
* Stores status of load output incl. 5V USB output (if existing on PCB)
*/
typedef struct {
load_state_t state;
usb_state_t usb_state;
float current; // actual measurement
float current_max; // maximum allowed current
int overcurrent_timestamp; // time at which an overcurrent event occured
bool enabled; // actual status
bool enabled_target; // target setting defined via communication
// port (overruled if battery is empty)
bool usb_enabled_target; // same for USB output
float current; ///< actual measurement
float current_max; ///< maximum allowed current
int overcurrent_timestamp; ///< time at which an overcurrent event occured
bool enabled; ///< actual status
bool enabled_target; ///< target setting defined via communication port (overruled if battery is empty)
bool usb_enabled_target; ///< same for USB output
} load_output_t;
void load_init(load_output_t *load);
@@ -57,4 +62,4 @@ void load_state_machine(load_output_t *load, bool source_enabled);
void load_check_overcurrent(load_output_t *load);
#endif /* __LOAD_H_ */
#endif /* LOAD_H */
+25 -14
View File
@@ -1,16 +1,32 @@
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __LOG_H_
#define __LOG_H_
#ifndef LOG_H
#define LOG_H
/** @file
*
* @brief
* Structs needed for data logging (like max/min values, etc.)
*/
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Log Data
/** Log Data
*
* Saves maximum ever measured values to EEPROM
*/
@@ -25,9 +41,4 @@ typedef struct {
int day_counter;
} log_data_t;
#ifdef __cplusplus
}
#endif
#endif // __LOG_H_
#endif /* LOG_H */
+20 -15
View File
@@ -34,6 +34,7 @@
#include "load.h" // load and USB output management
#include "leds.h"
#include "log.h"
#include "data_objects.h"
//----------------------------------------------------------------------------
// global variables
@@ -47,8 +48,9 @@ power_port_t hs_port = {}; // high-side (solar for typical MPPT)
power_port_t ls_port = {}; // low-side (battery for typical MPPT)
power_port_t *bat_port = NULL;
pwm_chg_t pwm_chg = {}; // only for PWM charger
battery_t bat;
battery_user_settings_t bat_user;
battery_conf_t bat_conf; // actual (used) battery configuration
battery_conf_t bat_conf_user; // temporary storage where the user can write to
battery_state_t bat_state; // battery state information
load_output_t load;
log_data_t log_data;
extern ThingSet ts; // defined in data_objects.cpp
@@ -72,7 +74,7 @@ void system_control() // called by control timer (see hardware.cpp)
static int counter = 0;
// convert ADC readings to meaningful measurement values
update_measurements(&dcdc, &bat, &load, &hs_port, &ls_port);
update_measurements(&dcdc, &bat_state, &load, &hs_port, &ls_port);
// control PWM of the DC/DC according to hs and ls port settings
// (this function includes MPPT algorithm)
@@ -87,7 +89,7 @@ void system_control() // called by control timer (see hardware.cpp)
// see also here: https://github.com/ARMmbed/mbed-os/issues/9065
timestamp++;
counter = 0;
battery_update_energy(&bat, bat_port->voltage, bat_port->current); // must be called once per second
battery_update_energy(&bat_conf, &bat_state, bat_port->voltage, bat_port->current); // must be called once per second
}
}
@@ -104,17 +106,17 @@ int main()
{
case MODE_NANOGRID:
power_port_init_nanogrid(&hs_port);
power_port_init_bat(&ls_port, &bat);
power_port_init_bat(&ls_port, &bat_conf);
bat_port = &ls_port;
break;
case MODE_MPPT_BUCK: // typical MPPT charge controller operation
power_port_init_solar(&hs_port);
power_port_init_bat(&ls_port, &bat);
power_port_init_bat(&ls_port, &bat_conf);
bat_port = &ls_port;
break;
case MODE_MPPT_BOOST: // for charging of e-bike battery via solar panel
power_port_init_solar(&ls_port);
power_port_init_bat(&hs_port, &bat);
power_port_init_bat(&hs_port, &bat_conf);
bat_port = &hs_port;
break;
}
@@ -127,18 +129,18 @@ int main()
interfaces_process_asap();
update_soc_led(bat.soc);
update_soc_led(bat_state.soc);
time_t now = timestamp;
if (now >= last_call + 1 || now < last_call) { // called once per second (or slower if blocking wait occured somewhere)
//printf("Still alive... time: %d, mode: %d\n", (int)time(NULL), dcdc.mode);
charger_state_machine(bat_port, &bat, bat_port->voltage, bat_port->current);
charger_state_machine(bat_port, &bat_conf, &bat_state, bat_port->voltage, bat_port->current);
load_state_machine(&load, ls_port.input_allowed);
eeprom_update();
//eeprom_update();
interfaces_process_1s();
toggle_led_blink();
@@ -177,7 +179,7 @@ void interfaces_process_asap()
void interfaces_process_1s()
{
#ifdef OLED_ENABLED
oled_output(&dcdc, &hs_port, &ls_port, &bat, &load);
oled_output(&dcdc, &hs_port, &ls_port, &bat_state, &load);
#endif
#ifdef GSM_ENABLED
@@ -207,14 +209,17 @@ void setup()
leds_init();
led_timer_start(NUM_LEDS * 60); // 60 Hz
battery_init(&bat, &bat_user);
battery_conf_init(&bat_conf, BATTERY_TYPE, BATTERY_NUM_CELLS, BATTERY_CAPACITY);
battery_conf_overwrite(&bat_conf, &bat_conf_user); // initialize conf_user with same values
battery_state_init(&bat_state);
load_init(&load);
dcdc_init(&dcdc);
half_bridge_init(PWM_FREQUENCY, 300, 12 / dcdc.hs_voltage_max, 0.97); // lower duty limit might have to be adjusted dynamically depending on LS voltage
eeprom_restore_data();
ts.set_conf_callback(eeprom_store_data); // after each configuration change, data should be written back to EEPROM
data_objects_read_eeprom();
ts.set_conf_callback(data_objects_update_conf); // after each configuration change, data should be written back to EEPROM
adc_setup();
dma_setup();
@@ -223,7 +228,7 @@ void setup()
wait(0.5); // wait for ADC to collect some measurement values
update_measurements(&dcdc, &bat, &load, &hs_port, &ls_port);
update_measurements(&dcdc, &bat_state, &load, &hs_port, &ls_port);
calibrate_current_sensors(&dcdc, &load);
}
+5 -5
View File
@@ -16,17 +16,17 @@
#include "power_port.h"
void power_port_init_bat(power_port_t *port, battery_t *bat)
void power_port_init_bat(power_port_t *port, battery_conf_t *bat)
{
port->input_allowed = true; // discharging allowed
port->output_allowed = true; // charging allowed
port->voltage_input_start = bat->cell_voltage_load_reconnect * bat->num_cells;
port->voltage_input_stop = bat->cell_voltage_load_disconnect * bat->num_cells;
port->voltage_input_start = bat->voltage_load_reconnect;
port->voltage_input_stop = bat->voltage_load_disconnect;
port->current_input_max = -bat->charge_current_max; // TODO: discharge current
port->voltage_output_target = bat->cell_voltage_max * bat->num_cells;
port->voltage_output_min = bat->cell_voltage_absolute_min * bat->num_cells;
port->voltage_output_target = bat->voltage_max;
port->voltage_output_min = bat->voltage_absolute_min;
port->current_output_max = bat->charge_current_max;
}
+12 -15
View File
@@ -1,5 +1,5 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
/* LibreSolar charge controller firmware
* Copyright (c) 2016-2019 Martin Jäger (www.libre.solar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,17 +14,18 @@
* limitations under the License.
*/
#ifndef __POWER_PORT_H__
#define __POWER_PORT_H__
#ifndef POWER_PORT_H
#define POWER_PORT_H
/** @file
*
* @brief Definition of power ports of a DC/DC converter (high-side or low-side terminal)
*/
#include <stdbool.h>
#include "battery.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Power port type
/** Power port type
*
* Saves current target settings of either high-side or low-side port of a
* DC/DC converter. In this way, e.g. a battery can be configured to be
@@ -51,14 +52,10 @@ typedef struct {
bool input_allowed; // discharging direction for battery port
} power_port_t;
void power_port_init_bat(power_port_t *port, battery_t *bat);
void power_port_init_bat(power_port_t *port, battery_conf_t *bat);
void power_port_init_solar(power_port_t *port);
void power_port_init_nanogrid(power_port_t *port);
#ifdef __cplusplus
}
#endif
#endif // __POWER_PORT_H__
#endif /* POWER_PORT_H */