Skip to content

Commit b03a086

Browse files
Backup battery sensors added, small bug fixes
1 parent e84217b commit b03a086

3 files changed

Lines changed: 92 additions & 1 deletion

File tree

BAT.ino

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
void Get_BAT() {
2+
// Read backup battery data
3+
long int Vo;
4+
float R2 = 10000;
5+
float logR1, R1, T;
6+
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
7+
8+
long int Rv1 = 2200; // Battery voltage divider in kOhm - top resistor
9+
long int Rv2 = 680; // Battery voltage divider in kOhm - bottom resistor
10+
11+
// Battery temperature
12+
// low temperature threshold and high-temperature threshold in the charger controller are preset internally to 73.5%·VREF33 (0C)and 29.5%·VREF33 (48C)
13+
14+
15+
Vo = analogRead(A7);
16+
//R1 = Vo*R2/(1023-(float)Vo); // 1023 if reference voltage is 5v
17+
R1 = Vo*R2/(675-(float)Vo); // 675 if reference voltage is 3.3v
18+
logR1 = log(R1);
19+
T = (1.0 / (c1 + c2*logR1 + c3*logR1*logR1*logR1)); // https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation
20+
T = T - 273.15;
21+
//T = T * 9.0 / 5.0 + 32.0; // Fahrenheit conversion
22+
23+
BAT_Temperature = T;
24+
25+
Vo = analogRead(A6);
26+
Vo = Vo*5000/1023;
27+
Vo = Vo*(Rv1+Rv2)/Rv2;
28+
29+
BAT_Voltage = Vo; // battery voltage in millivolts
30+
31+
32+
33+
// status information
34+
// ACOK Valid Input Supply Indicator. Open drain output. Add pull-up resistor. Logic LOW indicates the presence of a valid input supply.
35+
// CHGOK Charging Status Indicator. Open drain output. Add pull-up resistor. Logic LOW indicates normal charging. Logic HIGH indicates either a completed charge process or suspended
36+
// process because of some fault.
37+
38+
BAT_Status = !digitalRead(9); // ACOK
39+
BAT_Status = BAT_Status*2 + !digitalRead(7); // CHGOK
40+
41+
42+
/*
43+
Serial.print("BAT_Voltage = ");
44+
Serial.println(BAT_Voltage);
45+
Serial.print("BAT_Temperature = ");
46+
Serial.println(BAT_Temperature);
47+
Serial.print("BAT_Status = ");
48+
Serial.println(BAT_Status);
49+
*/
50+
51+
}

EFIS_ModuleA.ino

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ int i = 0;
5151
int OAT = 0;
5252
int Humidity = 0;
5353

54+
// Backup battery data
55+
unsigned int BAT_Voltage = 0;
56+
byte BAT_Status = 0;
57+
int BAT_Temperature = 0;
58+
5459
unsigned int Airspeed = 0;
5560
// int VerticalSpeed = 0;
5661
int AoA = 0;
@@ -77,16 +82,20 @@ const unsigned int CAN_AoA_Msg_ID = 41; // CAN Msg ID in DEC
7782
const unsigned int CAN_OAT_Msg_ID = 42; // CAN Msg ID in DEC
7883
const unsigned int CAN_RAW_Msg_ID = 43; // CAN Msg ID in DEC
7984
const unsigned int CAN_QNH_Msg_ID = 46; // CAN Msg ID in DEC
85+
const unsigned int CAN_BAT_Msg_ID = 86; // CAN Msg ID in DEC
8086
const unsigned int CAN_Air_Period = 300; // How often message sent in milliseconds
8187
const unsigned int CAN_AoA_Period = 200; // How often message sent in milliseconds
8288
const unsigned int CAN_OAT_Period = 2000; // How often message sent in milliseconds
8389
const unsigned int CAN_RAW_Period = 500; // How often message sent in milliseconds
8490
const unsigned int CAN_QNH_Period = 5000;
91+
const unsigned int CAN_BAT_Period = 3000; // How often message sent in milliseconds
8592
unsigned long CAN_Air_Timestamp = 0; // when was the last message sent
8693
unsigned long CAN_AoA_Timestamp = 0; // when was the last message sent
8794
unsigned long CAN_OAT_Timestamp = 0; // when was the last message sent
8895
unsigned long CAN_RAW_Timestamp = 0; // when was the last message sent
8996
unsigned long CAN_QNH_Timestamp = 0;
97+
unsigned long CAN_BAT_Timestamp = 0; // when was the last message sent
98+
9099
int QNH_MemOffset = 0;
91100

92101
unsigned char len = 0;
@@ -98,6 +107,8 @@ MCP_CAN CAN(CAN_CS_PIN); // Set CS pin
98107
void setup()
99108
{
100109
Wire.begin(); // wake up I2C bus
110+
pinMode(7, INPUT_PULLUP);
111+
pinMode(9, INPUT_PULLUP);
101112
delay (50);
102113
Serial.begin(115200);
103114

@@ -238,15 +249,40 @@ if (millis() > CAN_RAW_Timestamp + CAN_RAW_Period + random(0, 50)) {
238249
// QNH is stored in this module as well as Display modules where it can be changed.
239250
// Latest change in the Display module overwrites the QNH value on all devices.
240251
// The QNH gets re-broadcasted in case one of the units goes down
241-
if (millis() > CAN_QNH_Timestamp + CAN_QNH_Period) {
252+
// !!!!!!!!!!!!!! QNH re-broadcasting has been removed as unnnecesary !!!!!!!!!!!!!
253+
// !!!!!!!!!!!! re-broadcasting code left commented out pending testing !!!!!!!!!!!
254+
/* if (millis() > CAN_QNH_Timestamp + CAN_QNH_Period) {
242255
243256
Send_QNH();
244257
CAN_QNH_Timestamp = millis();
245258
246259
}
260+
*/
261+
262+
/*
263+
* The section below does not belong to Module A (air pressure data)
264+
* The data below is most suitable for EMS module
265+
* EMS module does not have analog inputs left available
266+
* so the backup battery data will be capured bu this module until EMS module expanded (one day)
267+
*/
247268

269+
// Send Backup Battery data
270+
if (millis() > CAN_BAT_Timestamp + CAN_BAT_Period + random(0, 100)) {
271+
272+
Get_BAT();
273+
274+
canMsg[0] = BAT_Voltage;
275+
canMsg[1] = BAT_Voltage >> 8;
248276

277+
canMsg[2] = BAT_Status;
278+
279+
canMsg[3] = BAT_Temperature;
280+
281+
CAN.sendMsgBuf(CAN_BAT_Msg_ID, 0, 4, canMsg);
282+
283+
CAN_BAT_Timestamp = millis();
249284

285+
}
250286

251287

252288
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Unzip libraries.zip to the "libraries" folder in your Arduino environment.
88

99
## Release Notes: ##
1010

11+
### 2023-06-27 ###
12+
* Removed QNH re-broadcasting as unnecessary
13+
* Added code to read and broadcast backup battery data from CAN HUB ver 3
14+
1115
### 2021-06-08 ###
1216
* Bug fix for QNH setting
1317

0 commit comments

Comments
 (0)