esp加入
This commit is contained in:
@@ -16,19 +16,19 @@ INA226_t ina226[INA226_NUM];
|
||||
static soft_iic_info_struct ina226_soft_iic_config;
|
||||
|
||||
|
||||
void INA226_Init()
|
||||
void INA226_Init(void)
|
||||
{
|
||||
uint8 addr_list[INA226_NUM] = INA226_ADDR;
|
||||
uint8 mode[2] = INA226_DEF_MODE;
|
||||
float max_current_A = 20.0f;
|
||||
float rshunt_mOhm = 10.0f;
|
||||
float amp_fix_k = 1.0f;
|
||||
float vot_fix_k = 1.0f;
|
||||
float max_current_A = 30.0f;
|
||||
float rshunt_mOhm = 2.0f;
|
||||
float vot_fix_k[INA226_NUM] = INA226_VOT_FIX_K;
|
||||
float amp_fix_k[INA226_NUM] = INA226_AMP_FIX_K;
|
||||
uint8 counter;
|
||||
|
||||
for(counter = 0; counter < INA226_NUM; counter++)
|
||||
{
|
||||
INA226_Single_Init(&ina226[counter], addr_list[counter], mode, max_current_A, rshunt_mOhm, amp_fix_k, vot_fix_k);
|
||||
INA226_Single_Init(&ina226[counter], addr_list[counter], mode, max_current_A, rshunt_mOhm, amp_fix_k[counter], vot_fix_k[counter]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ void INA226_Single_Init(INA226_t *ina226, uint8 addr, uint8 mode[2], float max_c
|
||||
ina226->calibration.cal[1] = (uint8)((uint16)cal & 0xFF);
|
||||
|
||||
memset(&ina226->result, 0, sizeof(ina226->result));
|
||||
|
||||
ina226_soft_iic_config.addr = ina226->config.addr;
|
||||
soft_iic_write_8bit_registers(&ina226_soft_iic_config, INA226_CONFIG_REG, ina226->config.mode, 2);
|
||||
soft_iic_write_8bit_registers(&ina226_soft_iic_config, INA226_CALIBRATION_REG, ina226->calibration.cal, 2);
|
||||
|
||||
}
|
||||
|
||||
void INA226_Read(INA226_t *ina226)
|
||||
void INA226_Single_Read(INA226_t *ina226)
|
||||
{
|
||||
uint8 counter;
|
||||
if(!is_iic_init) return;
|
||||
@@ -75,13 +75,13 @@ void INA226_Read(INA226_t *ina226)
|
||||
soft_iic_read_8bit_registers(&ina226_soft_iic_config, INA226_SHUNTVOT_REG, ina226->result.org_reg[0],2);
|
||||
|
||||
|
||||
ina226->result.voltage_V = (int16)((ina226->result.org_reg[1][0] << 8) | ina226->result.org_reg[1][1]) * 0.00125f;
|
||||
ina226->result.voltage_V = (int16)((ina226->result.org_reg[1][0] << 8) | ina226->result.org_reg[1][1]) * 0.00125f * ina226->config.vot_fix_k;
|
||||
ina226->result.current_A = (int16)((ina226->result.org_reg[3][0] << 8) | ina226->result.org_reg[3][1]) * ina226->calibration.c_lsb_mA * 0.001f;
|
||||
ina226->result.power_W = (int16)((ina226->result.org_reg[2][0] << 8) | ina226->result.org_reg[2][1]) * ina226->calibration.c_lsb_mA * 0.025f;
|
||||
ina226->result.power_W = (int16)((ina226->result.org_reg[2][0] << 8) | ina226->result.org_reg[2][1]) * ina226->calibration.c_lsb_mA * 0.025f * ina226->config.vot_fix_k;
|
||||
ina226->result.shunt_voltage_mV = (int16)((ina226->result.org_reg[0][0] << 8) | ina226->result.org_reg[0][1]) * 0.0025f;
|
||||
|
||||
ina226->result.voltage_V = ina226->result.voltage_V > 0 ? ina226->result.voltage_V : 0;
|
||||
ina226->result.current_A = ina226->result.current_A > 0 ? ina226->result.current_A : 0;
|
||||
ina226->result.voltage_V = ina226->result.voltage_V > 0.009 ? ina226->result.voltage_V : 0;
|
||||
ina226->result.current_A = ina226->result.current_A > 0.009 ? ina226->result.current_A : 0;
|
||||
ina226->result.power_W = ina226->result.power_W > 0.016 && ina226->result.current_A > 0 && ina226->result.voltage_V > 0 ? ina226->result.power_W : 0;
|
||||
ina226->result.shunt_voltage_mV = ina226->result.shunt_voltage_mV > 0 ? ina226->result.shunt_voltage_mV : 0;
|
||||
|
||||
@@ -96,3 +96,12 @@ void INA226_Read(INA226_t *ina226)
|
||||
ina226->result.energy_J += (ina226->result.past_voltage_V[9] * ina226->result.past_current_A[9] + ina226->result.past_voltage_V[8] * ina226->result.past_current_A[8]) * (INA226_READ_TIME_MS / 2000.0f);
|
||||
ina226->result.quantity_C += (ina226->result.past_current_A[9] + ina226->result.past_current_A[8]) * (INA226_READ_TIME_MS / 2000.0f);
|
||||
}
|
||||
|
||||
void INA226_Read(void)
|
||||
{
|
||||
uint8 counter;
|
||||
for(counter = 0; counter < INA226_NUM; counter++)
|
||||
{
|
||||
INA226_Single_Read(&ina226[counter]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user