Unfortunately, I never did well in math at school and as such, this is a field I struggle with so please bear with me as I know what I am asking is likely very simple math to work out.
I am building a device that uses a current transducer to meter power generated by my solar system, and how much has been stored, etc. I am using a STM32F103C8T which contains a 12-bit ADC and will sample up to 16 channels (iirc). One of the features of this device is that it will let you sample the internal vref so that you can use it to correct for sampling errors due to drift, etc.
As I am looking for good accuracy I have used MAX6350 (I had a few floating around) as a precision 5V reference and using two 1K resistors divided it down to 2.5V for the current transducer's vref. This improved the output of the transducer considerably even though I am doing a less than perfect divide by 2 (yes, I should get a MAX6325). To be able to adjust for error I have also fed this 2.5V reference into the ADC.
The current transducer is a
LSTR 15-NP configured for two loops at a nominal 7.5A.
So, I have three analog inputs to the mcu:
1) Current Transducer Output (CH_CUR)
2) Current Transducer VREF (CH_CREF)
3) Battery voltage which I am dropping 48V via two zeners and then using another divider network to scale the remainder to the 3.3V ADC input. (CH_VOL)
So in software, I have four samples per sampling, the fourth being the STM32's ADC reference (CH_VREF). At the moment what I have done is the following although I question its correctness.
const float vref = (4095.0f * 1200.0f) / samples[CH_VREF];
const float cref = samples[CH_CREF] * (vref / 2047.5f);
const float c = (samples[CH_CUR] * (cref / 4095.0f) - (cref / 2.0f)) * (7500.0f / (3125.0f - 2500.0f));
const float v = samples[CH_VOL] * (10725.0f / 4095.0f) + 47757.0f;
Does this look correct, or am I missing something here? While the results are close to my DC clamp meter, it's still about 500mA off on average.
Edit: Forgot to add, here is a sample of the raw samples when there is zero current flow.
VREF CREF CUR VOL
1515 3141 2024 1376
1515 3141 2022 1402
1513 3142 2021 1439
1514 3143 2023 1360
1514 3141 2023 1366
1514 3142 2021 1450
1514 3141 2021 1372
1514 3142 2024 1374
1514 3142 2022 1347
1515 3140 2023 1414
1515 3141 2022 1441
1515 3141 2023 1351