Updated state machine and some clean-up

This commit is contained in:
Martin Jäger
2017-04-07 23:22:22 +02:00
parent ba91e0b6c2
commit 0908ef3aba
19 changed files with 407 additions and 1728 deletions
+165
View File
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
+27
View File
@@ -0,0 +1,27 @@
# MPPT Charger Software
Software based on ARM mbed library for the LibreSolar 20 A MPPT solar charge controller
## State machine
The charge management is implemented using a state machine with the following states:
### Standby
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)
![Text](img/MPPT_flow_chart.png)
## DC/DC control class
The PWM signal generation for the DC/DC controller inside the charge controller is done by a separate class BuckConverter. Most of the dangerous functions which could blow up your MOSFETs are implemented here.
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+26 -5
View File
@@ -23,6 +23,7 @@ BuckConverter::BuckConverter(int freq_kHz)
last_time_CV_reset();
_pwm_delta = 1;
_enabled = false;
}
void BuckConverter::update(int input_voltage_mV, int output_voltage_mV, int output_current_mA) {
@@ -33,10 +34,22 @@ void BuckConverter::update(int input_voltage_mV, int output_voltage_mV, int outp
if (output_voltage_mV > _max_voltage_mV) {
// increase input voltage to lower output voltage
duty_cycle_step(-1);
_time_voltage_limit_reached = time(NULL);
if (output_current_mA > _min_current_mA) {
duty_cycle_step(-1);
_time_voltage_limit_reached = time(NULL);
}
else {
// switch off and wait for voltage to go down
// (otherwise current could get negative, i.e. into solar panel)
TIM1->BDTR &= ~(TIM_BDTR_MOE);
}
//printf("output_voltage_mV = %d, _max_voltage_mV = %d\n", output_voltage_mV, _max_voltage_mV);
fflush(stdout);
//fflush(stdout);
}
else if (~(TIM1->BDTR & TIM_BDTR_MOE) && _enabled == true) {
// switched off because of too high output voltage?
// now: output_voltage_mV <= _max_voltage_mV --> start again
start((float) output_voltage_mV / (input_voltage_mV - 1000.0));
}
else if (output_current_mA > _max_current_mA) {
// increase input voltage to decrease current
@@ -99,14 +112,18 @@ void BuckConverter::init_registers() {
TIM1->EGR |= TIM_EGR_UG;
}
void BuckConverter::set_voltage_limit(int voltage_mV) {
void BuckConverter::set_max_voltage(int voltage_mV) {
_max_voltage_mV = voltage_mV;
}
void BuckConverter::set_current_limit(int current_mA) {
void BuckConverter::set_max_current(int current_mA) {
_max_current_mA = current_mA;
}
void BuckConverter::set_min_current(int current_mA) {
_min_current_mA = current_mA;
}
time_t BuckConverter::last_time_CV() {
return _time_voltage_limit_reached;
}
@@ -183,6 +200,8 @@ void BuckConverter::start(float pwm_duty) {
// Break and Dead-Time Register
// MOE = 1: Main output enable
TIM1->BDTR |= TIM_BDTR_MOE;
_enabled = true;
}
@@ -191,6 +210,8 @@ void BuckConverter::stop() {
// Break and Dead-Time Register
// MOE = 1: Main output enable
TIM1->BDTR &= ~(TIM_BDTR_MOE);
_enabled = false;
}
+6 -2
View File
@@ -24,8 +24,9 @@ public:
*/
BuckConverter(int freq_kHz);
void set_voltage_limit(int voltage_mV);
void set_current_limit(int current_mA);
void set_max_voltage(int voltage_mV);
void set_max_current(int current_mA);
void set_min_current(int current_mA);
time_t last_time_CV ();
void last_time_CV_reset();
@@ -101,8 +102,11 @@ private:
float _max_duty;
int _pwm_delta;
bool _enabled;
int _max_voltage_mV;
int _max_current_mA;
int _min_current_mA;
int _output_power_prev_mW;
time_t _time_voltage_limit_reached;
};
-319
View File
@@ -1,319 +0,0 @@
/* mbed Library for EA DOG display
*
* This library is partly based on mbed DogLCD class by Igor Skochinsky and
* the official Electronic Assembly library for Arduino
*/
#include "DogLCD.h"
// macro to make sure x falls into range from low to high (inclusive)
#define CLAMP(x, low, high) { if ( (x) < (low) ) x = (low); if ( (x) > (high) ) x = (high); } while (0);
void DogLCD::_send_commands(const unsigned char* buf, size_t size)
{
// for commands, A0 is low
#ifdef READJUST_SPI_FREQUENCY
_spi.format(8,0);
_spi.frequency(10000000);
#endif
_cs = 0;
_a0 = 0;
while ( size-- > 0 )
_spi.write(*buf++);
_cs = 1;
}
void DogLCD::_send_data(const unsigned char* buf, size_t size)
{
// for data, A0 is high
#ifdef READJUST_SPI_FREQUENCY
_spi.format(8,0);
_spi.frequency(10000000);
#endif
_cs = 0;
_a0 = 1;
while ( size-- > 0 )
_spi.write(*buf++);
_cs = 1;
_a0 = 0;
}
// set column and page number
// void dog_1701::position(byte column, byte page)
void DogLCD::_set_xy(int x, int y)
{
int column = x;
int page = y;
if (_view == VIEW_TOP)
column += 30;
unsigned char cmd[3];
cmd[0] = 0x10 + (column>>4); //MSB adress column
cmd[1] = 0x00 + (column&0x0F); //LSB adress column
cmd[2] = 0xB0 + (page&0x0F); //adress page
/*
//printf("_set_xy(%d,%d)\n", x, y);
CLAMP(x, 0, LCDWIDTH-1);
CLAMP(y, 0, LCDPAGES-1);
unsigned char cmd[3];
cmd[0] = 0xB0 | (y & 0xF);
cmd[1] = (x & 0xF);
cmd[2] = 0x10 | ((x >> 4) & 0xF);
*/
_send_commands(cmd, 3);
}
// initialize and turn on the display
void DogLCD::init()
{
const unsigned char init_seq[] = {
0x40, //Display start line 0
0xa1, //ADC reverse
0xc0, //Normal COM0...COM63
0xa6, //Display normal
0xa2, //Set Bias 1/9 (Duty 1/65)
0x2f, //Booster, Regulator and Follower On
0xf8, //Set internal Booster to 4x
0x00,
0x27, //Contrast set
0x81,
0x09,
0xac, //No indicator
0x00,
0xaf, //Display on
};
#ifndef READJUST_SPI_FREQUENCY
_spi.format(8,0);
_spi.frequency(10000000);
#endif
//printf("Reset=L\n");
_reset = 0;
_cs = 1;
wait_ms(1);
//printf("Reset=H\n");
_reset = 1;
wait_ms(5);
//printf("Sending init commands\n");
_send_commands(init_seq, sizeof(init_seq));
}
/*----------------------------
Func: string
Desc: shows string with selected font on position
Vars: column (0..127/131), page(0..3/7), font adress in programm memory, stringarray
------------------------------*/
void DogLCD::string(int column, int page, const char *font_adress, const char *str)
{
unsigned int pos_array; //Postion of character data in memory array
int x, y, column_cnt, width_max; //temporary column and page adress, couloumn_cnt tand width_max are used to stay inside display area
int start_code, last_code, width, page_height, bytes_p_char; //font information, needed for calculation
const char *string;
start_code = font_adress[2]; //get first defined character
last_code = font_adress[3]; //get last defined character
width = font_adress[4]; //width in pixel of one char
page_height = font_adress[6]; //page count per char
bytes_p_char = font_adress[7]; //bytes per char
if(page_height + page > 8) //stay inside display area
page_height = 8 - page;
//The string is displayed character after character. If the font has more then one page,
//the top page is printed first, then the next page and so on
for(y = 0; y < page_height; y++)
{
_set_xy(column, page+y); //set startpositon and page
column_cnt = column; //store column for display last column check
string = str; //temporary pointer to the beginning of the string to print
_cs = 0;
_a0 = 1;
while(*string != 0)
{
if((int)*string < start_code || (int)*string > last_code) //make sure data is valid
string++;
else
{
//calculate positon of ascii character in font array
//bytes for header + (ascii - startcode) * bytes per char)
pos_array = 8 + (unsigned int)(*string++ - start_code) * bytes_p_char;
pos_array += y*width; //get the dot pattern for the part of the char to print
if(column_cnt + width > 102) //stay inside display area
width_max = 102-column_cnt;
else
width_max = width;
for(x=0; x < width_max; x++) //print the whole string
{
_spi.write(font_adress[pos_array+x]);
//spi_out(pgm_read_byte(&font_adress[pos_array+x])); //double width font (bold)
}
column_cnt += width;
}
}
_cs = 1;
_a0 = 0;
}
}
/*----------------------------
Func: view
Desc: ssets the display viewing direction
Vars: direction (top view 0xC8, bottom view (default) = 0xC0)
------------------------------*/
void DogLCD::view(unsigned int direction)
{
unsigned char cmd[2];
if(direction == VIEW_TOP)
{
cmd[0] = 0xA0;
_view = VIEW_TOP;
}
else
{
cmd[0] = 0xA1;
_view = VIEW_BOTTOM;
}
cmd[1] = direction;
_send_commands(cmd, 2);
clear_screen(); //Clear screen, as old content is not usable (mirrored)
}
void DogLCD::send_pic(const unsigned char* data)
{
//printf("Sending picture\n");
for (int i=0; i<LCDPAGES; i++)
{
_set_xy(0, i);
_send_data(data + i*LCDWIDTH, LCDWIDTH);
}
}
void DogLCD::clear_screen()
{
//printf("Clear screen\n");
memset(_framebuffer, 0, sizeof(_framebuffer));
if ( _updating == 0 )
{
send_pic(_framebuffer);
}
}
void DogLCD::all_on(bool on)
{
//printf("Sending all on %d\n", on);
unsigned char cmd = 0xA4 | (on ? 1 : 0);
_send_commands(&cmd, 1);
}
void DogLCD::pixel(int x, int y, int colour)
{
CLAMP(x, 0, LCDWIDTH-1);
CLAMP(y, 0, LCDHEIGHT-1);
int page = y / 8;
unsigned char mask = 1<<(y%8);
unsigned char *byte = &_framebuffer[page*LCDWIDTH + x];
if ( colour == 0 )
*byte &= ~mask; // clear pixel
else
*byte |= mask; // set pixel
if ( !_updating )
{
_set_xy(x, page);
_send_data(byte, 1);
}
}
void DogLCD::fill(int x, int y, int width, int height, int colour)
{
/*
If we need to fill partial pages at the top:
......+---+---+.....
^ | = | = | = : don't touch
| | = | = | * : update
y%8 | = | = |
| | = | = |
v | = | = |
y----> | * | * |
| * | * |
| * | * |
+---+---+
*/
//printf("fill(x=%d, y=%d, width=%d, height=%d, colour=%x)\n", x, y, width, height, colour);
CLAMP(x, 0, LCDWIDTH-1);
CLAMP(y, 0, LCDHEIGHT-1);
CLAMP(width, 0, LCDWIDTH - x);
CLAMP(height, 0, LCDHEIGHT - y);
int page = y/8;
int firstpage = page;
int partpage = y%8;
if ( partpage != 0 )
{
// we need to process partial bytes in the top page
unsigned char mask = (1<<partpage) - 1; // this mask has 1s for bits we need to leave
unsigned char *bytes = &_framebuffer[page*LCDWIDTH + x];
for ( int i = 0; i < width; i++, bytes++ )
{
// clear "our" bits
*bytes &= mask;
if ( colour != 0 )
*bytes |= ~mask; // set our bits
}
height -= partpage;
page++;
}
while ( height >= 8 )
{
memset(&_framebuffer[page*LCDWIDTH + x], colour == 0 ? 0 : 0xFF, width);
page++;
height -= 8;
}
if ( height != 0 )
{
// we need to process partial bytes in the bottom page
unsigned char mask = ~((1<<partpage) - 1); // this mask has 1s for bits we need to leave
unsigned char *bytes = &_framebuffer[page*LCDWIDTH + x];
for ( int i = 0; i < width; i++, bytes++ )
{
// clear "our" bits
*bytes &= mask;
if ( colour != 0 )
*bytes |= ~mask; // set our bits
}
page++;
}
//printf("_updating=%d\n", _updating);
if ( !_updating )
{
int laststpage = page;
for ( page = firstpage; page < laststpage; page++)
{
//printf("setting x=%d, page=%d\n", x, page);
_set_xy(x, page);
//printf("sending %d bytes at offset %x\n", width, page*LCDWIDTH + x);
_send_data(&_framebuffer[page*LCDWIDTH + x], width);
}
}
}
void DogLCD::beginupdate()
{
_updating++;
//printf("beginupdate: %d\n", _updating);
}
void DogLCD::endupdate()
{
_updating--;
//printf("endupdate: %d\n", _updating);
if ( _updating == 0 )
{
send_pic(_framebuffer);
}
}
-94
View File
@@ -1,94 +0,0 @@
/* mbed Library for EA DOG display
*
* This library is partly based on mbed DogLCD class by Igor Skochinsky and
* the official Electronic Assembly library for Arduino
*/
#ifndef __DOGLCD_H__
#define __DOGLCD_H__
#include "mbed.h"
/***********
* Module for Electronic Assembly's DOGL128-6 display module
* Should be compatible with other modules using ST7565 controller
***********/
#define LCDWIDTH 102
#define LCDHEIGHT 64
#define LCDPAGES (LCDHEIGHT+7)/8
#define VIEW_BOTTOM 0xC0
#define VIEW_TOP 0xC8
/*
Each page is 8 lines, one byte per column
Col0
+---+--
| 0 |
Page 0 | 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
+---+--
*/
/*
LCD interface class.
Usage:
DogLCD dog(spi, pin_power, pin_cs, pin_a0, pin_reset);
where spi is an instance of SPI class
*/
class DogLCD
{
public:
DogLCD(SPI& spi, PinName cs, PinName a0, PinName reset):
_spi(spi), _cs(cs), _a0(a0), _reset(reset), _updating(0)
{ }
void clear (void);
void contrast (int contr);
void view (unsigned int direction);
void string (int column, int page, const char *font_adress, const char *str);
void rectangle (int start_column, int start_page, int end_column, int end_page, int pattern);
void picture (int column, int page, const int *pic_adress);
// initialize and turn on the display
void init();
// send a 128x64 picture for the whole screen
void send_pic(const unsigned char* data);
// clear screen
void clear_screen();
// turn all pixels on
void all_on(bool on = true);
virtual int width() {return LCDWIDTH;};
virtual int height() {return LCDHEIGHT;};
virtual void pixel(int x, int y, int colour);
virtual void fill(int x, int y, int width, int height, int colour);
virtual void beginupdate();
virtual void endupdate();
private:
SPI& _spi;
DigitalOut _cs, _a0, _reset;
int _view;
int _updating;
void _send_commands(const unsigned char* buf, size_t size);
void _send_data(const unsigned char* buf, size_t size);
void _set_xy(int x, int y);
unsigned char _framebuffer[LCDWIDTH*LCDPAGES];
};
#endif //__DOGLCD_H__
-92
View File
@@ -1,92 +0,0 @@
/* File '16X32_numbers.FV' as include
The font was generated with EA FontEditor. Please contact ELECTRONIC ASSEMBLY
for more details (techik@lcd-module.de)
File based on official EA Arduino library.
the array starts with a 8 byte header:
1st Byte: 'F' first 2 bytes are always FV
2nd Byte: 'V' for FONT VERTICAL
3rd Byte: First code to define
4th Byte: Last code to define
5th Byte: Width of character in dots
6th Byte: Height of character in dots
7th Byte: Height of character in bytes
8th Byte: Bytes needed for each character (1..255)
or 0 for big fonts calculate WidthInDots * HeightInBytes
After that font data will follow */
#define FONT_16X32NUMS_LEN 1096
const char font_16x32nums[FONT_16X32NUMS_LEN] =
{
70, 86, 42, 58, 16, 32, 4, 64,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 6, 14, 28, 56,112,224,192,224,112, 56, 28, 14, 6, 0,
0, 0, 48, 56, 28, 14, 7, 3, 1, 3, 7, 14, 28, 56, 48, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,192,192,192,192,192,255,255,255,192,192,192,192,192, 0,
0, 0, 1, 1, 1, 1, 1,127,127,127, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,254,254,126, 30, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,192,192,192,192,192,192,192,192,192,192,192,192,192, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 28, 62, 62, 28, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,128,128, 0, 0, 0, 0, 0, 0, 0,
0, 0,192,192,192,192,195,199,199,195,192,192,192,192,192, 0,
0, 0, 1, 1, 1, 1, 97,241,241, 97, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,224,248,252,252, 62, 30, 30, 30, 62,252,252,248,224, 0, 0,
0,255,255,255,255, 0, 0,192,240, 60,255,255,255,255, 0, 0,
0,255,255,255,255, 60, 15, 3, 0, 0,255,255,255,255, 0, 0,
0, 7, 31, 63, 63,124,120,120,120,124, 63, 63, 31, 7, 0, 0,
0, 0,128,192,224,240,248,252,254,254,254,252, 0, 0, 0, 0,
0, 3, 7, 7, 7, 3, 1,255,255,255,255,255, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,255,255,255,255,255, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 63,127,127,127, 63, 0, 0, 0, 0,
0,112,248,252,124, 62, 30, 30, 30, 62,252,252,248,224, 0, 0,
0, 0, 0, 0, 0, 0, 0,128,192,240,255,255,255, 63, 0, 0,
0,128,224,248,252,254,255, 63, 15, 7, 3, 1, 0, 0, 0, 0,
0, 63,127,127,127,127,120,120,120,120,120,120,120, 48, 0, 0,
0, 48,120,124, 60, 30, 30, 30, 62,252,252,248,240,192, 0, 0,
0, 0, 0,128,192,192,192,192,224,255,255,255,127, 31, 0, 0,
0, 0, 0, 1, 3, 3, 3, 3, 7,255,255,255,254,248, 0, 0,
0, 12, 30, 62, 60,120,120,120,124, 63, 63, 31, 15, 3, 0, 0,
0, 0, 0, 0, 0, 0, 0,192,240,252,254,254,254, 0, 0, 0,
0, 0, 0,192,240,252,255, 63, 15,255,255,255,255, 0, 0, 0,
0,252,255,255,255,195,192,192,192,255,255,255,255,192, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1,127,127,127,127, 1, 0, 0,
0,252,254,254,254, 30, 30, 30, 30, 30, 30, 30, 30, 12, 0, 0,
0,255,255,255,255,192,224,224,224,224,192,128, 0, 0, 0, 0,
0, 1, 3, 3, 3, 3, 1, 1, 1, 3,255,255,255,252, 0, 0,
0, 12, 30, 62, 60,120,120,120,120, 60, 63, 31, 15, 3, 0, 0,
0,192,240,248,252, 60, 30, 30, 30, 30, 60,124,120, 48, 0, 0,
0,255,255,255,255,192,224,224,224,224,192,128, 0, 0, 0, 0,
0,255,255,255,255, 3, 1, 1, 1, 3,255,255,255,252, 0, 0,
0, 3, 15, 31, 63, 60,120,120,120, 60, 63, 31, 15, 3, 0, 0,
0, 12, 30, 30, 30, 30, 30, 30, 30, 30,254,254,254,252, 0, 0,
0, 0, 0, 0, 0, 0,128,224,248,254,255, 63, 15, 3, 0, 0,
0, 0, 0, 0,248,254,255,255, 15, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 63,127,127, 63, 0, 0, 0, 0, 0, 0, 0, 0,
0,192,240,248,252, 60, 30, 30, 30, 60,252,248,240,192, 0, 0,
0, 15, 63,127,255,240,224,224,224,240,255,127, 63, 15, 0, 0,
0,248,254,255,255, 7, 3, 3, 3, 7,255,255,254,248, 0, 0,
0, 3, 15, 31, 63, 60,120,120,120, 60, 63, 31, 15, 3, 0, 0,
0,192,240,248,252, 60, 30, 30, 30, 60,252,248,240,192, 0, 0,
0, 63,255,255,255,192,128,128,128,192,255,255,255,255, 0, 0,
0, 0, 0, 1, 3, 3, 7, 7, 7, 3,255,255,255,255, 0, 0,
0, 12, 30, 62, 60,120,120,120,120, 60, 63, 31, 15, 3, 0, 0,
0, 0, 0, 0, 0, 0,128,128,128,128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,248,248,248,248, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
-120
View File
@@ -1,120 +0,0 @@
/* File '6X8.FV' as include
The font was generated with EA FontEditor. Please contact ELECTRONIC ASSEMBLY
for more details (techik@lcd-module.de)
File based on official EA Arduino library.
the array starts with a 8 byte header:
1st Byte: 'F' first 2 bytes are always FV
2nd Byte: 'V' for FONT VERTICAL
3rd Byte: First code to define
4th Byte: Last code to define
5th Byte: Width of character in dots
6th Byte: Height of character in dots
7th Byte: Height of character in bytes
8th Byte: Bytes needed for each character (1..255)
or 0 for big fonts calculate WidthInDots * HeightInBytes
After that font data will follow */
#define FONT_6X8_LEN 584
const char font_6x8 [FONT_6X8_LEN] =
{
70, 86, 32,127, 6, 8, 1, 6,
0, 0, 0, 0, 0, 0,
0, 0, 95, 0, 0, 0,
0, 7, 0, 7, 0, 0,
20,127, 20,127, 20, 0,
36, 42,127, 42, 18, 0,
35, 19, 8,100, 98, 0,
54, 73, 86, 32, 80, 0,
0, 8, 7, 3, 0, 0,
0, 28, 34, 65, 0, 0,
0, 65, 34, 28, 0, 0,
42, 28,127, 28, 42, 0,
8, 8, 62, 8, 8, 0,
0,128,112, 48, 0, 0,
8, 8, 8, 8, 8, 0,
0, 0, 96, 96, 0, 0,
32, 16, 8, 4, 2, 0,
62, 81, 73, 69, 62, 0,
0, 66,127, 64, 0, 0,
66, 97, 81, 73, 70, 0,
33, 65, 73, 77, 51, 0,
24, 20, 18,127, 16, 0,
39, 69, 69, 69, 57, 0,
60, 74, 73, 73, 48, 0,
65, 33, 17, 9, 7, 0,
54, 73, 73, 73, 54, 0,
6, 73, 73, 41, 30, 0,
0, 0, 20, 0, 0, 0,
0, 64, 52, 0, 0, 0,
0, 8, 20, 34, 65, 0,
20, 20, 20, 20, 20, 0,
0, 65, 34, 20, 8, 0,
2, 1, 81, 9, 6, 0,
62, 65, 93, 89, 78, 0,
124, 18, 17, 18,124, 0,
127, 73, 73, 73, 54, 0,
62, 65, 65, 65, 34, 0,
127, 65, 65, 65, 62, 0,
127, 73, 73, 73, 65, 0,
127, 9, 9, 9, 1, 0,
62, 65, 73, 73,122, 0,
127, 8, 8, 8,127, 0,
0, 65,127, 65, 0, 0,
32, 64, 65, 63, 1, 0,
127, 8, 20, 34, 65, 0,
127, 64, 64, 64, 64, 0,
127, 2, 28, 2,127, 0,
127, 4, 8, 16,127, 0,
62, 65, 65, 65, 62, 0,
127, 9, 9, 9, 6, 0,
62, 65, 81, 33, 94, 0,
127, 9, 25, 41, 70, 0,
38, 73, 73, 73, 50, 0,
1, 1,127, 1, 1, 0,
63, 64, 64, 64, 63, 0,
31, 32, 64, 32, 31, 0,
63, 64, 56, 64, 63, 0,
99, 20, 8, 20, 99, 0,
3, 4,120, 4, 3, 0,
97, 81, 73, 69, 67, 0,
0,127, 65, 65, 65, 0,
2, 4, 8, 16, 32, 0,
0, 65, 65, 65,127, 0,
4, 2, 1, 2, 4, 0,
64, 64, 64, 64, 64, 0,
0, 3, 7, 8, 0, 0,
32, 84, 84, 84,120, 0,
127, 40, 68, 68, 56, 0,
56, 68, 68, 68, 40, 0,
56, 68, 68, 40,127, 0,
56, 84, 84, 84, 24, 0,
0, 8,126, 9, 2, 0,
24,164,164,164,124, 0,
127, 8, 4, 4,120, 0,
0, 68,125, 64, 0, 0,
32, 64, 64, 61, 0, 0,
127, 16, 40, 68, 0, 0,
0, 65,127, 64, 0, 0,
124, 4,120, 4,120, 0,
124, 8, 4, 4,120, 0,
56, 68, 68, 68, 56, 0,
252, 24, 36, 36, 24, 0,
24, 36, 36, 24,252, 0,
124, 8, 4, 4, 8, 0,
72, 84, 84, 84, 36, 0,
4, 4, 63, 68, 36, 0,
60, 64, 64, 32,124, 0,
28, 32, 64, 32, 28, 0,
60, 64, 48, 64, 60, 0,
68, 40, 16, 40, 68, 0,
76,144,144,144,124, 0,
68,100, 84, 76, 68, 0,
0, 8, 54, 65, 0, 0,
0, 0,119, 0, 0, 0,
0, 65, 54, 8, 0, 0,
2, 1, 2, 4, 2, 0,
60, 38, 35, 38, 60, 0
};
-120
View File
@@ -1,120 +0,0 @@
/* File '8X16neu.FV' as include
The font was generated with EA FontEditor. Please contact ELECTRONIC ASSEMBLY
for more details (techik@lcd-module.de)
File based on official EA Arduino library.
the array starts with a 8 byte header:
1st Byte: 'F' first 2 bytes are always FV
2nd Byte: 'V' for FONT VERTICAL
3rd Byte: First code to define
4th Byte: Last code to define
5th Byte: Width of character in dots
6th Byte: Height of character in dots
7th Byte: Height of character in bytes
8th Byte: Bytes needed for each character (1..255)
or 0 for big fonts calculate WidthInDots * HeightInBytes
After that font data will follow */
#define FONT_8X16_LEN 1544
const unsigned char font_8x16[FONT_8X16_LEN] =
{
70, 86, 32,127, 8, 16, 2, 16,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,252,252, 0, 0, 0, 0, 0, 0, 51, 51, 0, 0, 0,
0,252,252, 0, 0,252,252, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48,252,252, 48, 48,252,252, 48, 3, 15, 15, 3, 3, 15, 15, 3,
0,120,252,207,207,204,140, 0, 0, 12, 12, 60, 60, 15, 7, 0,
0, 28, 28,192,240, 60, 12, 0, 0, 12, 15, 3, 0, 14, 14, 0,
0,206,255,243, 63, 14, 0, 0, 31, 63, 48, 51, 31, 63, 51, 0,
0, 0, 0,252,252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,240,248, 28, 4, 0, 0, 0, 0, 15, 31, 56, 32, 0,
0, 4, 28,248,240, 0, 0, 0, 0, 32, 56, 31, 15, 0, 0, 0,
192,204,252,240,240,252,204,192, 0, 12, 15, 3, 3, 15, 12, 0,
0,192,192,248,248,192,192, 0, 0, 0, 0, 7, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,192,124, 60, 0, 0, 0,
0,192,192,192,192,192,192, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 60, 0, 0, 0,
0, 0, 0,128,224,124, 28, 0, 0, 56, 62, 7, 1, 0, 0, 0,
0,248,252, 12,140,252,248, 0, 0, 31, 63, 49, 48, 63, 31, 0,
0, 0, 48,252,252, 0, 0, 0, 0, 48, 48, 63, 63, 48, 48, 0,
0, 56, 60, 12,204,252, 56, 0, 0, 48, 60, 63, 51, 48, 48, 0,
0, 12, 12,204,252, 60, 12, 0, 0, 28, 60, 48, 51, 63, 28, 0,
0, 0,192,240,252,252, 0, 0, 0, 15, 15, 12, 63, 63, 12, 0,
0,252,252,204,204,204,140, 0, 0, 24, 56, 48, 48, 63, 31, 0,
0,240,248,156,140,140, 0, 0, 0, 31, 63, 49, 49, 63, 31, 0,
0, 12, 12, 12,204,252, 60, 0, 0, 0, 60, 63, 3, 0, 0, 0,
0, 56,252,204,204,252, 56, 0, 0, 31, 63, 48, 48, 63, 31, 0,
0,120,252,204,204,252,248, 0, 0, 0, 48, 48, 56, 31, 15, 0,
0, 0, 0,240,240, 0, 0, 0, 0, 0, 0, 60, 60, 0, 0, 0,
0, 0, 0,240,240, 0, 0, 0, 0, 0,192,124, 60, 0, 0, 0,
128,192,224,112, 56, 24, 8, 0, 0, 1, 3, 7, 14, 12, 8, 0,
0, 48, 48, 48, 48, 48, 48, 0, 0, 3, 3, 3, 3, 3, 3, 0,
8, 24, 56,112,224,192,128, 0, 8, 12, 14, 7, 3, 1, 0, 0,
0, 56, 60, 12,204,252, 56, 0, 0, 0, 0, 55, 55, 0, 0, 0,
240,248, 28,204, 76,152,240, 0, 15, 31, 56, 51, 50, 51, 25, 0,
0,240,248, 28, 28,248,240, 0, 0, 63, 63, 3, 3, 63, 63, 0,
0,252,252,204,204,252,120, 0, 0, 63, 63, 48, 48, 63, 31, 0,
0,248,252, 12, 12, 60, 56, 0, 0, 31, 63, 48, 48, 60, 28, 0,
0,252,252, 12, 28,248,240, 0, 0, 63, 63, 48, 56, 31, 15, 0,
0,252,252,204,204,204, 12, 0, 0, 63, 63, 48, 48, 48, 48, 0,
0,252,252,204,204,204, 12, 0, 0, 63, 63, 0, 0, 0, 0, 0,
0,248,252, 12,204,204,204, 0, 0, 31, 63, 48, 48, 63, 31, 0,
0,252,252,192,192,252,252, 0, 0, 63, 63, 0, 0, 63, 63, 0,
0, 12, 12,252,252, 12, 12, 0, 0, 48, 48, 63, 63, 48, 48, 0,
0, 0, 0, 0, 0,252,252, 0, 0, 28, 60, 48, 48, 63, 31, 0,
252,252,192,240, 60, 12, 0, 0, 63, 63, 0, 3, 15, 60, 48, 0,
0,252,252, 0, 0, 0, 0, 0, 0, 63, 63, 48, 48, 48, 48, 0,
252,252,112,192,112,252,252, 0, 63, 63, 0, 1, 0, 63, 63, 0,
0,252,252,224,128,252,252, 0, 0, 63, 63, 1, 7, 63, 63, 0,
0,248,252, 12, 12,252,248, 0, 0, 31, 63, 48, 48, 63, 31, 0,
0,252,252, 12, 12,252,248, 0, 0, 63, 63, 3, 3, 3, 1, 0,
0,248,252, 12, 12,252,248, 0, 0, 31, 63, 48, 24, 55, 47, 0,
252,252,140,140,252,248, 0, 0, 63, 63, 1, 3, 15, 60, 48, 0,
0,120,252,204,140, 12, 12, 0, 0, 48, 48, 49, 51, 63, 30, 0,
0, 12, 12,252,252, 12, 12, 0, 0, 0, 0, 63, 63, 0, 0, 0,
0,252,252, 0, 0,252,252, 0, 0, 31, 63, 48, 48, 63, 31, 0,
0,252,252, 0, 0,252,252, 0, 0, 3, 15, 60, 60, 15, 3, 0,
252,252, 0,128, 0,252,252, 0, 63, 31, 14, 7, 14, 31, 63, 0,
0, 28,124,224,224,124, 28, 0, 0, 56, 62, 7, 7, 62, 56, 0,
0, 60,252,192,192,252, 60, 0, 0, 0, 0, 63, 63, 0, 0, 0,
0, 12, 12,204,252, 60, 12, 0, 0, 60, 63, 51, 48, 48, 48, 0,
0, 0, 0,252,252, 12, 12, 0, 0, 0, 0, 63, 63, 48, 48, 0,
0, 28,124,224,128, 0, 0, 0, 0, 0, 0, 1, 7, 62, 56, 0,
0, 12, 12,252,252, 0, 0, 0, 0, 48, 48, 63, 63, 0, 0, 0,
128,224,120, 30,120,224,128, 0, 1, 1, 0, 0, 0, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 48, 48, 48, 48, 48, 48, 48, 0,
0, 7, 14, 28, 56,112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 96, 96, 96,224,192, 0, 0, 30, 63, 51, 51, 63, 63, 0,
0,252,252, 96, 96,224,192, 0, 0, 63, 63, 48, 48, 63, 31, 0,
0,192,224, 96, 96, 96, 0, 0, 0, 31, 63, 48, 48, 48, 48, 0,
0,192,224, 96, 96,252,252, 0, 0, 31, 63, 48, 48, 63, 63, 0,
0,192,224, 96, 96,224,192, 0, 0, 31, 63, 50, 50, 51, 51, 0,
0,192,192,248,252,204,204, 0, 0, 0, 0, 63, 63, 0, 0, 0,
0,192,224, 96, 96,224,224, 0, 0,207,223,216,216,255,127, 0,
0,252,252, 96, 96,224,192, 0, 0, 63, 63, 0, 0, 63, 63, 0,
0, 0, 96,236,236, 0, 0, 0, 0, 0, 48, 63, 63, 48, 0, 0,
0, 0, 0, 0,236,236, 0, 0, 0,192,192,192,255,127, 0, 0,
252,252,128,192,224, 96, 0, 0, 63, 63, 3, 7, 30, 56, 48, 0,
0, 0, 12,252,252, 0, 0, 0, 0, 0, 48, 63, 63, 48, 0, 0,
192,224,224,192,224,224,192, 0, 63, 63, 0, 7, 0, 63, 63, 0,
0,192,224, 96, 96,224,192, 0, 0, 63, 63, 0, 0, 63, 63, 0,
0,192,224, 96, 96,224,192, 0, 0, 31, 63, 48, 48, 63, 31, 0,
0,224,224, 96, 96,224,192, 0, 0,255,255, 48, 48, 63, 31, 0,
0,192,224, 96, 96,224,224, 0, 0, 31, 63, 48, 48,255,255, 0,
0,224,224, 96, 96,224,192, 0, 0, 63, 63, 0, 0, 0, 0, 0,
0,192,224, 96, 96, 96, 96, 0, 0, 49, 51, 51, 54, 62, 28, 0,
0, 96, 96,248,248, 96, 96, 0, 0, 0, 0, 31, 63, 48, 48, 0,
0,224,224, 0, 0,224,224, 0, 0, 31, 63, 48, 48, 63, 63, 0,
0,224,224, 0, 0,224,224, 0, 0, 3, 15, 60, 60, 15, 3, 0,
224,224, 0,128, 0,224,224, 0, 63, 31, 14, 7, 14, 31, 63, 0,
0, 96,224,128,128,224, 96, 0, 0, 48, 61, 15, 15, 61, 48, 0,
0,224,224, 0, 0,224,224, 0, 0,207,223,216,216,255,127, 0,
0, 96, 96, 96,224,224, 96, 0, 0, 48, 60, 63, 51, 48, 48, 0,
128,128,192,252,126, 2, 2, 0, 1, 1, 3, 63,126, 64, 64, 0,
0, 0, 0,254,254, 0, 0, 0, 0, 0, 0,127,127, 0, 0, 0,
2, 2,126,252,192,128,128, 0, 64, 64,126, 63, 3, 1, 1, 0,
192, 96,224,192,128,128,224, 0, 1, 0, 0, 1, 1, 1, 0, 0,
0, 0,128,224,224,128, 0, 0, 24, 30, 19, 16, 16, 19, 30, 24
};
-120
View File
@@ -1,120 +0,0 @@
/* File '8X8.FV' as include
The font was generated with EA FontEditor. Please contact ELECTRONIC ASSEMBLY
for more details (techik@lcd-module.de)
File based on official EA Arduino library.
the array starts with a 8 byte header:
1st Byte: 'F' first 2 bytes are always FV
2nd Byte: 'V' for FONT VERTICAL
3rd Byte: First code to define
4th Byte: Last code to define
5th Byte: Width of character in dots
6th Byte: Height of character in dots
7th Byte: Height of character in bytes
8th Byte: Bytes needed for each character (1..255)
or 0 for big fonts calculate WidthInDots * HeightInBytes
After that font data will follow */
#define FONT_8X8_LEN 776
const unsigned char font_8x8[FONT_8X8_LEN] =
{
70, 86, 32,127, 8, 8, 1, 8,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 95, 95, 0, 0, 0,
0, 7, 7, 0, 0, 7, 7, 0,
36,126,126, 36,126,126, 36, 0,
0, 36, 46,107,107, 58, 18, 0,
0,102, 54, 24, 12,102, 98, 0,
48,122, 79, 93, 55,114, 80, 0,
0, 0, 0, 7, 7, 0, 0, 0,
0, 0, 0, 62,127, 99, 65, 0,
0, 65, 99,127, 62, 0, 0, 0,
8, 42, 62, 28, 28, 62, 42, 8,
0, 8, 8, 62, 62, 8, 8, 0,
0,128,224, 96, 0, 0, 0, 0,
0, 8, 8, 8, 8, 8, 8, 0,
0, 0, 0, 96, 96, 0, 0, 0,
0, 96, 48, 24, 12, 6, 3, 0,
0, 62,127, 73, 69,127, 62, 0,
0, 64, 66,127,127, 64, 64, 0,
0, 66, 99,113, 89, 79, 70, 0,
0, 33, 97, 69, 79,123, 49, 0,
0, 24, 28, 22,127,127, 16, 0,
0, 39,103, 69, 69,125, 57, 0,
0, 62,127, 73, 73,121, 48, 0,
0, 1,113,121, 13, 7, 3, 0,
0, 54,127, 73, 73,127, 54, 0,
0, 6, 79, 73,105, 63, 30, 0,
0, 0, 0, 54, 54, 0, 0, 0,
0, 0, 64,118, 54, 0, 0, 0,
0, 0, 8, 28, 54, 99, 65, 0,
0, 36, 36, 36, 36, 36, 36, 0,
0, 65, 99, 54, 28, 8, 0, 0,
0, 2, 3, 81, 89, 15, 6, 0,
0, 62,127, 65, 93, 87, 94, 0,
0,124,126, 19, 19,126,124, 0,
0,127,127, 73, 73,127, 54, 0,
0, 62,127, 65, 65, 99, 34, 0,
0,127,127, 65, 99, 62, 28, 0,
0,127,127, 73, 73, 73, 65, 0,
0,127,127, 9, 9, 9, 1, 0,
0, 62,127, 65, 73,121,121, 0,
0,127,127, 8, 8,127,127, 0,
0, 0, 65,127,127, 65, 0, 0,
0, 32, 96, 64, 64,127, 63, 0,
0,127,127, 28, 54, 99, 65, 0,
0,127,127, 64, 64, 64, 64, 0,
127,127, 6, 12, 6,127,127, 0,
0,127,127, 14, 28,127,127, 0,
0, 62,127, 65, 65,127, 62, 0,
0,127,127, 9, 9, 15, 6, 0,
0, 62,127, 81, 33,127, 94, 0,
0,127,127, 9, 25,127,102, 0,
0, 38,111, 73, 73,123, 50, 0,
0, 1, 1,127,127, 1, 1, 0,
0, 63,127, 64, 64,127,127, 0,
0, 31, 63, 96, 96, 63, 31, 0,
127,127, 48, 24, 48,127,127, 0,
0, 99,119, 28, 28,119, 99, 0,
0, 7, 15,120,120, 15, 7, 0,
0, 97,113, 89, 77, 71, 67, 0,
0, 0, 0,127,127, 65, 65, 0,
0, 3, 6, 12, 24, 48, 96, 0,
0, 65, 65,127,127, 0, 0, 0,
8, 12, 6, 3, 6, 12, 8, 0,
64, 64, 64, 64, 64, 64, 64, 0,
2, 6, 12, 8, 0, 0, 0, 0,
0, 32,116, 84, 84,124,120, 0,
0,127,127, 68, 68,124, 56, 0,
0, 56,124, 68, 68, 68, 0, 0,
0, 56,124, 68, 68,127,127, 0,
0, 56,124, 84, 84, 92, 24, 0,
0, 4,126,127, 5, 5, 0, 0,
0,152,188,164,164,252,124, 0,
0,127,127, 4, 4,124,120, 0,
0, 0, 68,125,125, 64, 0, 0,
0,128,128,253,125, 0, 0, 0,
0,127,127, 16, 56,108, 68, 0,
0, 0, 65,127,127, 64, 0, 0,
124,124, 12, 24, 12,124,120, 0,
0,124,124, 4, 4,124,120, 0,
0, 56,124, 68, 68,124, 56, 0,
0,252,252, 68, 68,124, 56, 0,
0, 56,124, 68, 68,252,252, 0,
0,124,124, 4, 4, 12, 8, 0,
0, 72, 92, 84, 84,116, 36, 0,
0, 4, 4, 62,126, 68, 68, 0,
0, 60,124, 64, 64,124,124, 0,
0, 28, 60, 96, 96, 60, 28, 0,
28,124, 96, 48, 96,124, 28, 0,
0, 68,108, 56, 56,108, 68, 0,
0,156,188,160,160,252,124, 0,
0, 68,100,116, 92, 76, 68, 0,
0, 0, 8, 62,119, 65, 65, 0,
0, 0, 0,255,255, 0, 0, 0,
0, 65, 65,119, 62, 8, 0, 0,
12, 6, 6, 12, 24, 24, 12, 0,
0, 96,120, 94, 70, 88, 96, 0
};
-169
View File
@@ -1,169 +0,0 @@
/* mbed library for half bridge driver PWM generation
* Copyright (c) 2016 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.
*/
#include "HalfBridge.h"
HalfBridge::HalfBridge(PinName pin_HS, PinName pin_LS)
{
// Enable peripheral clock of GPIOA and GPIOB
RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN;
// Enable TIM1 clock
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
// Select alternate function mode on PA8 und PB13
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER8)) | GPIO_MODER_MODER8_1;
GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER13)) | GPIO_MODER_MODER13_1;
// Select AF2 on PA8 (TIM1_CH1)
GPIOA->AFR[1] |= 0x2 << ((8 - 8)*4); // AFR[1] for pins 8-15
// Select AF2 on PB13 (TIM1_CH1N)
GPIOB->AFR[1] |= 0x2 << ((13 - 8)*4); // AFR[1] for pins 8-15
// No prescaler --> timer frequency = 48 MHz
TIM1->PSC = 0;
// Capture/Compare Mode Register 1
// OC1M = 110: Select PWM mode 1 on OC1
// OC1PE = 1: Enable preload register on OC1 (reset value)
TIM1->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE;
// Capture/Compare Enable Register
// CC1E = 1: Enable the output on OC1
// CC1P = 0: Active high polarity on OC1 (default)
// CC1NE = 1: Enable the output on OC1N
// CC1NP = 0: Active high polarity on OC1N (default)
TIM1->CCER |= TIM_CCER_CC1E | TIM_CCER_CC1NE;// | TIM_CCER_CC1NP;
// Control Register 1
// TIM_CR1_CMS = 01: Select center-aligned mode 1
// TIM_CR1_CEN = 1: Counter enable
TIM1->CR1 |= TIM_CR1_CMS_0 | TIM_CR1_CEN;
// Control Register 2
// OIS1 = OIS1N = 0: Output Idle State is set to off
//TIM1->CR2 |= ;
// Force update generation (UG = 1)
TIM1->EGR |= TIM_EGR_UG;
// initialize frequency to set _pwm_resolution
frequency_kHz(1);
set_duty_cycle(0.5); // safer than 0 for DC/DC
}
void HalfBridge::frequency_kHz(int freq) {
_pwm_resolution = SystemCoreClock / (freq * 1000);
// Auto Reload Register
// center-aligned mode --> divide resolution by 2
TIM1->ARR = _pwm_resolution / 2;
}
void HalfBridge::set_duty_cycle(float duty) {
float duty_target;
// protection against wrong settings which could destroy the hardware
if (duty < _min_duty) {
duty_target = _min_duty;
}
else if (duty > _max_duty) {
duty_target = _max_duty;
}
else {
duty_target = duty;
}
TIM1->CCR1 = _pwm_resolution / 2 * duty_target;
}
void HalfBridge::duty_cycle_step(int delta)
{
float duty_target;
duty_target = (float)(TIM1->CCR1 + delta) / (_pwm_resolution / 2);
// protection against wrong settings which could destroy the hardware
if (duty_target < _min_duty) {
set_duty_cycle(_min_duty);
}
else if (duty_target > _max_duty) {
set_duty_cycle(_max_duty);
}
else {
TIM1->CCR1 = TIM1->CCR1 + delta;
}
}
float HalfBridge::get_duty_cycle() {
return (float)(TIM1->CCR1) / (_pwm_resolution / 2);;
}
void HalfBridge::deadtime_ns(int deadtime) {
uint8_t deadtime_clocks = (SystemCoreClock / 1000 / 1000) * deadtime / 1000;
// Break and Dead-Time Register
// MOE = 1: Main output enable
// OSSR = 0: Off-state selection for Run mode -> OC/OCN = 0
// OSSI = 0: Off-state selection for Idle mode -> OC/OCN = 0
TIM1->BDTR |= (deadtime_clocks & (uint32_t)0x7F); // ensure that only the last 7 bits are changed
}
void HalfBridge::start() {
// Break and Dead-Time Register
// MOE = 1: Main output enable
TIM1->BDTR |= TIM_BDTR_MOE;
}
void HalfBridge::stop() {
// Break and Dead-Time Register
// MOE = 1: Main output enable
TIM1->BDTR &= ~(TIM_BDTR_MOE);
}
void HalfBridge::lock_settings() {
// TODO: does not work properly, yet...
// Break and Dead-Time Register
TIM1->BDTR |= TIM_BDTR_LOCK_1 | TIM_BDTR_LOCK_0;
}
void HalfBridge::duty_cycle_limits(float min_duty, float max_duty) {
_min_duty = min_duty;
_max_duty = max_duty;
// adjust set value to new limits
if (get_duty_cycle() < _min_duty) {
set_duty_cycle(_min_duty);
}
else if (get_duty_cycle() > _max_duty) {
set_duty_cycle(_max_duty);
}
}
-86
View File
@@ -1,86 +0,0 @@
/* mbed library for half bridge driver PWM generation
* Copyright (c) 2016 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.
*/
#include "mbed.h"
class HalfBridge
{
public:
/** Create a half bridge class for the specified pins
*
* @param pin_HS PinName of the high-side output
* @param pin_LS PinName of the low-side output
*/
HalfBridge(PinName pin_HS, PinName pin_LS);
/** Set the PWM frequency in kHz
*
* @param freq Frequency in kHz
*/
void frequency_kHz(int freq);
/** Set the deadtime between switching the two FETs on/off
*
* @param deadtime Deadtime in ns
*/
void deadtime_ns(int deadtime);
/** Lock the settings of PWM generation to prevent accidental changes
* (does not work properly, yet! --> TODO)
*/
void lock_settings(void);
/** Start the PWM generation
*/
void start();
/** Stop the PWM generation
*/
void stop();
/** Set the duty cycle of the PWM signal between 0.0 and 1.0
*
* @param duty Duty cycle between 0.0 and 1.0
*/
void set_duty_cycle(float duty);
/** Adjust the duty cycle with minimum step size
*
* @param delta Number of steps (positive or negative)
*/
void duty_cycle_step(int delta);
/** Read the currently set duty cycle
*
* @returns
* Duty cycle between 0.0 and 1.0
*/
float get_duty_cycle();
/** Set limits for the duty cycle to prevent hardware damages
*
* @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 duty_cycle_limits(float min_duty, float max_duty);
private:
int _pwm_resolution;
float _min_duty;
float _max_duty;
};
-324
View File
@@ -1,324 +0,0 @@
/**
* @author Aaron Berk
*
* @section LICENSE
*
* Copyright (c) 2010 ARM Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* A PID controller is a widely used feedback controller commonly found in
* industry.
*
* This library is a port of Brett Beauregard's Arduino PID library:
*
* http://www.arduino.cc/playground/Code/PIDLibrary
*
* The wikipedia article on PID controllers is a good place to start on
* understanding how they work:
*
* http://en.wikipedia.org/wiki/PID_controller
*
* For a clear and elegant explanation of how to implement and tune a
* controller, the controlguru website by Douglas J. Cooper (who also happened
* to be Brett's controls professor) is an excellent reference:
*
* http://www.controlguru.com/
*/
/**
* Includes
*/
#include "PID.h"
PID::PID(float Kc, float tauI, float tauD, float interval) {
usingFeedForward = false;
inAuto = false;
//Default the limits to the full range of I/O: 3.3V
//Make sure to set these to more appropriate limits for
//your application.
setInputLimits(0.0, 3.3);
setOutputLimits(0.0, 3.3);
tSample_ = interval;
setTunings(Kc, tauI, tauD);
setPoint_ = 0.0;
processVariable_ = 0.0;
prevProcessVariable_ = 0.0;
controllerOutput_ = 0.0;
prevControllerOutput_ = 0.0;
accError_ = 0.0;
bias_ = 0.0;
realOutput_ = 0.0;
}
void PID::setInputLimits(float inMin, float inMax) {
//Make sure we haven't been given impossible values.
if (inMin >= inMax) {
return;
}
//Rescale the working variables to reflect the changes.
prevProcessVariable_ *= (inMax - inMin) / inSpan_;
accError_ *= (inMax - inMin) / inSpan_;
//Make sure the working variables are within the new limits.
if (prevProcessVariable_ > 1) {
prevProcessVariable_ = 1;
} else if (prevProcessVariable_ < 0) {
prevProcessVariable_ = 0;
}
inMin_ = inMin;
inMax_ = inMax;
inSpan_ = inMax - inMin;
}
void PID::setOutputLimits(float outMin, float outMax) {
//Make sure we haven't been given impossible values.
if (outMin >= outMax) {
return;
}
//Rescale the working variables to reflect the changes.
prevControllerOutput_ *= (outMax - outMin) / outSpan_;
//Make sure the working variables are within the new limits.
if (prevControllerOutput_ > 1) {
prevControllerOutput_ = 1;
} else if (prevControllerOutput_ < 0) {
prevControllerOutput_ = 0;
}
outMin_ = outMin;
outMax_ = outMax;
outSpan_ = outMax - outMin;
}
void PID::setTunings(float Kc, float tauI, float tauD) {
//Verify that the tunings make sense.
if (Kc == 0.0 || tauI < 0.0 || tauD < 0.0) {
return;
}
//Store raw values to hand back to user on request.
pParam_ = Kc;
iParam_ = tauI;
dParam_ = tauD;
float tempTauR;
if (tauI == 0.0) {
tempTauR = 0.0;
} else {
tempTauR = (1.0 / tauI) * tSample_;
}
//For "bumpless transfer" we need to rescale the accumulated error.
if (inAuto) {
if (tempTauR == 0.0) {
accError_ = 0.0;
} else {
accError_ *= (Kc_ * tauR_) / (Kc * tempTauR);
}
}
Kc_ = Kc;
tauR_ = tempTauR;
tauD_ = tauD / tSample_;
}
void PID::reset(void) {
float scaledBias = 0.0;
if (usingFeedForward) {
scaledBias = (bias_ - outMin_) / outSpan_;
} else {
scaledBias = (realOutput_ - outMin_) / outSpan_;
}
prevControllerOutput_ = scaledBias;
prevProcessVariable_ = (processVariable_ - inMin_) / inSpan_;
//Clear any error in the integral.
accError_ = 0;
}
void PID::setMode(int mode) {
//We were in manual, and we just got set to auto.
//Reset the controller internals.
if (mode != 0 && !inAuto) {
reset();
}
inAuto = (mode != 0);
}
void PID::setInterval(float interval) {
if (interval > 0) {
//Convert the time-based tunings to reflect this change.
tauR_ *= (interval / tSample_);
accError_ *= (tSample_ / interval);
tauD_ *= (interval / tSample_);
tSample_ = interval;
}
}
void PID::setSetPoint(float sp) {
setPoint_ = sp;
}
void PID::setProcessValue(float pv) {
processVariable_ = pv;
}
void PID::setBias(float bias){
bias_ = bias;
usingFeedForward = 1;
}
float PID::compute() {
//Pull in the input and setpoint, and scale them into percent span.
float scaledPV = (processVariable_ - inMin_) / inSpan_;
if (scaledPV > 1.0) {
scaledPV = 1.0;
} else if (scaledPV < 0.0) {
scaledPV = 0.0;
}
float scaledSP = (setPoint_ - inMin_) / inSpan_;
if (scaledSP > 1.0) {
scaledSP = 1;
} else if (scaledSP < 0.0) {
scaledSP = 0;
}
float error = scaledSP - scaledPV;
//Check and see if the output is pegged at a limit and only
//integrate if it is not. This is to prevent reset-windup.
if (!(prevControllerOutput_ >= 1 && error > 0) && !(prevControllerOutput_ <= 0 && error < 0)) {
accError_ += error;
}
//Compute the current slope of the input signal.
float dMeas = (scaledPV - prevProcessVariable_) / tSample_;
float scaledBias = 0.0;
if (usingFeedForward) {
scaledBias = (bias_ - outMin_) / outSpan_;
}
//Perform the PID calculation.
controllerOutput_ = scaledBias + Kc_ * (error + (tauR_ * accError_) - (tauD_ * dMeas));
//Make sure the computed output is within output constraints.
if (controllerOutput_ < 0.0) {
controllerOutput_ = 0.0;
} else if (controllerOutput_ > 1.0) {
controllerOutput_ = 1.0;
}
//Remember this output for the windup check next time.
prevControllerOutput_ = controllerOutput_;
//Remember the input for the derivative calculation next time.
prevProcessVariable_ = scaledPV;
//Scale the output from percent span back out to a real world number.
return ((controllerOutput_ * outSpan_) + outMin_);
}
float PID::getInMin() {
return inMin_;
}
float PID::getInMax() {
return inMax_;
}
float PID::getOutMin() {
return outMin_;
}
float PID::getOutMax() {
return outMax_;
}
float PID::getInterval() {
return tSample_;
}
float PID::getPParam() {
return pParam_;
}
float PID::getIParam() {
return iParam_;
}
float PID::getDParam() {
return dParam_;
}
-213
View File
@@ -1,213 +0,0 @@
/**
* @author Aaron Berk
*
* @section LICENSE
*
* Copyright (c) 2010 ARM Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* A PID controller is a widely used feedback controller commonly found in
* industry.
*
* This library is a port of Brett Beauregard's Arduino PID library:
*
* http://www.arduino.cc/playground/Code/PIDLibrary
*
* The wikipedia article on PID controllers is a good place to start on
* understanding how they work:
*
* http://en.wikipedia.org/wiki/PID_controller
*
* For a clear and elegant explanation of how to implement and tune a
* controller, the controlguru website by Douglas J. Cooper (who also happened
* to be Brett's controls professor) is an excellent reference:
*
* http://www.controlguru.com/
*/
#ifndef PID_H
#define PID_H
/**
* Includes
*/
#include "mbed.h"
/**
* Defines
*/
#define MANUAL_MODE 0
#define AUTO_MODE 1
/**
* Proportional-integral-derivative controller.
*/
class PID {
public:
/**
* Constructor.
*
* Sets default limits [0-3.3V], calculates tuning parameters, and sets
* manual mode with no bias.
*
* @param Kc - Tuning parameter
* @param tauI - Tuning parameter
* @param tauD - Tuning parameter
* @param interval PID calculation performed every interval seconds.
*/
PID(float Kc, float tauI, float tauD, float interval);
/**
* Scale from inputs to 0-100%.
*
* @param InMin The real world value corresponding to 0%.
* @param InMax The real world value corresponding to 100%.
*/
void setInputLimits(float inMin , float inMax);
/**
* Scale from outputs to 0-100%.
*
* @param outMin The real world value corresponding to 0%.
* @param outMax The real world value corresponding to 100%.
*/
void setOutputLimits(float outMin, float outMax);
/**
* Calculate PID constants.
*
* Allows parameters to be changed on the fly without ruining calculations.
*
* @param Kc - Tuning parameter
* @param tauI - Tuning parameter
* @param tauD - Tuning parameter
*/
void setTunings(float Kc, float tauI, float tauD);
/**
* Reinitializes controller internals. Automatically
* called on a manual to auto transition.
*/
void reset(void);
/**
* Set PID to manual or auto mode.
*
* @param mode 0 -> Manual
* Non-zero -> Auto
*/
void setMode(int mode);
/**
* Set how fast the PID loop is run.
*
* @param interval PID calculation peformed every interval seconds.
*/
void setInterval(float interval);
/**
* Set the set point.
*
* @param sp The set point as a real world value.
*/
void setSetPoint(float sp);
/**
* Set the process value.
*
* @param pv The process value as a real world value.
*/
void setProcessValue(float pv);
/**
* Set the bias.
*
* @param bias The bias for the controller output.
*/
void setBias(float bias);
/**
* PID calculation.
*
* @return The controller output as a float between outMin and outMax.
*/
float compute(void);
//Getters.
float getInMin();
float getInMax();
float getOutMin();
float getOutMax();
float getInterval();
float getPParam();
float getIParam();
float getDParam();
private:
bool usingFeedForward;
bool inAuto;
//Actual tuning parameters used in PID calculation.
float Kc_;
float tauR_;
float tauD_;
//Raw tuning parameters.
float pParam_;
float iParam_;
float dParam_;
//The point we want to reach.
float setPoint_;
//The thing we measure.
float processVariable_;
float prevProcessVariable_;
//The output that affects the process variable.
float controllerOutput_;
float prevControllerOutput_;
//We work in % for calculations so these will scale from
//real world values to 0-100% and back again.
float inMin_;
float inMax_;
float inSpan_;
float outMin_;
float outMax_;
float outSpan_;
//The accumulated error, i.e. integral.
float accError_;
//The controller output bias.
float bias_;
//The interval between samples.
float tSample_;
//Controller output as a real world value.
volatile float realOutput_;
};
#endif /* PID_H */
+8 -7
View File
@@ -80,7 +80,7 @@ const int thermistorBetaValue = 3435; // typical value for Semitec 103AT-5 ther
#define PIN_UEXT_MISO PB_4
#define PIN_UEXT_MOSI PB_5
#define PIN_UEXT_SCK PB_3
#define PIN_UEXT_SSEL PA_0
#define PIN_UEXT_SSEL PC_13
#define PIN_SWD_TX PA_9
#define PIN_SWD_RX PA_10
@@ -94,11 +94,12 @@ const int thermistorBetaValue = 3435; // typical value for Semitec 103AT-5 ther
#define PIN_REF_I_DCDC PA_4
#define PIN_V_REF PA_5
#define PIN_V_BAT PA_6
#define PIN_V_SOLAR PA_7
#define PIN_V_TEMP PA_1
#define PIN_I_LOAD PB_0
#define PIN_I_DCDC PB_1
#define PIN_V_REF PA_5
#define PIN_V_BAT PA_6
#define PIN_V_SOLAR PA_7
#define PIN_TEMP_INT PA_1
#define PIN_TEMP_BAT PA_0
#define PIN_I_LOAD PB_0
#define PIN_I_DCDC PB_1
#endif
+2 -2
View File
@@ -41,7 +41,7 @@ const int charge_current_max = 10000; // mA PCB maximum: 20 A
// State: CV/absorption
const int cell_voltage_max = 2400; // max voltage per cell
const int time_limit_CV = 120; // min
const int current_cutoff_CV = 1000; //2000; // mA
const int current_cutoff_CV = 300; //2000; // mA
// State: float/trickle
const bool trickle_enabled = true;
@@ -97,7 +97,7 @@ const int thermistorBetaValue = 3435; // typical value for Semitec 103AT-5 ther
#define PIN_V_REF PA_0 // not connected
#define PIN_V_BAT PA_4
#define PIN_V_SOLAR PA_5
#define PIN_V_TEMP PA_0 // not connected
#define PIN_TEMP_INT PA_0 // not connected
#define PIN_I_LOAD PA_6
#define PIN_I_DCDC PA_7
+104
View File
@@ -0,0 +1,104 @@
/* LibreSolar MPPT charge controller firmware
* Copyright (c) 2016-2017 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 CONFIG_H
#define CONFIG_H
#include "mbed.h"
#define MPPT_20A
// DC/DC converter settings
const int _pwm_frequency = 70; // kHz
const int charge_current_cutoff = 20; // mA --> if lower, charger is switched off
const int max_solar_voltage = 55000; // mV
const int num_cells = 6;
// State: Standby
const int solar_voltage_offset_start = 5000; // mV charging switched on if Vsolar > Vbat + offset
const int solar_voltage_offset_stop = 1000; // mV charging switched off if Vsolar < Vbat + offset
const int time_limit_recharge = 60;//5*60; // sec
const int cell_voltage_recharge = 2300; // mV
// State: CC/bulk
const int charge_current_max = 10000; // mA PCB maximum: 20 A
// State: CV/absorption
const int cell_voltage_max = 2400; // max voltage per cell
const int time_limit_CV = 120; // min
const int current_cutoff_CV = 2000; // mA
// State: float/trickle
const bool trickle_enabled = true;
const int cell_voltage_trickle = 2300; // voltage for trickle charging of lead-acid batteries
const int time_trickle_recharge = 30; // min
// State: equalization
const bool equalization_enabled = false;
const int cell_voltage_equalization = 2500; // mV
const int time_limit_equalization = 60; // min
const int current_limit_equalization = 1000; // mA
const int equalization_trigger_time = 8; // weeks
const int equalization_trigger_deep_cycles = 10; // times
const int cell_voltage_load_disconnect = 1950;
const int cell_voltage_load_reconnect = 2200;
/*
// typcial LiFePO4 battery
const int num_cells = 4;
const int v_cell_max = 3550; // max voltage per cell
const int v_cell_trickle = 3550; // voltage for trickle charging of lead-acid batteries
const int v_cell_load_disconnect = 3000;
const int v_cell_load_reconnect = 3150;
*/
const int thermistorBetaValue = 3435; // typical value for Semitec 103AT-5 thermistor: 3435
//----------------------------------------------------------------------------
// global variables
// 20A board (rev. 0.6)
#define PIN_UEXT_TX PA_2
#define PIN_UEXT_RX PA_3
#define PIN_UEXT_SCL PB_6
#define PIN_UEXT_SDA PB_7
#define PIN_UEXT_MISO PB_4
#define PIN_UEXT_MOSI PB_5
#define PIN_UEXT_SCK PB_3
#define PIN_UEXT_SSEL PA_0
#define PIN_SWD_TX PA_9
#define PIN_SWD_RX PA_10
#define PIN_PWM_HS PA_8
#define PIN_PWM_LS PB_13
#define PIN_LED_GREEN PB_14
#define PIN_LED_RED PB_15
#define PIN_LOAD_DIS PB_2
#define PIN_REF_I_DCDC PA_4
#define PIN_V_REF PA_5
#define PIN_V_BAT PA_6
#define PIN_V_SOLAR PA_7
#define PIN_TEMP_INT PA_1
#define PIN_I_LOAD PB_0
#define PIN_I_DCDC PB_1
#endif
+69 -55
View File
@@ -18,14 +18,11 @@
//#include "config_12a.h" // choose old PCB revision (12A)
#include "config.h" // choose new PCB revision (20A)
#include "BuckConverter.h"
//#include "DogLCD.h"
//#include "font_6x8.h"
#include "Adafruit_SSD1306.h"
//#include "SDFileSystem.h"
#include <math.h> // log for thermistor calculation
#include "display.h"
//#define DOGLCD_ENABLED
//#define SDCARD_ENABLED
#define OLED_ENABLED
@@ -34,11 +31,6 @@
//----------------------------------------------------------------------------
// global variables
#ifdef DOGLCD_ENABLED
SPI spi(PIN_UEXT_MOSI, NC, PIN_UEXT_SCK);
DogLCD lcd(spi, PIN_UEXT_SSEL, PIN_UEXT_RX, PIN_UEXT_TX); // spi, CS, CD, reset
#endif
#ifdef SDCARD_ENABLED
SDFileSystem sd(PIN_UEXT_MOSI, PIN_UEXT_MISO, PIN_UEXT_SCK, PIN_UEXT_SSEL, "sd");
#endif
@@ -63,15 +55,15 @@ DigitalOut load_disable(PIN_LOAD_DIS);
AnalogIn v_ref(PIN_V_REF);
AnalogIn v_bat(PIN_V_BAT);
AnalogIn v_solar(PIN_V_SOLAR);
AnalogIn v_temp(PIN_V_TEMP);
AnalogIn v_temp(PIN_TEMP_INT);
AnalogIn i_load(PIN_I_LOAD);
AnalogIn i_dcdc(PIN_I_DCDC);
int solar_voltage; // mV
int battery_voltage; // mV
int dcdc_current = 0; // mA
int load_current; // mA
float temperature; // mA
int load_current = 0; // mA
float temperature; // °C
int solar_power = 0; // unit: mW
int dcdc_current_offset = 0;
@@ -99,10 +91,8 @@ int state = BAT_ERROR;
void setup();
void update_measurements();
void update_controller();
void enter_state(int next_state);
void state_machine();
void adjust_input_voltage(int delta_mV);
void update_screen();
void energy_counter();
void load_management();
@@ -143,13 +133,8 @@ int main()
//----------------------------------------------------------------------------
void setup()
{
#ifdef DOGLCD_ENABLED
lcd.init();
lcd.view(VIEW_TOP);
#endif
led_green = 1;
load_disable = 0;
load_disable = 1;
// ref_i_dcdc = 0; // 0 for buck, 1 for boost (TODO)
// for RTC backup register
@@ -158,17 +143,18 @@ void setup()
set_time(rtc_read_backup_reg(0));
input_Wh_day = float(rtc_read_backup_reg(1)) / 1000.0; // mWh
output_Wh_day = float(rtc_read_backup_reg(2)) / 1000.0; // mWh
input_Wh_total = float(rtc_read_backup_reg(3)); // Wh
output_Wh_total = float(rtc_read_backup_reg(4)); // Wh
input_Wh_day = (float)rtc_read_backup_reg(1) / 1000.0; // mWh
output_Wh_day = (float)rtc_read_backup_reg(2) / 1000.0; // mWh
input_Wh_total = (float)rtc_read_backup_reg(3); // Wh
output_Wh_total = (float)rtc_read_backup_reg(4); // Wh
mppt.frequency_kHz(_pwm_frequency);
mppt.deadtime_ns(300);
mppt.set_duty_cycle(0.90);
mppt.lock_settings();
mppt.set_current_limit(charge_current_max);
mppt.set_voltage_limit(num_cells * cell_voltage_max);
mppt.set_max_current(charge_current_max);
mppt.set_min_current(charge_current_cutoff);
mppt.set_max_voltage(num_cells * cell_voltage_max);
mppt.duty_cycle_limits((float) cell_voltage_load_disconnect * num_cells / max_solar_voltage, 0.97);
update_measurements();
@@ -211,8 +197,8 @@ void enter_state(int next_state)
case CHG_CC:
serial.printf("Enter State: CHG_CC\n");
//serial.printf("P=%d Vsol=%d Vbat=%d Ibat=%d delta_time_CV=%d\n", solar_power, solar_voltage, battery_voltage, dcdc_current, time(NULL) - mppt.last_time_CV());
mppt.set_current_limit(charge_current_max);
mppt.set_voltage_limit(num_cells * cell_voltage_max);
mppt.set_max_current(charge_current_max);
mppt.set_max_voltage(num_cells * cell_voltage_max);
mppt.last_time_CV_reset();
mppt.start((float) battery_voltage / (solar_voltage - 1000.0));
led_red = 1;
@@ -221,25 +207,27 @@ void enter_state(int next_state)
case CHG_CV:
serial.printf("Enter State: CHG_CV\n");
//serial.printf("P=%d Vsol=%d Vbat=%d Ibat=%d delta_time_CV=%d\n", solar_power, solar_voltage, battery_voltage, dcdc_current, time(NULL) - mppt.last_time_CV());
mppt.set_voltage_limit(num_cells * cell_voltage_max);
mppt.set_max_voltage(num_cells * cell_voltage_max);
break;
case CHG_TRICKLE:
serial.printf("Enter State: CHG_TRICKLE\n");
//serial.printf("P=%d Vsol=%d Vbat=%d Ibat=%d delta_time_CV=%d\n", solar_power, solar_voltage, battery_voltage, dcdc_current, time(NULL) - mppt.last_time_CV());
mppt.set_voltage_limit(num_cells * cell_voltage_trickle);
mppt.set_max_voltage(num_cells * cell_voltage_trickle);
mppt.last_time_CV_reset();
break;
case CHG_EQUALIZATION:
serial.printf("Enter State: CHG_EQUALIZATION\n");
mppt.set_voltage_limit(num_cells * cell_voltage_equalization);
mppt.set_max_voltage(num_cells * cell_voltage_equalization);
mppt.last_time_CV_reset();
mppt.set_current_limit(current_limit_equalization);
mppt.set_max_current(current_limit_equalization);
break;
case TEST:
serial.printf("Enter State: TEST\n");
//mppt.set_current_limit(charge_current_max);
//mppt.set_voltage_limit(num_cells * cell_voltage_max);
mppt.start(0.50);
led_red = 1;
break;
@@ -261,16 +249,33 @@ void enter_state(int next_state)
/*****************************************************************************
* Charger state machine
*
* INIT Initial state when system boots up. Checks communication to BMS
* and turns the CHG and DSG FETs on
* STANDBY Battery can be discharged, but no charging power is available
* or battery is fully charged
* CHG_CC Constant current (CC) charging with maximum current possible
* (MPPT algorithm is running)
* CHG_CV Constant voltage (CV) charging at maximum cell voltage
* BAT_ERROR An error occured. Charging disabled.
*
## Standby
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)
*/
void state_machine()
{
@@ -319,25 +324,31 @@ void state_machine()
}
}
else if (dcdc_current < charge_current_cutoff
|| solar_voltage < battery_voltage + solar_voltage_offset_stop) {
|| solar_voltage < battery_voltage + solar_voltage_offset_stop)
{
enter_state(STANDBY);
}
break;
}
case CHG_TRICKLE: {
if (time(NULL) - mppt.last_time_CV() > time_trickle_recharge * 60) {
if (time(NULL) - mppt.last_time_CV() > time_trickle_recharge * 60)
{
enter_state(CHG_CC);
}
else if (dcdc_current < charge_current_cutoff
|| solar_voltage < battery_voltage + solar_voltage_offset_stop) {
// current cutoff might never be reached because of lakage
// current inside battery --> stay in trickle till end of day
else if ((dcdc_current < charge_current_cutoff
&& battery_voltage < num_cells * cell_voltage_trickle)
|| solar_voltage < battery_voltage + solar_voltage_offset_stop)
{
enter_state(STANDBY);
}
break;
}
case TEST: {
break;
}
default:
mppt.stop();
break;
@@ -448,7 +459,7 @@ void update_measurements()
// low pass filter of measurement values:
// y(n) = (1-c)*x(n) + c*y(n-1) with c=exp(-Ta/RC)
// https://en.wikipedia.org/wiki/Low-pass_filter#Simple_infinite_impulse_response_filter
float c = 0.2; // filter constant
float c = 0.3; // filter constant
// first call of function
if (battery_voltage == 0) {
@@ -457,17 +468,17 @@ void update_measurements()
#ifdef MPPT_12A
// solar voltage divider o-- 150k --o-- 6.8k --o
tmp = adc_read(v_solar) * vcc * 1568 / 68;
solar_voltage = (100 - c) * tmp + c * solar_voltage;
tmp = adc_read_avg(v_solar) * vcc * 1568 / 68;
solar_voltage = (1.0 - c) * tmp + c * solar_voltage;
// battery voltage divider o-- 120k --o-- 10k --o
tmp = adc_read(v_bat) * vcc * 130 / 10;
battery_voltage = (100 - c) * tmp + c * battery_voltage;
tmp = adc_read_avg(v_bat) * vcc * 130 / 10;
battery_voltage = (1.0 - c) * tmp + c * battery_voltage;
tmp = adc_read(i_dcdc) * vcc * 1000 / 5 / 50;
tmp = adc_read_avg(i_dcdc) * vcc * 1000 / 5 / 50;
dcdc_current = (1.0 - c) * (tmp + dcdc_current_offset) + c * dcdc_current;
tmp = adc_read(i_load) * vcc * 1000 / 5 / 50;
tmp = adc_read_avg(i_load) * vcc * 1000 / 5 / 50;
load_current = (1.0 - c) * (tmp + load_current_offset) + c * load_current;
solar_power = battery_voltage * dcdc_current / 1000;
@@ -570,7 +581,7 @@ void update_screen(void)
oled.printf("Tot +%4.1fkWh -%4.1fkWh", input_Wh_total / 1000.0, fabs(output_Wh_total) / 1000.0);
oled.setTextCursor(0, 56);
oled.printf("PWM %.1f%% ", mppt.get_duty_cycle() * 100.0);
oled.printf("Temp %.1f PWM %.1f%% ", temperature, mppt.get_duty_cycle() * 100.0);
switch (state) {
case STANDBY:
oled.printf("Standby\n");
@@ -587,6 +598,9 @@ void update_screen(void)
case CHG_BIKE:
oled.printf("Bike gen\n");
break;
case TEST:
oled.printf("Test\n");
break;
default:
oled.printf("Error\n");
break;