PER Firmware
Loading...
Searching...
No Matches
telemetry.h
Go to the documentation of this file.
1
8#ifndef TELEMETRY_H
9#define TELEMETRY_H
10
11#include <stdint.h>
12
13// todo maybe a better home for these
14static inline float vbatt_to_voltage(uint16_t vbatt_raw) {
15 // Example conversion:
16 // 600V actual => linearly scaled to 2v -> linearly scaled to 4v -> (4.7/5.7) divider to ~3.3v
17 // Full conversion:
18 // V * (1/300) * 2 * (4.7/5.7) * 4095/3.3 = ADC
19 // V = (300) * (1/2) * (5.7/4.7) * (3.3/4095) * ADC
20
21 static constexpr float ADC_TO_PACK_VOLTAGE = 300.0f * (1.0f / 2.0f) * (5.7f / 4.7f) * (3.3f / 4095.0f);
22
23 float voltage = vbatt_raw * ADC_TO_PACK_VOLTAGE;
24
25 return voltage;
26}
27
28// DHAB S/134 current sensor conversion
29static inline float isense_to_current(uint16_t isense_raw) {
30 static constexpr float ADC_VREF = 3.3f;
31 static constexpr float ADC_MAX = 4095.0f;
32 static constexpr float ADC_TO_VOLTS = ADC_VREF / ADC_MAX;
33
34 static constexpr float DIV_R1 = 2400.0f;
35 static constexpr float DIV_R2 = 4700.0f;
36 static constexpr float DIV_GAIN = (DIV_R1 + DIV_R2) / DIV_R2;
37
38 static constexpr float V_OFFSET = 2.5f;
39 static constexpr float G = 10.0e-3f;
40
41 float v_adc = isense_raw * ADC_TO_VOLTS;
42 float v_sensor = v_adc * DIV_GAIN;
43 float current = (v_sensor - V_OFFSET) / G; // data
44
45 // Apply offset correction
46 static constexpr float ISENSE_OFFSET_AMPS = 2.5f; // todo tune this
47 current += ISENSE_OFFSET_AMPS;
48
49 return current;
50}
51
52static constexpr uint32_t BMS_PERIOD_MS = 200;
53
54static constexpr uint32_t TELEMETRY_100HZ_PERIOD_MS = 10;
55void report_telemetry_100hz(void);
56
57static constexpr uint32_t TELEMETRY_8HZ_PERIOD_MS = 125;
58void report_telemetry_8hz(void);
59
60static constexpr uint32_t TELEMETRY_02HZ_PERIOD_MS = 5000;
61void report_telemetry_02hz(void);
62
63#endif // TELEMETRY_H
static constexpr uint32_t TELEMETRY_100HZ_PERIOD_MS
Definition telemetry.h:54
static float vbatt_to_voltage(uint16_t vbatt_raw)
Definition telemetry.h:14
static constexpr uint32_t TELEMETRY_8HZ_PERIOD_MS
Definition telemetry.h:57
static constexpr uint32_t BMS_PERIOD_MS
Definition telemetry.h:52
static constexpr uint32_t TELEMETRY_02HZ_PERIOD_MS
Definition telemetry.h:60
static float isense_to_current(uint16_t isense_raw)
Definition telemetry.h:29
void report_telemetry_02hz(void)
Reports telemetry data at 0.2 Hz rate Includes: ABOX git hash, CAN stats.
Definition telemetry.c:101
void report_telemetry_8hz(void)
Reports telemetry data at 8 Hz rate Includes: Thermal stats and the emeter thermal summary.
Definition telemetry.c:54
void report_telemetry_100hz(void)
Reports telemetry data at 100 Hz rate Includes: Pack analog stats and cell telemetry.
Definition telemetry.c:22