Author Topic: Current Ranger reading unreadable [solution]  (Read 3853 times)

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Current Ranger reading unreadable [solution]
« on: November 12, 2018, 09:18:35 AM »
Hi Felix,


I have observed in uA (nA is the same) very often when I read a sleep current, it is anything from 0 to 40uA. My DMM is showing 5uA and stable. How can I stabilise readings on the OLED screen please so that it is producing a value similar to my DMM? Averaging?

See video here:
https://www.dropbox.com/s/t2z7neinmqqasbo/Video.MOV?dl=0

Thanks
Alex
« Last Edit: May 23, 2019, 01:50:46 PM by Felix »

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Re: Current Ranger reading unreadable
« Reply #1 on: November 12, 2018, 09:19:22 AM »
Reply from Felix via e-mail:

Ok, so basically it is so sensitive in NA range that it picks up noise induced by the wires. There is no way around it. Remember, the output will be amplified 100 times. The leads will act as antennas. In fact if you try this on the uCurrent, the effect should be even worse (looking on the scope the noise fills the screen).
The ADC sampling is a simple averaging algorithm using built in averaging of the SAMD21.
The only way to filter out noise would be to do more advanced software filtering. In other words, to simulate the RMS algorithm of the DMM, which in fact is much much slower in terms of bandwidth, and may only give you a few readings a second.
The default firmware algorithm for the ADC, as given in the sample sketch, only samples a few times a second as well. This is to keep noise coupled into the amplifiers output at a minimum - that would only be visible on a scope though, not on a RMS-ing DMM. So if you dont care about using with a scope, than you can increase averaging, or even sample+average constantly, between OLED updates. So that should help dramatically with the jumping. However you can not expect the 12bit ADC will be as accurate as the advanced DMM ADC circuitry. It is just there to give you "good enough" informational readings. And of course, with the limitations I have discussed above - it's possible to make it more accurate/stable, but with the tradeoffs I mentioned.
I hope this makes sense?

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Re: Current Ranger reading unreadable
« Reply #2 on: November 13, 2018, 03:57:12 AM »
Hi Felix,

Thanks for your reply - I'll come back to you on the firmware. I need to dive into it to understand what's going on.
I have increased averaging and had another interesting observation.
Take a look at these photos

This is the CurrentRanger


and this is uCurrent Gold



My DMM is giving results similar to the uCurrent Gold.
The same sleeping node, the same wires, i.e. the same setup.

The node is a simple bare atmega328p and nrf24l01+
Typically I get about 4-5uA on these nodes.

Now, I am testing CurrentRanger against a current source

10uA current


100uA current


and 1mA current


My question is why there is a huge difference in measuring the node current (15uA vs 4.7uA), but the current source testing is spot on?


PS If averaning is not increased autoranging on the CurrentRanger is often not usable - it switches between nA and uA all the time.


wile1411

  • Jr. Member
  • **
  • Posts: 54
  • Country: au
Re: Current Ranger reading unreadable
« Reply #3 on: November 13, 2018, 04:01:27 PM »
PS If averaning is not increased autoranging on the CurrentRanger is often not usable - it switches between nA and uA all the time.

just wondering what code changes you did for the averaging?
Mine also flicks back and forth between nA and uA rapidly. It flicks so much that I'm about to remove the beep code or (limit it 1 per 600 loops or so) just to shut it up.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Current Ranger reading unreadable
« Reply #4 on: November 13, 2018, 04:25:52 PM »
I wonder if this is powering your DUT with a bench power supply, as I see in the other thread. I have that same chinese supply, and it's noisy.

The uCurrent only outputs directly from the opamps - (same opamps, same amplification).
So the problem here is strictly with the CurrentRanger's SAMD21 ADC readings, and we cannot compare between the 2 units unless we do an apples-to-apples test. This can be done in BIAS MODE of the CurrentRanger, no OLED connected.

Anyway I suspect this is all because of noise, usually from a power supply. And I don't know exacly if there's an easy way around it.

The first thing I would recommend, if not already, is to try to power the DUT using a battery instead of a power supply.
See if that makes a difference. Also the LPF should help especially in the lower range. Let me know what results you have.

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Re: Current Ranger reading unreadable
« Reply #5 on: November 13, 2018, 04:31:54 PM »
just wondering what code changes you did for the averaging?
Mine also flicks back and forth between nA and uA rapidly. It flicks so much that I'm about to remove the beep code or (limit it 1 per 600 loops or so) just to shut it up.

I am still tinkering with it so my answer if not a definitive one. Start with 10 and gradually increase it.
With averaging you won't have it.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Current Ranger reading unreadable
« Reply #6 on: November 13, 2018, 04:40:55 PM »
How about continuous averaging between OLED updates?
That's still not RMS but should dampen noise a lot more.

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Re: Current Ranger reading unreadable
« Reply #7 on: November 13, 2018, 04:47:43 PM »
I am still tinkering with it so my answer if not a definitive one. Start with 10 and gradually increase it.
With averaging you won't have it.

