build in adc reference table
This commit is contained in:
parent
5757e93b57
commit
10b55e5aa5
|
@ -3,8 +3,8 @@
|
|||
ESPMega_CT::ESPMega_CT(uint8_t analog_pin, float (*adc_to_watts)(uint16_t adc_value), uint32_t fram_address)
|
||||
{
|
||||
this->analog_pin = analog_pin;
|
||||
this->adc_to_watts = adc_to_watts;
|
||||
this->fram_address = fram_address;
|
||||
this->adc_to_watts = adc_to_watts;
|
||||
}
|
||||
|
||||
void ESPMega_CT::begin()
|
||||
|
@ -37,3 +37,17 @@ float ESPMega_CT::get_power()
|
|||
{
|
||||
return this->power;
|
||||
}
|
||||
|
||||
float ESPMega_CT::adc_to_watts_builtin(uint16_t adc_value)
|
||||
{
|
||||
const float RATIO = 0.1;
|
||||
const float BURDEN_RESISTANCE = 20;
|
||||
const float VOLTAGE = 220;
|
||||
const uint16_t ADC_RANGE_START = 500;
|
||||
const uint16_t ADC_RANGE_END = 16000;
|
||||
const float ADC_RANGE = 12;
|
||||
float burden_voltage = (adc_value - ADC_RANGE_START) / (ADC_RANGE_END - ADC_RANGE_START) * ADC_RANGE;
|
||||
float secondary_current = burden_voltage / BURDEN_RESISTANCE;
|
||||
float primary_current = secondary_current / RATIO;
|
||||
return primary_current * VOLTAGE;
|
||||
}
|
|
@ -15,4 +15,5 @@ class ESPMega_CT {
|
|||
float power;
|
||||
long double energy;
|
||||
float (*adc_to_watts)(uint16_t adc_value);
|
||||
float adc_to_watts_builtin(uint16_t adc_value);
|
||||
};
|
Loading…
Reference in New Issue