9 years, 4 months ago.

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;

void add_one_tic()
{       
 int i;
 
 Seconds = Seconds + (float)__Time_tic_in_Second__;
 
 // mesures ADC
    meas = a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
    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)
 time_tic.attach(&add_one_tic, __Time_tic_in_Second__);
...
}

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 ;) )

ADC problem concerning this source code: https://developer.mbed.org/users/Fo170/code/Nucleo_Web_ENC28J60_ADC/

but also : https://developer.mbed.org/users/Fo170/code/Nucleo_Web_ENC28J60/

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

2 Answers

9 years, 4 months 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

Accepted Answer

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++) {
                    temp_value = sensor_pin[a].read();
                    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
9 years, 4 months ago.

Did you have a look at his?

https://developer.mbed.org/users/chris/notebook/Getting-best-ADC-performance/

thank you for your response, against the meantime I measure 0-3,3V line and I watched the ripple on food, ENC28J60 card must consume too on the 3.3V regulator Nucleo map , it is strongly involved in measurement problem.

posted by FOURNET Olivier 06 Aug 2015