Author Topic: Questions about using uCurrent with Arduino Analog Input  (Read 5231 times)

0 Members and 3 Guests are viewing this topic.

Offline peter64Topic starter

  • Newbie
  • Posts: 7
  • Country: jp
Questions about using uCurrent with Arduino Analog Input
« on: July 27, 2015, 07:17:29 am »
Hello EEVblog,

This is my first post so please let me know if I make any mistakes or I need to provide additional details.

I recently purchased two uCurrents with the intention to use them as inputs for arduino analogue inputs.
I am attempting to make a simple calorimeter to attempt to measure the thermal output of resistors as a small project.
I was hoping to use the arduino to measure the temperature of various parts of the calorimeter in conjunction with the current and voltage across the load.
From all this data I was going to attempt determine calibrate my calorimeter based on the input power and the output thermal heat.

The specifics of my setup are as follows:

An Arduino Due power from 8AA batteries.
4 LM35D temperature sensors wired to A0-A3 powered from 5v and attached to the Arduino 5vGND
A uCurrent to measure the current flowing through Rload in mA or uA and convert to a voltage I can use on the Arduino analog input.
Rload is being powered from an independent 9V battery but I am also using a voltage divider with various points to tap into to provide various voltages to the Rload used to calibrate the calorimeter.
The uCurrent has its negative voltage terminal wired to the 5vGND (I've also tried the 3.3vGND as well) and the positive terminal wire to the arduino analog input. The current inputs are in line with Rload.

The good news is that the uCurrent provides me with the correct current value (or sufficiently close to it).
The bad news is that every time I change the voltage over Rload it seems to bias the temperature reading on my sensors by a large margin.
I've attached a screenshot of a chart showing my 4 temperature sensors readings temp0-temp3 connected to A0-A3 respectively (in degrees C).
It also has current4 which is the current in micro amps.
Prior to hooking up the uCurrent the temperature sensors did not change in the fashion they now are when current went through Rload.
They would increase steadily based on the actual heat.

The effect on the temperature sensors appears to be most concentrated in temp0 (corresponding to A0).
The other sensors also fluctuate but no where near the same degree.
When I use a DMM to measure current there is no similar fluctuation.

I'm sure I'm missing something fundamental regarding the operation of the uCurrent and how it is working in my system.
Let me know if there are any additional details I can provide.
Any help would be appreciated.

Peter
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 18880
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #1 on: July 27, 2015, 07:37:25 am »
Hello Peter, I've not fully understood your setup. You say something about using a voltage divider to get different voltages from the 9V battery, you are aware of course that this is bad practice unless you are drawing small currents else the load has an effect on your divider. The uCurrent will still have a burden voltage albeit much lower.

Also be careful of the power switch, if you pull it all the way down it will short the input, this is so that you can change range without interrupting your circuit. So if your changing range you flick the power switch to short, change the range switch and then switch back again to normal on position.
 

Offline peter64Topic starter

  • Newbie
  • Posts: 7
  • Country: jp
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #2 on: July 27, 2015, 08:11:30 am »
Thanks Simon for your fast reply.

I've attached an image of a circuit diagram that will hopefully help show what I'm doing. One thing to add is that the uCurrent is being powered by a separate 3V c2032 battery.
I'm just having difficulty understanding why having the uCurrent in the circuit at all should effect the temperature sensors.
I could understand if it had a burden load which resulted in a change of the power dissipated by Rload. But I can't understand why it would have any effect on the Arduinos other analog inputs.
Let me know if I can provide any further details to help you understand the issue better.
The current flowing through Rload is some where in the order of 1mA so I think it should be ok.

Thanks again,

Peter
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 18880
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #3 on: July 27, 2015, 11:50:39 am »
I see your problem, remember that the two negative sockets on the uCurrent are connected together so you have the negative current sense on the positive side of your load, this is basically connecting the positive side of your load to GND. It would be better to put the ucurrent on the negative side of the load.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 18880
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #4 on: July 27, 2015, 11:51:39 am »
having said that the uCurrent is as you say on it's own battery and the load is also on it's own battery
 

Offline peter64Topic starter

  • Newbie
  • Posts: 7
  • Country: jp
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #5 on: July 27, 2015, 12:21:17 pm »
Thanks again Simon for your help.
I tried as you said to put the uCurrent after the load. It didn't appear to have any effect. I included my logged data below.
I wonder if the uCurrent needs to have it's battery negative tied to the same Arduino Due 5VGND that the uCurrent V- is tied too, so it isn't floating any more.
Would that break the uCurrent if I tried that and if not, is there any reason to think it might help?

Quote
time    temp0           temp1           temp2           temp3           current4        err0            err1            err2            err3            err4
229336  29.343433       28.857334       28.579510       28.849855       0.000000        0.317500        0.308601        0.323257        0.310321        0.000000
234116  29.334152       28.851030       28.575659       28.841675       0.000000        0.327959        0.310076        0.321073        0.294517        0.000000
238893  29.338396       28.855375       28.579107       28.840868       0.000000        0.329751        0.309175        0.328779        0.317640        0.227987
243671  29.341028       28.853464       28.577457       28.842718       0.000000        0.327039        0.304995        0.323326        0.294237        0.000000
248449  29.344261       28.856100       28.582176       28.843372       0.000000        0.322786        0.317060        0.325320        0.309155        0.000000
253227  29.342978       28.857992       28.583624       28.839863       0.000000        0.351893        0.333925        0.348081        0.328075        0.000000
258007  29.311380       28.866980       28.588503       28.850607       36.010098       0.357921        0.349244        0.362068        0.352793        2.841769
262792  28.930332       28.862734       28.584146       28.841114       570.854797      0.320935        0.308107        0.326108        0.313855        3.442075
267576  28.932671       28.865347       28.589710       28.840136       570.772522      0.328683        0.299575        0.335922        0.299966        3.387500
272360  28.935057       28.864100       28.586655       28.836065       570.695129      0.327969        0.308744        0.328548        0.317520        3.260786
277145  28.930422       28.861807       28.582153       28.832634       570.630249      0.367748        0.344373        0.358231        0.349072        3.226588
281929  29.295176       28.867884       28.588062       28.839172       50.353432       0.364319        0.327630        0.364154        0.343489        0.000000
286714  28.742136       28.861727       28.586176       28.831633       641.664795      0.330011        0.312591        0.332994        0.315316        3.133500
291498  28.649036       28.857178       28.583218       28.822632       780.325562      0.313198        0.296330        0.317620        0.305172        3.264478
296282  28.646246       28.858217       28.580851       28.817091       780.239807      0.333041        0.317500        0.329184        0.316980        3.262438
301067  28.650715       28.861708       28.582701       28.816288       780.229431      0.323610        0.321527        0.334684        0.320233        3.500690
305851  28.649441       28.856466       28.575644       28.810846       780.136902      0.383997        0.344042        0.385019        0.362260        3.298476
310633  29.083496       28.867601       28.581406       28.817776       235.753998      0.360365        0.341258        0.365518        0.353484        0.000000
315415  29.354816       28.872562       28.586077       28.824440       0.000000        0.367006        0.316890        0.370590        0.351082        0.000000
320198  29.353182       28.876703       28.586384       28.819378       0.000000        0.367127        0.316550        0.358027        0.338890        0.000000
324978  29.362627       28.879230       28.591002       28.822838       0.000000        0.378468        0.335006        0.376226        0.357079        0.000000
329763  28.792772       28.863737       28.603878       28.801516       880.292358      0.383931        0.323189        0.351406        0.326981        3.847636
334550  28.667496       28.854605       28.604349       28.790716       1127.023193     0.383716        0.313057        0.343867        0.317660        3.858904
339335  28.662601       28.851376       28.598843       28.783623       1126.843628     0.375534        0.309994        0.349035        0.322157        3.943397
344122  28.674107       28.861134       28.607649       28.790190       1126.832764     0.384821        0.331764        0.358257        0.362251        3.532325
348906  29.052114       28.870409       28.594957       28.796562       439.761047      0.366349        0.333574        0.383286        0.356332        0.100708
353687  29.364279       28.884480       28.589748       28.803473       0.000000        0.369142        0.330989        0.374342        0.341972        0.050354
358469  29.363195       28.882654       28.587631       28.801615       0.000000        0.385200        0.355495        0.364623        0.356119        0.000000
363256  28.981312       28.880629       28.584301       28.788460       494.411957      0.341471        0.328007        0.355237        0.332765        3.243537
368044  28.943176       28.879095       28.585691       28.788542       570.345276      0.334816        0.318377        0.338703        0.351506        3.301453
372832  28.942907       28.874390       28.585627       28.783943       570.287354      0.349208        0.329972        0.342426        0.330260        3.300781
377617  29.058041       28.879311       28.585224       28.784782       370.640228      0.339161        0.307901        0.349978        0.310423        0.000000
382398  29.365849       28.882376       28.587019       28.786354       0.000000        0.338722        0.322020        0.335601        0.317809        0.000000
387178  29.366926       28.881508       28.588131       28.782959       0.000000        0.372645        0.356003        0.374909        0.373715        0.000000

temp0     29.34 -> 28.93 -> ~29.30 -> 28.65 -> 29.35 -> 28.66 -> 29.36 -> 28.94 -> 29.36
current4  0     -> 570   -> 0      -> 780   -> 0     -> 1127  -> 0     -> 570   -> 0
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4559
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #6 on: July 27, 2015, 12:40:15 pm »
I wonder if the uCurrent needs to have it's battery negative tied to the same Arduino Due 5VGND that the uCurrent V- is tied too, so it isn't floating any more.
You have connected the negative output terminal to GND of the Arduino. So it is not floating anymore.
Also, connecting battery negative to anywhere would render the virtual ground useless, probably killing some parts.
http://www.eevblog.com/files/uCurrentRev5schematic.pdf
The opamp U2 is generating Vbat/2 virtual ground that you have connected to the output gnd.
« Last Edit: July 27, 2015, 12:57:22 pm by Jeroen3 »
 

Offline peter64Topic starter

  • Newbie
  • Posts: 7
  • Country: jp
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #7 on: July 27, 2015, 01:04:18 pm »
Thanks Jeroen for the schematic, and explaining why I shouldn't wire the battery terminal to anything.
I'm really curious whats going on and why its causing the voltage on other analog inputs on the arduino due to change.
If anyone else has any thoughts or things that I could test I'm happy to take voltage and current measurements else where in the circuit while the uCurrent is running.
 

Offline peter64Topic starter

  • Newbie
  • Posts: 7
  • Country: jp
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #8 on: July 27, 2015, 01:25:52 pm »
I was doing some hunting online to see if I could find anything Arduino related that might give clues, but I'm a bit out of my league with this.
I was looking for any reference of ADC inputs being dependent on other ADC inputs. This is all I came up with but I can honestly say I don't understand if the uCurrent would be a cause of this ADC input dependence. (http://www.eevblog.com/files/uCurrentRev5schematic.pdf)

http://mjlorton.com/forum/index.php?topic=439.0
Quote
ADC inputs are anything but resistive, they are in most cases a switched capacitor sample and hold. Especially on a MCU with multiple inputs and a single ADC with a mux for them. This leads to the inputs being a high impedance most of the time but drawing a small pulse of current to charge ( or source a small current if the input is dropping) an internal sample and hold cap in the ADC. This can lead to both scale errors and to noise on the converted value, as well as the values becoming dependant on the other ADC inputs if you are using multiple inputs. There are 2 methods to mitigate this, you can use a unity gain opamp buffer on the pin to give a low impedance drive or you can use a RC filter to the pin. This was always used on the 7106/7 with a 1M and 47n to 100n film capacitor across the input, the 1M resistor gave less then 1 LSB of error on the device due to the 100M plus input impedance ( aside from those current spikes as the internal switches operated of course, which is why the capacitor was there to provide a current buffer that swamped the charge).

To not use the RC you must have a higher current through any voltage divider, generally 1mA or thereabouts at full scale will work as a ballpark figure. Will be increased dissipation in the resistors and cause some thermal drift, but will give a slightly lower input noise than high value resistors.

As seen the reference needs to be stable, using a 4.096V LDO reference and driving the internal reference input with this gives about the best full scale range, but you need to have the LDO well decoupled and the output needs a filter as well to reduce the noise that the MCU will place on it. There have been many applications that run the whole MCU on a precision 5V reference ( providing the current drawn is low and essentially constant, and you use bus buffers on the input and output digital pins supplied from a separate logic 5V supply) to get a stable internal operating environment.

Another noise reduction technique is to initiate the ADC conversion and then stop the MCU and wake it when the conversion is complete. This reduces internal noise from changing data buses and voltage noise across the power and ground bonds and the substrate from influencing the result. With this the only thing running is a clock oscillator driving the ADC.
 

Offline peter64Topic starter

  • Newbie
  • Posts: 7
  • Country: jp
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #9 on: July 27, 2015, 01:51:31 pm »
The more I read, I'm pretty sure the issue lies in how the Due ADC is working.
It makes sense because the order I am reading the inputs is temp0 -> temp1 -> temp2 -> temp3 -> current4 -> temp0.
Since temp0 follows current4 it is probably experiencing the most distortion as the value settles.
I will need to try and tweak the Due ADC settling time to see if this fixes the value.
I will update here once i figure out how with the result.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 18880
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #10 on: July 27, 2015, 03:42:03 pm »
Well as it's an arduino I'd expect the analogue libraries to handle timings, the analogue clock is limited to make sure there is enough time for the sample and hold capacitor to charge to discharge as it's the same ADC and front end for all 8 channels. maybe put a delay in after the 4th channel read
 

Offline peter64Topic starter

  • Newbie
  • Posts: 7
  • Country: jp
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #11 on: July 28, 2015, 12:55:11 am »
Just to update that I've resolved my issue.

1) delaying after reading didn't help didn't help.

