Input current on A0 higher as soon as I read A1

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Input current on A0 higher as soon as I read A1

Post by petergebruers »

I am new to Z-Uno so I may be doing something wrong.

When i use the ADC on A0 it has a very high impedance. As soon as I use the multiplexer, input current is much higher. Am I doing something wrong, or is something on the Z-Uno switching input mode of the pin? Like, accidentally turning on the weak pull-up?

Here's runnable code to reproduce the problem:

Code: Select all

// petergebruers analog input current test.
// connect uA meter and a 1k resistor between A0 and ground.
// Observe current is < 1 uA and measurement is correct
// Then uncomment the line // analog1 = analogRead(A1);
// Observe current is 26 uA so a voltage of 26 mV develops
// across the resistor and the measurement changes.
// Z-Uno 2.1.1

#define SENSOR_MULTILEVEL_SCALE_MILLIVOLT 0x01

ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_MULTILEVEL(
    ZUNO_SENSOR_MULTILEVEL_TYPE_VOLTAGE,
    SENSOR_MULTILEVEL_SCALE_MILLIVOLT,
    SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
    SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS,
    Analog0getter));

void setup() {
  analogReference(INTERNAL);
  Serial1.begin();
}

uint16_t analog0, analog1;
void loop() {
  analog0 = analogRead(A0);
  Serial1.println(analog0);
  // UNCOMMENT next to observe higher input current.
  // analog1 = analogRead(A1);
}

int16_t Analog0getter(void) {
  return 0; // not important.
}
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Input current on A0 higher as soon as I read A1

Post by p0lyg0n1 »

I check it asap. What is the purpose to use the internal voltage reference(1.2V)? Did you see the same behavior in previous versions?
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Input current on A0 higher as soon as I read A1

Post by petergebruers »

Someone on the Fibaro forum needs a Z-Wave 0-10 V input. He tried a Fib RGBW but it does not meet his expectations. So he asked if someone could design a Z-Uno based solution, I joined the discussion, but clearly stated I am not a professional (but also an "enthousiast")... This is the first time I used the ADC, that is why I started by doing some simple checks.

I use the internal reference to get started with minimal cost and components, just to see how good it is.

The discussion and final application specification can be found here:

https://forum.fibaro.com/index.php?/top ... ut-device/

Is this enough background information?
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Input current on A0 higher as soon as I read A1

Post by p0lyg0n1 »

Oh, I see.
I think that I can make a small example for you and I will test ADC using it. I'll try to do it tomorrow, but I have a lot of work... May be I need a couple of days... I can give you a brief list of principles first.
So, first of all you have to use a voltage divider to scale output of sensor 0-10V to 0-3V(default settings of ADC) or to 0-1.2V(as in your example, if you use INTERNAL ref). If you don't need a battery power device you don't need to use internal reference because you are already have a stable voltage on 3v pin(or 5v, or Vin) from your power supply(you have to measure it value to take a precise result). Voltage divider consists of two resistors. Let say we connect them this way: Sensor10v_out-R1-A0pin-R2-GND. We have to reduce the current, so R1+R2 = 100KOhms will be enough, 10V/(100KOhm) = 100uA. Then we have to scale the voltage right way. In case 0-3V we have R1=70KOhm, R2=30KOhm. Then we have to calculate the voltage value using value that we got from ADC:

Code: Select all

#define REF_VOLTAGE 3000 // in mVolts use precise value, mesure it from 3v pin
#define DIVIDER_R1 70 // you have to mesure it too, just fractions without units
#define DIVIDER_R2 30
#define ADC_MAX     4095 //we use 12 bit resolution
//... 
// setup maximum resolution for z-wave chip - 12 bits
analogReadResolution(12);
dword calculated_voltage = REF_VOLTAGE;
calculated_voltage *= analogRead(A0);
calculated_voltage /= ADC_MAX;
calculated_voltage *= (DIVIDER_R1+DIVIDER_R2);
calculated_voltage /= DIVIDER_R2;
Fix me;) It's just an illustration of idea;)
Be careful! Check twice all values before connect divider to Z-Uno, measure them with voltmeter first! 10v connected directly will burn your Z-Uno!
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Input current on A0 higher as soon as I read A1

Post by petergebruers »

Thanks for reading that long topic on the Fibaro forum and answering in detail. So the only remaining issue is the input buffer current.

First, I have to clear up some confusion. I have no issues with the hardware, nor with the software aspect of this project. Long time ago I worked as a test engineer, I wrote programs to test the specs of analog and mixed signal chips... But I am not sure about the other people involved in that topic, so I really appreciate it when you go through the basics! And I'm also fairly new the Z-Uno so I appreciate this too!

Also, thank you for planning a test to investigate the input issues when more than 1 input gets sampled. The OP needs more than 1 input so this is important to him. He can work around the issue by adding buffer(s) or a multiplexer but this would increase complexity.

I wonder why you suggest to use the Z-Uno Voltage regulator... There is a diode between the 3V3 regulator and the SoC so I expect the VCC to be noisier, more variable and less accurate than the 1.25 V reference. Did I miss something? Is there any particular reason why you do not like the internal reference? Remember, the OP is going for at least 1024 significant bits in this case (maybe at 12 bit resolution) and he'd like to get 0.1 % accuracy as well...

Regarding divider: you say: "R1+R2 = 100KOhms will be enough, 10V/(100KOhm) = 100uA." At room temperature, I measure < 1 uA input current to the ADC so I agree. But the Spec of the chips says +/- 10 uA so in that case the input current would cause too much loading of the divider and I would not get accurate results. I'll do more tests to confirm the value of the leakage on 1 input but at higher temperatures, the spec might be too pessimistic.

