Z-Wave-Me / Z-Uno-Core

Core files for Z-Uno support in Arduino IDE 1.6.5
21 stars 12 forks source link

ADC give sometimes wrong value (from other channel) #109

Closed michapr closed 7 years ago

michapr commented 7 years ago

I was using the ADC and was confused about the error rate (wrong given values). That's why I tried to isolate the problem.

Made a simple sketch using 4 different analog inputs: ADC0 - reference voltage source ADC1 - 50% VCC output ADC2 - 50% 5V output ADC3 - 1.5V battery

Made > 7500 loops reading the values ADC0;ADC1;ADC2;ADC3. Right values like this:

412;589;798;536
412;588;796;537
412;587;798;537

I got for the reference voltage (ADC0) following result:

value    410     411     412     413     414     415     416     417     534     535     536     537     538     539     540
number   41  629     2872    2388    678     749     119     1   1   6   25  12  3   9   2

checking this I have seen such lines:

413;589;796;537
537;590;798;537
413;588;797;537
...
412;586;799;536
536;589;797;536
413;588;800;962
...

Seems value from last ADC3 was returned for ADC0 !

To be sure I have set the value for ADC3 to 0V (GND) and checked again:

412;589;799;0
0;587;798;0
413;589;800;0
...
412;588;798;0
0;588;799;0
412;589;800;0

Additional have got some (not only a few) strange results for ADC3 (connected to GND):

412;589;800;0
412;589;799;404
412;586;799;0
...
412;588;800;0
412;587;798;963
412;590;799;0

Then have removed the reading of ADC3 (no difference set the pin to input or not) - result:

412;589;798;
965;587;799;
412;588;800;
....
412;590;798;
964;589;797;
414;589;798;

"964" is wrong - of course... taken from ADC3 - see before

So I think something is there wrong with any registers reading the values from ADC, depending on what - no idea...

ADC can not be used without any error correction in this time - must be checked multiple times for getting a reliable result.

Code as reference is attached - the setting back to input mode is from other sketch - it must be used, because of after analogRead the port will be set to output and give back to ADC source a high level voltage...

ZUNO_ADC_test.txt

Michael

PoltoS commented 7 years ago

Fixed in 2.0.9