Arduino nano A2D
subject: arduino nano a2d accuracy
implementation:
i have battery of 8 x 4.2v li-ion cells wired in series
each cell junction connected potential divider output of drives analogue input pin of arduino nano
to compensate resistor , other errors unit calibrated providing reference voltage each input volts per bit can calculated , stored in eeprom use in later calculations. calibrated a2d reference voltage stored. reference voltage provided in increments of 4.0v so:
4, 8, 12, 16, 20, 24, 28, 32
the run time code crude:
correctedvoltagearray[0] = (rawbinaryarray[0] * voltsperbitarray[0]); // once
for(j=1; j <= 7; j++) // 7 times
{
correctedvoltagearray[j] = ((rawbinaryarray[j] * voltsperbitarray[j]) - (rawbinaryarray[j - 1] * voltsperbitarray[j - 1])); // calculate individual cell voltages
}
ok. yes works if there 1 bit error in top voltage reading result in 1 x voltsperbitarray[7] final error.
explanation:
lets call cell tapping voltages a, b, c, d, e, f, g, h
lets assume each tap 4.0v
they increase 4 @ each tap:
a = 4
b = 8
c = 12
d = 16
e = 20
f = 24
g = 28
h = 32
using formula (cell voltage cv = (this cell voltage - lower cell voltage)) cell h = h - g result cv = 4
if h has +1 bit error volts per bit z result cv = (4 + z)
this 'real' calculated data example:
cell voltage 1 4.187773 raw = 959 v/b = 0.004367
cell voltage 2 4.195252 raw = 963 v/b = 0.008705
cell voltage 3 4.177235 raw = 964 v/b = 0.013029
cell voltage 4 4.211671 raw = 956 v/b = 0.017544
cell voltage 5 4.214136 raw = 979 v/b = 0.021436
cell voltage 6 4.220350 raw = 982 v/b = 0.025668
cell voltage 7 4.208635 raw = 977 v/b = 0.030108
cell voltage 8 4.225077 raw = 964 v/b = 0.034896
the above cell voltages when checked dvm 4.21v
i try different approach:
cv = (thisvoltage + sum(lowervoltages)) / cellfactor;
so:
resulta = (a)/1;
resultb = (b + a)/3;
resultc = (c + b + a)/6;
resultd = (d + c + b + a)/10;
resulte = (e + d + c + b + a)/15;
resultf = (f + e + d + c + b + a)/21;
resultf = (g + f + e + d + c + b + a)/28;
resultf = (h + g + f + e + d + c + b + a)/36;
limitations:
i realise not eliminate errors may give me results nearer true values. in event keen see effect be.
problem:
i don't know how turn above algorithmic expression. yes have series of calculations should possible have one.
questions:
1. going off rails here?
2. there better approach?
3. can write loop above?
finally - thank if far.
brian
implementation:
i have battery of 8 x 4.2v li-ion cells wired in series
each cell junction connected potential divider output of drives analogue input pin of arduino nano
to compensate resistor , other errors unit calibrated providing reference voltage each input volts per bit can calculated , stored in eeprom use in later calculations. calibrated a2d reference voltage stored. reference voltage provided in increments of 4.0v so:
4, 8, 12, 16, 20, 24, 28, 32
the run time code crude:
correctedvoltagearray[0] = (rawbinaryarray[0] * voltsperbitarray[0]); // once
for(j=1; j <= 7; j++) // 7 times
{
correctedvoltagearray[j] = ((rawbinaryarray[j] * voltsperbitarray[j]) - (rawbinaryarray[j - 1] * voltsperbitarray[j - 1])); // calculate individual cell voltages
}
ok. yes works if there 1 bit error in top voltage reading result in 1 x voltsperbitarray[7] final error.
explanation:
lets call cell tapping voltages a, b, c, d, e, f, g, h
lets assume each tap 4.0v
they increase 4 @ each tap:
a = 4
b = 8
c = 12
d = 16
e = 20
f = 24
g = 28
h = 32
using formula (cell voltage cv = (this cell voltage - lower cell voltage)) cell h = h - g result cv = 4
if h has +1 bit error volts per bit z result cv = (4 + z)
this 'real' calculated data example:
cell voltage 1 4.187773 raw = 959 v/b = 0.004367
cell voltage 2 4.195252 raw = 963 v/b = 0.008705
cell voltage 3 4.177235 raw = 964 v/b = 0.013029
cell voltage 4 4.211671 raw = 956 v/b = 0.017544
cell voltage 5 4.214136 raw = 979 v/b = 0.021436
cell voltage 6 4.220350 raw = 982 v/b = 0.025668
cell voltage 7 4.208635 raw = 977 v/b = 0.030108
cell voltage 8 4.225077 raw = 964 v/b = 0.034896
the above cell voltages when checked dvm 4.21v
i try different approach:
cv = (thisvoltage + sum(lowervoltages)) / cellfactor;
so:
resulta = (a)/1;
resultb = (b + a)/3;
resultc = (c + b + a)/6;
resultd = (d + c + b + a)/10;
resulte = (e + d + c + b + a)/15;
resultf = (f + e + d + c + b + a)/21;
resultf = (g + f + e + d + c + b + a)/28;
resultf = (h + g + f + e + d + c + b + a)/36;
limitations:
i realise not eliminate errors may give me results nearer true values. in event keen see effect be.
problem:
i don't know how turn above algorithmic expression. yes have series of calculations should possible have one.
questions:
1. going off rails here?
2. there better approach?
3. can write loop above?
finally - thank if far.
brian
subject: arduino nano a2d accuracyif donno answer questions 1 , 2 qn 3 implement following loop:
cv = (thisvoltage + sum(lowervoltages)) / cellfactor;
so:
resulta = (a)/1;
resultb = (b + a)/3;
resultc = (c + b + a)/6;
resultd = (d + c + b + a)/10;
resulte = (e + d + c + b + a)/15;
resultf = (f + e + d + c + b + a)/21;
resultf = (g + f + e + d + c + b + a)/28;
resultf = (h + g + f + e + d + c + b + a)/36;
3. can write loop above?
code: [select]
uint8_t cellfactor[8] = {1,3,6,10,15,21,28,36};
float cv;
cv = thisvoltage; //thisvoltage converted ad input i'm assuming
for(uint8_t i=1;i<8++i){
cv = (thisvoltage +(cv*cellfactor[i-1]))/cellfactor[i];
}
Arduino Forum > Using Arduino > Programming Questions > Arduino nano A2D
arduino
Comments
Post a Comment