Blimey! I should have guessed. Thank you Felix, you have made my made.
I connected two 2xAA batteries and guess what? Everything working as should - no more noise.
uA is showing 0.1 and nA is very stable at around 120.

I knew this chinese PSU is noisy, which is fine for 90% applications, but I simply did not rule it out this time.

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Re: Current Ranger reading unreadable
« Reply #8 on: November 13, 2018, 04:56:39 PM »
How about continuous averaging between OLED updates?
That's still not RMS but should dampen noise a lot more.

That's what I do pretty much - 200 averages and 300 OLED refresh.
However, I wonder about setting up averaging in hardware. I checked the ADC driver datasheet for SAMD21:

Quote
ADC_RESOLUTION_CUSTOM needs to be set as the resolution. When this is set the number of samples to accumulate and the division ratio can be set by the configuration struct members adc_config::accumulate_samples and adc_config::divide_result. When using this mode the ADC result register will be set to be 16-bit wide to accommodate the larger result sizes produced by the accumulator.

It is possible to have 1024 samples (16 bit) averaging as a trade conversion speed for accuracy.
Have you considered it?
« Last Edit: November 14, 2018, 10:35:00 AM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Current Ranger reading unreadable
« Reply #9 on: November 14, 2018, 10:53:52 AM »
ADC hardware sampling is done in the adcRead() function.
You can do up to 1024 samples:

Code: [Select]
ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_1024 | ADC_AVGCTRL_ADJRES(0xAul); //take 16 samples adjust by 10

You should probably also speed up sampling time:

Code: [Select]
//sample timing (0 .. 0b111);
ADC->SAMPCTRL.reg = 0b0; //0x00 fastest

Have not tried this exact config, just wrote code from datasheet values. See ADC section/register summary and descriptions for more details how these parameters are working.

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Re: Current Ranger reading unreadable
« Reply #10 on: November 14, 2018, 02:13:08 PM »
Thank you Felix
I have amended the code and happy with the performance:



I have also tried to insert RMS into the code, but for whatever reason it is not always working well with autoranging:

Code: [Select]
void readVOUT() {

  read1 = 0, read2 = 0;
  long rmsValue1 = 0, rmsValue2 = 0;
  long RMS1 = 0, RMS2 = 0;
  float runningAverage1 = 0, runningAverage2 = 0;
  long sample1 = 0, sample2 = 0;
  bool a = false;
  for (int i = 0; i < ADCREADINGS; i++) {
    sample1 = adcRead(SENSE_GNDISO);    // read analog input to sensorValue
    sample2 = adcRead(SENSE_OUTPUT);    // read analog input to sensorValue
    rmsValue1 = rmsValue1 + sq((float)sample1);
    rmsValue2 = rmsValue2 + sq((float)sample2);
  }
  RMS1 = sqrt(rmsValue1 / (ADCREADINGS) );
  RMS2 = sqrt(rmsValue2 / (ADCREADINGS) );
  //-----------------
  /*
//Smoothing averages further
  if (a == false) {
    runningAverage1 = RMS1;
    runningAverage2 = RMS2;
    a = true;
  }
  runningAverage1 = (((10 - 1) * runningAverage1) + RMS1) / 10;
  runningAverage2 = (((10 - 1) * runningAverage2) + RMS2) / 10;
  read1 = runningAverage1;
  read2 = runningAverage2;
*/
//----------------------
  read1 = RMS1;
  read2 = RMS2;

    readDiff = read2 - read1;
}
« Last Edit: November 14, 2018, 05:01:43 PM by alexsh1 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Current Ranger reading unreadable
« Reply #11 on: November 14, 2018, 02:21:39 PM »
Great!
What settings did you end up using?
And by RMS you mean doing a SQRT of the sum of squares?

alexsh1

  • Jr. Member
  • **
  • Posts: 58
  • Country: gb
Re: Current Ranger reading unreadable
« Reply #12 on: November 14, 2018, 05:11:25 PM »
I have used ADCREADINGS 250 with some further enhancements (speed and averaging) as per your advice. I also increased OLED refresh rete - now its looking like a professional DMM  ;D Averaging register has to be shifted right according to the DS if more than 16 samples are used (page 900 of the DS).


Re RMS. yes, please see above my proposed code. The only problem with the code above is that autoranging not always working correctly. I did not spent enought time to debug it. It is based on this paper :

https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&cad=rja&uact=8&ved=2ahUKEwj6q-7r8tTeAhVRQcAKHV3hAlsQFjAJegQICRAC&url=http%3A%2F%2Fwww.ejece.org%2Findex.php%2Fejece%2Farticle%2Fdownload%2F6%2F8&usg=AOvVaw3mmWebflq4GwTSDHHBP6me
« Last Edit: November 14, 2018, 05:14:23 PM by alexsh1 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Current Ranger reading unreadable
« Reply #13 on: November 19, 2018, 04:07:09 PM »
Great, I updated the CR firmware to add more averaging.
« Last Edit: May 23, 2019, 01:50:29 PM by Felix »