ESPHome  2024.12.2
constants.h
Go to the documentation of this file.
1 #pragma once
2 #include <cstdint>
3 
4 namespace esphome {
5 namespace bl0906 {
6 
7 // Total power conversion
8 static 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
11 static 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
16 static const float BL0906_FREF = 10000000;
17 // Temperature conversion
18 static const float BL0906_TREF = 12.5 / 59 - 40;
19 // Current conversion
20 static const float BL0906_IREF = 1.097 / (12875 * 1 * (5.1 + 5.1) * 1000 / 2000);
21 // Voltage conversion
22 static const float BL0906_UREF = 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) / (13162 * 1 * 100 * 1000);
23 // Power conversion
24 static 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
27 static 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
32 static const float BL0906_KI = 12875 * 1 * (5.1 + 5.1) * 1000 / 2000 / 1.097;
33 // Power coefficient
34 static 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 
37 static const uint8_t USR_WRPROT_WITABLE[6] = {0xCA, 0x9E, 0x55, 0x55, 0x00, 0xB7};
38 static const uint8_t USR_WRPROT_ONLYREAD[6] = {0xCA, 0x9E, 0x00, 0x00, 0x00, 0x61};
39 
40 static const uint8_t BL0906_READ_COMMAND = 0x35;
41 static const uint8_t BL0906_WRITE_COMMAND = 0xCA;
42 
43 // Register address
44 // Voltage
45 static const uint8_t BL0906_V_RMS = 0x16;
46 
47 // Total power
48 static const uint8_t BL0906_WATT_SUM = 0X2C;
49 
50 // Current1~6
51 static const uint8_t BL0906_I_1_RMS = 0x0D; // current_1
52 static const uint8_t BL0906_I_2_RMS = 0x0E;
53 static const uint8_t BL0906_I_3_RMS = 0x0F;
54 static const uint8_t BL0906_I_4_RMS = 0x10;
55 static const uint8_t BL0906_I_5_RMS = 0x13;
56 static const uint8_t BL0906_I_6_RMS = 0x14; // current_6
57 
58 // Power1~6
59 static const uint8_t BL0906_WATT_1 = 0X23; // power_1
60 static const uint8_t BL0906_WATT_2 = 0X24;
61 static const uint8_t BL0906_WATT_3 = 0X25;
62 static const uint8_t BL0906_WATT_4 = 0X26;
63 static const uint8_t BL0906_WATT_5 = 0X29;
64 static const uint8_t BL0906_WATT_6 = 0X2A; // power_6
65 
66 // Active pulse count, unsigned
67 static const uint8_t BL0906_CF_1_CNT = 0X30; // Channel_1
68 static const uint8_t BL0906_CF_2_CNT = 0X31;
69 static const uint8_t BL0906_CF_3_CNT = 0X32;
70 static const uint8_t BL0906_CF_4_CNT = 0X33;
71 static const uint8_t BL0906_CF_5_CNT = 0X36;
72 static const uint8_t BL0906_CF_6_CNT = 0X37; // Channel_6
73 
74 // Total active pulse count, unsigned
75 static const uint8_t BL0906_CF_SUM_CNT = 0X39;
76 
77 // Voltage frequency cycle
78 static const uint8_t BL0906_FREQUENCY = 0X4E;
79 
80 // Internal temperature
81 static const uint8_t BL0906_TEMPERATURE = 0X5E;
82 
83 // Calibration register
84 // RMS gain adjustment register
85 static const uint8_t BL0906_RMSGN_1 = 0x6D; // Channel_1
86 static const uint8_t BL0906_RMSGN_2 = 0x6E;
87 static const uint8_t BL0906_RMSGN_3 = 0x6F;
88 static const uint8_t BL0906_RMSGN_4 = 0x70;
89 static const uint8_t BL0906_RMSGN_5 = 0x73;
90 static const uint8_t BL0906_RMSGN_6 = 0x74; // Channel_6
91 
92 // RMS offset correction register
93 static const uint8_t BL0906_RMSOS_1 = 0x78; // Channel_1
94 static const uint8_t BL0906_RMSOS_2 = 0x79;
95 static const uint8_t BL0906_RMSOS_3 = 0x7A;
96 static const uint8_t BL0906_RMSOS_4 = 0x7B;
97 static const uint8_t BL0906_RMSOS_5 = 0x7E;
98 static const uint8_t BL0906_RMSOS_6 = 0x7F; // Channel_6
99 
100 // Active power gain adjustment register
101 static const uint8_t BL0906_WATTGN_1 = 0xB7; // Channel_1
102 static const uint8_t BL0906_WATTGN_2 = 0xB8;
103 static const uint8_t BL0906_WATTGN_3 = 0xB9;
104 static const uint8_t BL0906_WATTGN_4 = 0xBA;
105 static const uint8_t BL0906_WATTGN_5 = 0xBD;
106 static 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.
110 static const uint8_t BL0906_USR_WRPROT = 0x9E;
111 
112 // Reset Register
113 static const uint8_t BL0906_SOFT_RESET = 0x9F;
114 
115 const 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
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7