GetADC returning odd value

Discussion specific to the 24-pin ZX microcontrollers, e.g. ZX-24r, ZX-24s and ZX-24t.
Post Reply
Chuckh
Posts: 1
Joined: 25 September 2013, 15:43 PM

GetADC returning odd value

Post by Chuckh »

Newbe needs help!

I am new to using microprocessors and having trouble understanding what I'm doing wrong. I have a ZX24s processor and am trying to read the output of the ADC pin and convert to actual volts. I can read the value at the pin and get .773vdc but the pin return calculates at .734vdc approx. I have tried any number of changes to the code but am clearly missing something. I have added several calls to see if there are and changes but they all return the same value. Any ideas what I'm doing wrong?
Attachments
Read_Air_temp_Sensor.bas
(1.34 KiB) Downloaded 591 times
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: GetADC returning odd value

Post by dkinzer »

Chuckh wrote:Any ideas what I'm doing wrong?
As always, it is best to remove as many variables as possible. For example, connect the wiper of a potentiometer to a pin with the other terminals connected to Vcc and ground. This will allow you to vary the analog input over the range and then, using a simple program, output the result of the ADC conversions.

The example program below allows one to test both the function form and the subroutine form of GetADC(). You can comment/uncomment the #define to control which form is used.

Code: Select all

Const pin as Byte = 13

'#define USE_FUNCTION_FORM

Sub Main()
    Do
#if defined(USE_FUNCTION_FORM)
        Dim i as Integer
        i = GetADC(pin)
        Debug.Print i
#else
        Dim f as Single
        Call GetADC(pin, f)
        Debug.Print Fmt(f, 3)
#endif
        Call Sleep(1.0)
    Loop
End Sub
Once you have this simple program running and understand the results, you can then add code to convert the ADC conversion to a voltage.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

it is worth noting the time getadc takes to execute as its relatively significant, and if you try and execute another getadc (via a task) before one complete you get inconsistent results.

took me a while to find my issue on that one !
icasey
Posts: 5
Joined: 13 June 2014, 22:03 PM

Post by icasey »

Don,
I'm using your simplified code you posted above.
I am having a similar problem with the ZX24U as I wanted the 12 bit resolution, right now I am using pin 19 and have it grounded.
My results are between 178 - 187 with i = GetADC(pin) or 0.042 - 0.046 with Call GetADC(pin,f).

I have another connection on pin 20 with a pot 0 - 2.5v.
mV at pin20, reading
0, 403-408
100, 573
500, 1240
1000, 2072
1500, 2250
2000, 3746
2210, 4094
The high reading sounds correct but obviously the 0mV reading is off.
Any ideas what I may be doing wrong?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

icasey wrote:Any ideas what I may be doing wrong?
On xmega devices, the analog input range is 0 to Vcc/1.6. Assuming that you're running it at 3.3 volts that makes the maximum analog voltage slightly more than 2 V.

As for the low end, the xmega devices have a pronounced offset voltage (more so than the mega and tiny devices). You can calibrate your particular device by performing an ADC conversion using a grounded input. That reading (or the average of several) should then be subtracted from subsequent readings to remove the effect of the offset. Note that you should be careful to consider any value less than the offset to be zero.
- Don Kinzer
icasey
Posts: 5
Joined: 13 June 2014, 22:03 PM

Post by icasey »

Thanks Don
I got it worked out, 405 counts seems a little high for an offset.

Would I need to calibrate every zx24 with a different set of values?
The 2 I have here seem to be identical, but I guess that could change from different batches.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

icasey wrote:Would I need to calibrate every zx24 with a different set of values?
The offset for dies from the same wafer are probably pretty close if not identical. However, the offset may vary from wafer to wafer meaning that for any two devices it may be different.
- Don Kinzer
Post Reply