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?
GetADC returning odd value
GetADC returning odd value
- Attachments
-
- Read_Air_temp_Sensor.bas
- (1.34 KiB) Downloaded 591 times
Re: GetADC returning odd value
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.Chuckh wrote:Any ideas what I'm doing wrong?
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
- Don Kinzer
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?
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?
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.icasey wrote:Any ideas what I may be doing wrong?
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