I’m chugging through some of the code in EnergyMonitor::calcIrms(). I’m curious around the factor 1024 on line 193:
189: sampleI = analogRead(inPinI)
191: // Digital low pass filter extracts the 2.5 V or 1.65 V dc offset,
192: // then subtract this - signal is now centered on 0 counts.
193: offsetI = (offsetI + (sampleI-offsetI)/1024);
194: filteredI = sampleI - offsetI;
I believe that the factor should be 4096 for a 12 bit ADC. Probably better should be “ADC_COUNTS” which is defined as
// to enable 12-bit ADC resolution on Arduino Due,
// include the following line in main sketch inside setup() function:
// otherwise will default to 10 bits, as in regular Arduino-based boards.
#define ADC_BITS 12
#define ADC_BITS 10
#define ADC_COUNTS (1<<ADC_BITS)
What am I overlooking?