## ADC far too random and imprecise

ADC far too random and imprecise, the code section on ADC measurements: (mesure ADC trop aleatoire et imprecise, la partie concernant les mesures ADC :)

```#define      __Time_tic_in_Second__      0.1

Ticker time_tic;

{
int i;

Seconds = Seconds + (float)__Time_tic_in_Second__;

meas = meas * 3300.0; // Change the value to be in the 0 to 3300 range
...
}

int main()
{
...
// Init the ticker with the address of the function (add_one_second) to be attached and the interval (100 ms)
...
}

```

The material used is a map NUCLEO F411RE & A map ENC28J60.

where have the cause of its precision errors? if you have an idea I'm interested;) (d'où viens la cause de ses erreurs de precision ? si vous avez une idee je suis preneur ;) )

Please use `<<code>> and <</code>>` around your code to make it readable. Also can you show a pic how you wired it, and what you are measuring with your ADC?

posted by Erik - 05 Aug 2015

##### 5 years ago.

The another software solution to the problem is getting RMS (Root Mean Square) of the at least 50 ADC reading of each channel (100 is far enough)... Get 50 reading and add it to an array... and then calculate RMS...So we could get the very stable ADC values without any hardware modification or etc..

link to RMS information is https://en.wikipedia.org/wiki/Root_mean_square

How is that any better than taking the mean of a 50 readings? The values are all positive numbers, RMS is normally only used when you have a mixture of positive and negative values.

Either way, when calculating an average (or RMS) it's far more efficient to keep a single variable of the running total of all the values added together rather than logging the values into an array and then adding the contents of the array. The only time logging the individual values is of benefit is if you need to calculate the standard deviation.

posted by Andy A 06 Aug 2015

And what Andy describes is a first-order IIR low-pass filter, which indeed rejects high frequency disturbances.

posted by Erik - 06 Aug 2015

A code example of RMS for your needs.

```// RMS calculation of analogical channel measurements
memset(rms_store, 0, sizeof(rms_store));
//analog_power_pin = 1;
wait_ms(10);
for (b = 0; b < RMS_SAMPLING_NUMBER; b++) {
rms_store[b] = temp_value * temp_value;
total_sampling = total_sampling + rms_store[b];
temp_value = 0;
}
//analog_power_pin = 0;
sensor_values[a] = (sqrt ((float)((total_sampling / RMS_SAMPLING_NUMBER)))) * 4095;
total_sampling = 0;
// End of RMS calculation
```

sensor_values array can be modified for your needs..

Regards...

posted by Kamil M 17 Aug 2015
##### 5 years ago.

Did you have a look at his?