1352 |
miho |
1 |
//********************************************************************** |
|
|
2 |
// INFO BATTERY PACK |
|
|
3 |
//********************************************************************** |
|
|
4 |
// (c) OK1XGL 2008 |
|
|
5 |
|
|
|
6 |
|
|
|
7 |
#include <16F88.h> |
|
|
8 |
#device *=16 |
|
|
9 |
#device adc=10 |
|
|
10 |
|
|
|
11 |
#fuses WDT,INTRC_IO, NOPUT, NOMCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO, CCPB3 |
|
|
12 |
#use delay(clock=4000000,RESTART_WDT) |
|
|
13 |
#use FAST_IO (A) |
|
|
14 |
#use FAST_IO (B) |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
// definice pinu |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
// vystupy LED diody |
|
|
21 |
#define LED1_G PIN_A6 |
|
|
22 |
#define LED2_Y PIN_A7 |
|
|
23 |
#define LED3_Y PIN_A4 |
|
|
24 |
#define LED4_R PIN_B0 |
|
|
25 |
|
|
|
26 |
// analogove vstupy |
|
|
27 |
#define I_SENSE PIN_A0 |
|
|
28 |
#define IB_CAN 0 |
|
|
29 |
#define V_SENSE PIN_A1 |
|
|
30 |
#define VB_CAN 1 |
|
|
31 |
#define TM_PIN PIN_B7 |
|
|
32 |
|
|
|
33 |
#define TB_CAN 6 |
|
|
34 |
#define REF_25V PIN_A3 |
|
|
35 |
|
|
|
36 |
// vstupy rizeni funkcnosti |
|
|
37 |
#define SOURCE_ON PIN_B6 // analogovy vstup |
|
|
38 |
#define VS_CAN 5 |
|
|
39 |
#define LOAD_ON PIN_B4 |
|
|
40 |
|
|
|
41 |
// vystupy rizeni funkcnosti |
|
|
42 |
#define CHRG_ON PIN_B1 |
|
|
43 |
#define BATT_ON PIN_B3 |
|
|
44 |
|
|
|
45 |
// nastavovaci signaly |
|
|
46 |
#define SET PIN_A5 |
|
|
47 |
#define UP PIN_B7 |
|
|
48 |
|
|
|
49 |
#define UP_MASK 0x01 // maska pro stisknute tlacitko UP |
|
|
50 |
#define SET_MASK 0x02 // maska pro stisknute tlacitko SET |
|
|
51 |
|
|
|
52 |
// debug seriovka |
|
|
53 |
#ifdef DEBUG |
|
|
54 |
#use rs232 (baud = 9600, xmit = PIN_B5, DISABLE_INTS) |
|
|
55 |
#endif |
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
#define VS_MIN_mV 8000 // minimalni vstupni napeti napajeciho zdroje pro nabijeni |
|
|
60 |
|
|
|
61 |
#define VB_MIN_mV 10000 // minimalni napeti baterie - dojde k odpojeni |
|
|
62 |
#define VB_LOW_mV 11000 // nizke napeti baterie - upozorneni pred odpojenim |
|
|
63 |
|
|
|
64 |
#define TB_MAX 45 // max teplota baterie pri nabijeni |
|
|
65 |
#define TB_MIN 5 // min teplota baterie pri nabijeni |
|
|
66 |
#define TB_DEFAULT 25 // teplota baterie, kdyz teplomer neni pouzit |
|
|
67 |
|
|
|
68 |
#define VREF_DIS_mV 2500 |
|
|
69 |
#define VREF_CHRG_mV 5000 |
|
|
70 |
|
|
|
71 |
#define VS_STEP_mV ((VREF_CHRG_mV / 1024.0) * ((8.2 + 1) / 1)) // rozliseni mereni vstupniho napeti mV () |
|
|
72 |
#define VB_STEP_mV ((VREF_DIS_mV / 1024.0) * ((68 + 10) / 10.0)) // rozliseni mereni napeti baterie v mV (19 mV -> 1.9 mv na clanek) |
|
|
73 |
//#define VS_MIN (int16)(VS_MIN_mV / VS_STEP_mV) |
|
|
74 |
#define VS_MIN (int16)44 |
|
|
75 |
#define VB_MIN (int16)(VB_MIN_mV / VB_STEP_mV) |
|
|
76 |
#define VB_LOW (int16)(VB_LOW_mV / VB_STEP_mV) |
|
|
77 |
|
|
|
78 |
#define I_STEP_mA ((VREF_DIS_mV / 1024.0) * 10 * 0.1) // rozliseni mereni proudu v mV (2.44 mA) |
|
|
79 |
|
|
|
80 |
#define TICK_mS 4 // tik kratkeho casovace v ms |
|
|
81 |
#define S_TICK_TIME ~4000 // hodnota pro natazeni kratkeho casovace |
|
|
82 |
#define L_TICK_TIME 300 / TICK_mS // |
|
|
83 |
#define HOUR_TIME_WDT 9000 // cas v ms / 400 ms nastav na 1 hod |
|
|
84 |
|
|
|
85 |
#define CAP_BATT ((60.0 * 60.0 * 1000.0) / (TICK_ms * I_STEP_mA)) // pro prevod kapacity baterie na vnitrni reprezentaci |
|
|
86 |
|
|
|
87 |
// adresy parametru programu v eeprom |
|
|
88 |
#define B_CAP_H_ADDR 0 |
|
|
89 |
#define B_CAP_L_ADDR 1 |
|
|
90 |
#define EFF_ADDR 2 |
|
|
91 |
#define LOSS_CAP_H_ADDR 3 |
|
|
92 |
#define LOSS_CAP_L_ADDR 4 |
|
|
93 |
#define LOSS_DAY_H_ADDR 5 |
|
|
94 |
#define LOSS_DAY_L_ADDR 6 |
|
|
95 |
#define TB_REF_ADDR 7 |
|
|
96 |
|
|
|
97 |
// maximalni hodnoty parametru programu |
|
|
98 |
const int8 PAR_MAX_TAB [8] = {5, |
|
|
99 |
9, |
|
|
100 |
9, |
|
|
101 |
9, |
|
|
102 |
9, |
|
|
103 |
6, |
|
|
104 |
9}; |
|
|
105 |
|
|
|
106 |
// tabulka pro ziskani koeficientu ucinnosti |
|
|
107 |
// hodnoty se ziskaji ze vztahu: 64 / koeficient ucinnosti (pr: 64 / 1.2 = 53) |
|
|
108 |
const int8 CHRG_EFF_TAB [10] = {71, // ucinnost 0.9 |
|
|
109 |
67, // 0.95 |
|
|
110 |
64, // 1.0 |
|
|
111 |
61, // 1.05 |
|
|
112 |
58, // 1.10 |
|
|
113 |
55, // 1.15 |
|
|
114 |
53, // 1.20 |
|
|
115 |
51, // 1.25 |
|
|
116 |
49, // 1.30 |
|
|
117 |
47}; // 1.35 |
|
|
118 |
|
|
|
119 |
// globalni promenne |
|
|
120 |
int8 TB_val; // teplota baterie |
|
|
121 |
int8 TB_ref; // teplota baterie, pri ktere se merilo samovybijeni |
|
|
122 |
int8 TB_avr24; // prumerna teplota baterie za 24 hod |
|
|
123 |
|
|
|
124 |
int8 l_timer; // pro dlouhy periodicky casovac |
|
|
125 |
int1 s_tick; // kratky tik periodickeho casovace |
|
|
126 |
int1 l_tick; // dlouhy tik periodickeho casovace |
|
|
127 |
|
|
|
128 |
int1 blink; // zrcadlo pro rychle blikani ledkami |
|
|
129 |
int1 slow_blink; // zrcadlo pro pomale blikani ledkami |
|
|
130 |
|
|
|
131 |
int1 invalid_cap; // neplatny zaznam o aktualni kapacite baterie |
|
|
132 |
int32 B_cap; // aktualini kapacita baterie |
|
|
133 |
|
|
|
134 |
int16 hour_time; // cas pro odmereni 1 hod pomoci wdt |
|
|
135 |
|
|
|
136 |
// promenne vypocitane z parametru programu |
|
|
137 |
int32 B_cap_4_4; // mez pro plnou kapacitu baterie |
|
|
138 |
int32 B_cap_3_4; // mez pro 3/4 kapacitu baterie |
|
|
139 |
int32 B_cap_2_4; // mez pro 2/3 kapacitu baterie |
|
|
140 |
int32 B_cap_1_4; // mez pro 1/4 kapacitu baterie |
|
|
141 |
|
|
|
142 |
int16 chrg_01C; // regulace proudu na 0.1C |
|
|
143 |
int16 chrg_02C; // regulace proudu na 0.2C |
|
|
144 |
int8 chrg_eff; // ucinnost nabijeni |
|
|
145 |
|
|
|
146 |
int8 k; // strmost samovybijeni |
|
|
147 |
|
|
|
148 |
// definice potrebnych registru CPU |
|
|
149 |
#bit ADIE = 0x8c.6 // povoleni interruptu od AD |
|
|
150 |
#bit PEIE = 0x0b.6 // povoleni interruptu od periferii |
|
|
151 |
#bit ADIF = 0x0c.6 |
|
|
152 |
#bit TMR1IF = 0x0c.0 // preteceni casovace 1 |
|
|
153 |
|
|
|
154 |
// Makro pro nastaveni pinu jao vystup (reverzni funke k output_float () ) |
|
|
155 |
#define output_fixed(pin) { #asm BCF ((pin) / 8 + 0x80).((pin) % 8) #endasm } |
|
|
156 |
|
|
|
157 |
|
|
|
158 |
// defaultni parametry programu ulozene v eeprom |
|
|
159 |
#rom 0x2100={3, // kpacita baterie tisice |
|
|
160 |
5, // kapacita baterie stovky |
|
|
161 |
0, // ucinnost nabijeni ve tvaru 1.xx s krokem 05 |
|
|
162 |
3, // ztracena kapacita samovybijenim desitky procent |
|
|
163 |
0, // ztracena kapacita samovybijenim jednotky procent |
|
|
164 |
3, // za dobu desitky dni |
|
|
165 |
0, // za dobu jednotky dni |
|
|
166 |
25} // referencni teplota pri ktere probihalo samovybijeni |