ESPHome 2025.5.0
Loading...
Searching...
No Matches
constants.h
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3
4namespace esphome {
5namespace bl0906 {
6
7// Total power conversion
8static const float BL0906_WATT = 16 * 1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) /
9 (40.41259 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000);
10// Total Energy conversion
11static const float BL0906_CF = 16 * 4194304 * 0.032768 * 16 /
12 (3600000 * 16 *
13 (40.4125 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000 /
14 (1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000))));
15// Frequency conversion
16static const float BL0906_FREF = 10000000;
17// Temperature conversion
18static const float BL0906_TREF = 12.5 / 59 - 40;
19// Current conversion
20static const float BL0906_IREF = 1.097 / (12875 * 1 * (5.1 + 5.1) * 1000 / 2000);
21// Voltage conversion
22static const float BL0906_UREF = 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) / (13162 * 1 * 100 * 1000);
23// Power conversion
24static const float BL0906_PREF = 1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) /
25 (40.41259 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000);
26// Energy conversion
27static const float BL0906_EREF = 4194304 * 0.032768 * 16 /
28 (3600000 * 16 *
29 (40.4125 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000 /
30 (1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000))));
31// Current coefficient
32static const float BL0906_KI = 12875 * 1 * (5.1 + 5.1) * 1000 / 2000 / 1.097;
33// Power coefficient
34static const float BL0906_KP = 40.4125 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000 / 1.097 / 1.097 /
35 (20000 + 20000 + 20000 + 20000 + 20000);
36
37static const uint8_t USR_WRPROT_WITABLE[6] = {0xCA, 0x9E, 0x55, 0x55, 0x00, 0xB7};
38static const uint8_t USR_WRPROT_ONLYREAD[6] = {0xCA, 0x9E, 0x00, 0x00, 0x00, 0x61};
39
40static const uint8_t BL0906_READ_COMMAND = 0x35;
41static const uint8_t BL0906_WRITE_COMMAND = 0xCA;
42
43// Register address
44// Voltage
45static const uint8_t BL0906_V_RMS = 0x16;
46
47// Total power
48static const uint8_t BL0906_WATT_SUM = 0x2C;
49
50// Current1~6
51static const uint8_t BL0906_I_1_RMS = 0x0D; // current_1
52static const uint8_t BL0906_I_2_RMS = 0x0E;
53static const uint8_t BL0906_I_3_RMS = 0x0F;
54static const uint8_t BL0906_I_4_RMS = 0x10;
55static const uint8_t BL0906_I_5_RMS = 0x13;
56static const uint8_t BL0906_I_6_RMS = 0x14; // current_6
57
58// Power1~6
59static const uint8_t BL0906_WATT_1 = 0x23; // power_1
60static const uint8_t BL0906_WATT_2 = 0x24;
61static const uint8_t BL0906_WATT_3 = 0x25;
62static const uint8_t BL0906_WATT_4 = 0x26;
63static const uint8_t BL0906_WATT_5 = 0x29;
64static const uint8_t BL0906_WATT_6 = 0x2A; // power_6
65
66// Active pulse count, unsigned
67static const uint8_t BL0906_CF_1_CNT = 0x30; // Channel_1
68static const uint8_t BL0906_CF_2_CNT = 0x31;
69static const uint8_t BL0906_CF_3_CNT = 0x32;
70static const uint8_t BL0906_CF_4_CNT = 0x33;
71static const uint8_t BL0906_CF_5_CNT = 0x36;
72static const uint8_t BL0906_CF_6_CNT = 0x37; // Channel_6
73
74// Total active pulse count, unsigned
75static const uint8_t BL0906_CF_SUM_CNT = 0x39;
76
77// Voltage frequency cycle
78static const uint8_t BL0906_FREQUENCY = 0x4E;
79
80// Internal temperature
81static const uint8_t BL0906_TEMPERATURE = 0x5E;
82
83// Calibration register
84// RMS gain adjustment register
85static const uint8_t BL0906_RMSGN_1 = 0x6D; // Channel_1
86static const uint8_t BL0906_RMSGN_2 = 0x6E;
87static const uint8_t BL0906_RMSGN_3 = 0x6F;
88static const uint8_t BL0906_RMSGN_4 = 0x70;
89static const uint8_t BL0906_RMSGN_5 = 0x73;
90static const uint8_t BL0906_RMSGN_6 = 0x74; // Channel_6
91
92// RMS offset correction register
93static const uint8_t BL0906_RMSOS_1 = 0x78; // Channel_1
94static const uint8_t BL0906_RMSOS_2 = 0x79;
95static const uint8_t BL0906_RMSOS_3 = 0x7A;
96static const uint8_t BL0906_RMSOS_4 = 0x7B;
97static const uint8_t BL0906_RMSOS_5 = 0x7E;
98static const uint8_t BL0906_RMSOS_6 = 0x7F; // Channel_6
99
100// Active power gain adjustment register
101static const uint8_t BL0906_WATTGN_1 = 0xB7; // Channel_1
102static const uint8_t BL0906_WATTGN_2 = 0xB8;
103static const uint8_t BL0906_WATTGN_3 = 0xB9;
104static const uint8_t BL0906_WATTGN_4 = 0xBA;
105static const uint8_t BL0906_WATTGN_5 = 0xBD;
106static const uint8_t BL0906_WATTGN_6 = 0xBE; // Channel_6
107
108// User write protection setting register,
109// You must first write 0x5555 to the write protection setting register before writing to other registers.
110static const uint8_t BL0906_USR_WRPROT = 0x9E;
111
112// Reset Register
113static const uint8_t BL0906_SOFT_RESET = 0x9F;
114
115const uint8_t BL0906_INIT[2][6] = {
116 // Reset to default
117 {BL0906_WRITE_COMMAND, BL0906_SOFT_RESET, 0x5A, 0x5A, 0x5A, 0x52},
118 // Enable User Operation Write
119 {BL0906_WRITE_COMMAND, BL0906_USR_WRPROT, 0x55, 0x55, 0x00, 0xB7}};
120
121} // namespace bl0906
122} // namespace esphome
const uint8_t BL0906_INIT[2][6]
Definition constants.h:115
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7