-->
Page 1 of 3

code for correcting non-linearity

PostPosted: Wed Sep 16, 2015 8:34 am
by mpeg42
The analog input of the ESP8266 ist absolute non-linear.
Now i look for a little programm to correct this.

Here are my measurements:

0.0V - 5
0.1V - 195
0.2V - 338
0.3V - 463
0.4V - 555
0.5V - 643
0.6V - 714
0.7V - 782
0.8V - 842
0.9V - 900
1.0V - 952

thanks for your tips.

Re: code for correcting non-linearity

PostPosted: Wed Sep 16, 2015 9:05 am
by martinayotte
According to this graph, it should be pretty linear, except near the far boundaries :

wiki/lib/exe/fetch.php?media=essp8266_adc.png

Image

Re: code for correcting non-linearity

PostPosted: Wed Sep 16, 2015 10:09 am
by pvvx
Your measurements are not true.

SDK is not a linear ADC
Espressif uses primitive correction:

Correction adders z - 21:

Code: Select allvoid read_sar_dout(uint16 * buf)
{
   volatile uint32 * sar_regs = &SAR_BASE[32]; // 8 regs 0x60000D80...
   int i;
   for(i = 0; i < 8; i++) {
      int x = ~(*sar_regs++);
      int z = (x & 0xFF) - 21;
      x &= 0x700;
      if(z > 0) x = ((z * 279) >> 8) + x;
      buf[i] = x;
   }
}



The sum of eight values:

Code: Select alluint16 sar_dout, tout, sardata[8];

   read_sar_dout(sardata);

    for (i = 0; i < 8; i++) {
        sar_dout += sardata[i];
        ADC_DBG("%d, ", sardata[i]);
    }


tout = (sar_dout + 8) >> 4; // tout is 10 bits fraction

Image
Riso, Сiso ?

Re: code for correcting non-linearity

PostPosted: Wed Sep 16, 2015 11:30 am
by martinayotte
pvvx wrote:Your measurements are not true.


@pvvx, no problems, it is not my measurements, it is a graph provided in the Wiki, link provided...
(Personally, I didn't experiment the ESP internal ADC at all ... ;) )