2) changing the adc tracking time and prescaler did help

Quote
  REG_ADC_MR = (REG_ADC_MR & 0xF0FFFFFF) | 0x0F000000; // tracking time = 15 + 1 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFCFFFFF) | 0x00000000; // settling time 0=3, 1=5, 2=9, 3=17 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000; // start up time = 16 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFFF00FF) | 0x00001F00; // prescaler rate = (15 + 1) * 2 = 32 clocks
temp0     28.63 -> 28.59 -> 28.63  -> 28.57 -> 28.63 -> 28.50 -> 28.63
current4  0     -> 568   -> 0      -> 776   -> 0     -> 1121  -> 0     
dip                0.04               0.06              0.13


  REG_ADC_MR = (REG_ADC_MR & 0xF0FFFFFF) | 0x0F000000; // tracking time = 15 + 1 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFCFFFFF) | 0x00300000; // settling time 0=3, 1=5, 2=9, 3=17 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000; // start up time = 16 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFFF00FF) | 0x00001F00; // prescaler rate = (15 + 1) * 2 = 32 clocks
temp0     28.60 -> 28.57 -> 28.60  -> 28.54 -> 28.60 -> 28.47 -> 28.63
current4  0     -> 568   -> 0      -> 777   -> 0     -> 1122  -> 0     
dip                0.03               0.06              0.13


  REG_ADC_MR = (REG_ADC_MR & 0xF0FFFFFF) | 0x0F000000; // tracking time = 15 + 1 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFCFFFFF) | 0x00000000; // settling time 0=3, 1=5, 2=9, 3=17 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000; // start up time = 16 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFFF00FF) | 0x00000800; // prescaler rate = (15 + 1) * 2 = 32 clocks
