# linearity problem with the ADC on a 20x2 chip

#### cravenhaven

##### Senior Member
I have a linearity problem with the ADC on a 20x2 chip.

The basic test circuit is shown below and consists of a 10K 25turn trimpot connected between V+ and ground, and the wiper connected to the adc pin via either a 100ohm or 5k6 resistor.
I am monitoring the output of the ADCs at a set range of voltages as measured by my digital multimeter (a low cost model), but notice that at the bottom of the scale the voltage and the ADC outputs become nonlinear.
The relevant code segments are attached.

Code:
``````main:
pause 2000
goto main
end

TempW3=TempW2/100
IF TempW3>\$FF THEN
Temp1=TempW3/10
GOSUB Displ_Byte
Temp1=TempW3//10
ELSE Temp1=TempW3
ENDIF
GOSUB Displ_Byte
SERTXD(".")
Temp1=TempW2//100
GOSUB Displ_Byte
RETURN

Displ_Byte:
BINTOASCII Temp1,hundr,tens,units
IF hundr = "0" THEN
hundr = ""
IF tens = "0" THEN
tens = ""
ENDIF
ENDIF
SERTXD( hundr, tens, units, " ")
RETURN``````
As you can see in the excel picture the readings become quite nonlinear near the bottom of the range.

#### Attachments

• 65.1 KB Views: 40
• 4.3 KB Views: 31

#### hippy

##### Senior Member
Is it not simply the case that the bottom axis of your graph is non-linear ?

#### MartinM57

##### Moderator
But your graph is non-linear in the x-axis itself - you have constant x-direction gaps between your data points, but the points themselves are not linear. You need to plot again with a linear x-axis.

Looking at the numbers they look pretty linear e.g. 0.25v = 47; 2.5v = 478 etc

#### cravenhaven

##### Senior Member
Thanks for that. I was concentrating on the picture too much. I finally found the correct graph type in excel and the data does indeed look quite linear

#### SAborn

##### Senior Member
I dont see where you have set the ADC pin in code for a ADC input, this could cause the problem you have, (been there and forgot to do it also).

Once you set the input for ADC i think the problem will go away.

#### cravenhaven

##### Senior Member
I have an initialisation section that sets up the adc channels as well as Symbols for defining the actual channels. The program is quite large (3500 bytes so far) so I just put in what I considered the most appropriate.

Code:
``````SYMBOL Solar_in		=5		;ADC5 pin B.3. NB 20X2 requires numeric ADC number rather than pin number
SYMBOL BattI_in		=6		;ADC6 pin B.4
SYMBOL BattV_in		=11		;ADC11 pin B.6