I also connected a ADS1115 delta-sigma 16-bits ADC (so integrating type). Costs a few $ on a breakout board. If you are interested, I'll turn it into a complete solution and post it here so you can link to it on your website.

Datasheet:

http://www.ti.com/lit/ds/symlink/ads1114.pdf

This chip is a much better solution for this particular application (measuring 0-10 V of existing tank pressure and temperature sensors).

I did some basis measurements and it beats the built-in ADC by an order of magnitude on several aspects.

- Extremely easy to use. Requires almost no code (only send a few commands over I2C).
- 4 single ended inputs (or 2 differential).
- 15 bits resolution + sign bit (= 16 bits in total).
- IT automatically averages the input. No math/loop/time/sampling needed.
- It does not keep the Z-Uno busy
- 8 -> 868 samples per second.
- built-in programmable gain amplifier.
- built-in reference.

I'm not from Ti, I do not gain anything by saying this!

I think this chip beats the Z-Uno ADC any time you need to sample signals below 400 Hz... And if the Z-Uno input current issue cannot be solved, I would certainly use this chip instead of adding buffers or other stuff... What do you think?

Are you interested in a comparison between this ADS1115 and the built-in ADC? In that case, I'll take some extra measurements and produce a nice document. Just ask and then give me a few days...

Again, thank you for your fast and to-the-point answers. I think this is a strong selling point of the Z-Uno.

EDIT: the original breakout board from Adafruit:

https://www.adafruit.com/product/1085
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Input current on A0 higher as soon as I read A1

Post by PoltoS »

Z-Uno is certainly not he best ADC chip. Sure comparison with a specialised chip is interesting.

Please keep in mind that the 1.21 V have about 10% deviation from chip to chip. You need to apply calibration. Once done, it will be about 1% accuracy
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Input current on A0 higher as soon as I read A1

Post by p0lyg0n1 »

Thank you, Peter. I am sorry for "basics" in the previous post. I didn't understand the main problem deep enough. It's an interesting challenge for us anyway. We don't use ADC very often in our projects. It looks that we have to dig deeper ;-) The time has come. It will be cool if you create a library for ADS1115. I have one on a breakout board, so I can test it too :) I think that we have to understand the limits of builtin ADC too. It's very useful for many project to use builtin features for 100%. So, I need a little time for my experiments. I'll keep you posted. Thank you once more. We are deep inspired by your activity!
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Input current on A0 higher as soon as I read A1

Post by petergebruers »

p0lyg0n1 wrote:
26 Oct 2017 12:32
(...)
It will be cool if you create a library for ADS1115.
(...)
I take the challenge! Give me some time!

There is an Adafruit library, but I do not use it. I think it is too simplistic and does not expose enough of the devices' capabilities. I hope I do not offend anyone by saying so. But "squeezing" this ADC into something like "analogRead" does not do justice of the device... I used the library once, on my Arduino, but I haven't even tried it on my Z-Uno... At the moment I use some basic code in my sketch, dedicated for some experiments. I have some ideas on how to turn that sketch into something more general and more useful.

I've just ordered an extra board, I'll let you know if it is a good one when it arrives:

https://www.aliexpress.com/item/ADS1115 ... 96242.html?

In the meantime, I am gathering some performance parameters (statistical analysis) of the Z-Uno ADC and its internal reference. It is to soon to paste data, I need a few more days.
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Input current on A0 higher as soon as I read A1

Post by p0lyg0n1 »

It sounds great. I don't have a time to check your example on the hardware myself, but I have a little time to refresh some info from datasheet and look into code. So, there are some new data:
1. ADC0(VRef+) & ADC1(VRef-) can be used as voltage references. May be it's a side affect of this. Code looks absolutely right, but it may be. You can check that using this code: analogReference(ADC_HIGH_EXTERNAL | ADC_LOW_EXTERNAL) = ADC0 is Vref+, ADC1 is Vref-, analogReference(ADC_HIGH_EXTERNAL | ADC_LOW_GND) = ADC0 is Vref+, GND is Vref-. Can you reproduce the same wrong behavior using ADC2/ADC3 instead of ADC1?
2. The datasheet said that you can check the behavior of the ADC inputs using auto-zero option: the high values recommended for high-impedance sensors, the low values for low-impedance sensors (it wasn't documented yet, but you can try to use this): zunoADCAdvConfig() with one of these flags(listed in ZUNO_Definitions.h):ZUNO_ADC_ADV_AZP128,ZUNO_ADC_ADV_AZP256,ZUNO_ADC_ADV_AZP512,ZUNO_ADC_ADV_AZP1024. Example: zunoADCAdvConfig(ZUNO_ADC_ADV_AZP1024);
3. You can enable internal buffering between input and ADC using this (it wasn't documented too):
zunoADCAdvConfig(ZUNO_ADC_ADV_BUFFERED); If you want to use both options they could be ored like this: zunoADCAdvConfig(ZUNO_ADC_ADV_BUFFERED| ZUNO_ADC_ADV_AZP256);
We have a big & deep challenge with S2 and I think that I could check ADC myself only in two weeks :(.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Input current on A0 higher as soon as I read A1

Post by petergebruers »

Just a quick update. I have done some characterisation of the built-in ADC under different conditions (USB power, battery) but it is not ready for publishing. I have not yet toyed with the advanced settings because I needed a "baseline performance" before I could start the ADS1115 library and comparison. Unfortunately I have a very busy week, so progress is slow. If anyone is interested in preliminary results, please contact my via PM!

Just wanted to say this, so you know I am still working on these projects!
Post Reply