temp0     28.58 -> 28.55 -> 28.58  -> 28.44 -> 28.58 -> 28.10 -> 28.58
current4  0     -> 568   -> 0      -> 777   -> 0     -> 1122  -> 0     
dip                0.03               0.14              0.48


  REG_ADC_MR = (REG_ADC_MR & 0xF0FFFFFF) | 0x0F000000; // tracking time = 15 + 1 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFCFFFFF) | 0x00000000; // settling time 0=3, 1=5, 2=9, 3=17 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000; // start up time = 16 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFFF00FF) | 0x00000F00; // prescaler rate = (15 + 1) * 2 = 32 clocks
temp0     28.54 -> 28.65 -> 28.54  -> 28.80 -> 28.54 -> 29.16 -> 28.54
current4  0     -> 568   -> 0      -> 777   -> 0     -> 1122  -> 0     
dip                -0.11              -0.26             -0.62


  REG_ADC_MR = (REG_ADC_MR & 0xF0FFFFFF) | 0x0F000000; // tracking time = 15 + 1 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFCFFFFF) | 0x00000000; // settling time 0=3, 1=5, 2=9, 3=17 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000; // start up time = 16 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFFF00FF) | 0x00000F00; // prescaler rate = (15 + 1) * 2 = 32 clocks
temp0     28.83 -> 28.32 -> 28.83  -> 28.08 -> 28.83 -> 28.38 -> 28.83
current4  0     -> 568   -> 0      -> 777   -> 0     -> 1122  -> 0     
dip                -0.11              -0.26             -0.62


  REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000; // start up time = 16 clocks
  REG_ADC_MR = (REG_ADC_MR & 0xFFFF00FF) | 0x00000100; // prescaler rate = (15 + 1) * 2 = 32 clocks
temp0     28.83 -> 28.30 -> 28.83  -> 28.06 -> 28.83 -> 28.36 -> 28.83
current4  0     -> 571   -> 0      -> 781   -> 0     -> 1128  -> 0     
dip                0.53               0.77              0.47

3) the most effective solution however was just to read the same adc input 105 times and discard the first 5 before moving to the next adc input and reading it 105 times. reading and dropping the first 5 results eliminated almost all the noise. this worked in my case because I am time averaging values for increased precision.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 18880
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Questions about using uCurrent with Arduino Analog Input
« Reply #12 on: July 28, 2015, 05:58:05 am »
sounds like the arduino library guffed up.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf