ATTINY1616 (& derivatives) your best current resistor read config

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Trying to read with reasonable accuracy (+/- 25mA) a current over a 30mOhm resistor, or 50mOhm. Attempting not to go above 50mOhm for efficiency.

No speed requirement and triggering the ADC at 2Hz from RTC.

Here's the expected reads. You can see that I've lowered the 0.1A value to try and get a read. With the 30mOhm I can't, but I can start to get a read with the 50mOhm at about 200mA
 

// 0.03 ohm * 0.1A = 0.003v, /0.55*1023 = 6
// 0.03 ohm * 0.5A = 0.015v, /0.55*1023 = 28
// 0.03 ohm * 0.9A = 0.027v, /0.55*1023 = 50
#define USB_CURRENT_CHANGE_HYSTERESIS 1U
#define USB_CURRENT_USB2_ADC_VALUE 2U
#define USB_CURRENT_USB3_ADC_VALUE 28U
#define USB_CURRENT_USBC_CC15_ADC_VALUE 50U

ADC is configured to run a 62KHz. MainClk at 250KHz. 64 samples
 

    // ADC0
    ADC0.CALIB = ADC_DUTYCYC_DUTY25_gc;
    ADC0.CTRLB = ADC_SAMPNUM_ACC64_gc;
    ADC0.CTRLC = ADC_PRESC_DIV4_gc | ADC_REFSEL_INTREF_gc; // 62.5KHz
    ADC0.CTRLD = ADC_INITDLY_DLY256_gc | ADC_ASDV_ASVON_gc | 0b111 << ADC_SAMPDLY_gp;
    ADC0.DBGCTRL = ADC_DBGRUN_bm;
    ADC0.EVCTRL = ADC_STARTEI_bm; // Auto trigger
    ADC0.SAMPCTRL = 0x1F;     //SAMPLEN 31
    //ADC0.INTCTRL = ADC_RESRDY_bm;
    ADC_CONFIG(USB_CURRENT_ADC_CHANNEL, USB_CURRENT_ADC_REF);
    ADC0.CTRLA = ADC_RUNSTBY_bm | ADC_RESSEL_10BIT_gc | ADC_ENABLE_bm;

As good as it gets without a op-amp across the resistor?
 

This topic has a solution.
Last Edited: Sun. Apr 10, 2022 - 05:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What full-scale current are you aiming at ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

900mA is last point (I'm detecting 100mA, 500mA, 900mA.

Using a 0.05mOhm sense, I calibrated it to the following

 

// 0.05 ohm * 0.1A = 0.005v, /0.55*1023 = 9.3
// 0.05 ohm * 0.5A = 0.025v, /0.55*1023 = 46
// 0.05 ohm * 0.9A = 0.045v, /0.55*1023 = 83.7
#define USB_CURRENT_CHANGE_HYSTERESIS (1U*ADC_SAMPLES/4)
#define USB_CURRENT_USB2_ADC_VALUE (26U)
#define USB_CURRENT_USB3_ADC_VALUE (15U*ADC_SAMPLES)
#define USB_CURRENT_USBC_CC15_ADC_VALUE (50U*ADC_SAMPLES)

So switch point (hypothetical) should be 64*9.3=595, whereas you can see I'm using 26U. Way out!

 

Last Edited: Sat. Apr 9, 2022 - 03:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
Attempting not to go above 50mOhm for efficiency

 

Seems to me that 50mOhm is a magic number for measure.

 

In my Switching project I installed two 0.1 ohm 0603 in parallel, in Source of Mosfet- to enable watching a current ramp, to see whether the inductor goes to saturation.

 

There are some projects for measuring a very low resistance, and if I remember well, they use 0.1 ohm and /less than/ 10ms pulse for ADC.

Last Edited: Sat. Apr 9, 2022 - 03:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:

Trying to read with reasonable accuracy (+/- 25mA) a current...

 

What current? 1A, 5A, 10A, 500A?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

900mA max.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is embarassing, I had a problem in my code. It is working great with a 50mOhm resistor. Going to try a 30mOhm next.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As good as it gets without a op-amp across the resistor?

 Of course you will likely have an opamp...how else will you use the full 1000+ ADC counts?  The only other way, would be if you were measuring maybe 40 amps, you'd create a full voltage.

 

Remember, you will generally be a few counts off (and also always one count of flicker and also a couple counts of noise), so working with a value of "6" is rather poor.  Some AVR's have an internal opamp, though they are relatively crappy (software cal to the rescue).

Give yourself at least a few counts of hysteresis, maybe 4 or 5 minimum.   

if you are accumulating 64000 counts, a 1% trip hysteresis would be around 640 counts, if using full scale range.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sat. Apr 9, 2022 - 04:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Gotta ask...

 

I assume one end of Rsense is tied to ground?

 

+1 on using an op-amp on the front end, even if it is an AVR with an internal op-amp.

 

IIRC, some AVRs can use an external voltage reference for the ADC.

That, also, would be great for your project, as you could use a lower Vref to improve the amount of the scale that you are using, (without an op-amp).

 

One can use a formal voltage reference "ic" for the external reference, if accuracy is needed.

Otherwise one might just use the forward voltage of a diode, (LED), with or without a parallel voltage divider, as a "poor man's" voltage reference.

 

Lots of options.

 

JC 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That, also, would be great for your project, as you could use a lower Vref to improve the amount

Well, sort of/maybe.   The bandgap is already in there & some what optimized.  Going lower, will probably rapidly dip into to ADCs parasitics, so the result will likely go to crap.

For example, you might say, I'll use a 50mv Vref & jeepers have 1000 levels, that's 50 microvoilts per step!!  NOT!   No doubt someone (Ralph?) has experimented with how low you can push it in the real world.   Maybe do a lot of averaging and software cal to gain some traction.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


snoopy33 wrote:
Trying to read with reasonable accuracy (+/- 25mA) a current over a 30mOhm resistor,
750 micro-volts

snoopy33 wrote:
As good as it gets without a op-amp across the resistor?
or CSA (differential amplifier by a zero-drift op amp)

Willing to try tinyAVR 2-series PGA?

AVR DB op amp is noisier than PGA though might work with some analog and digital filtering as the sample rate is only 2 Hz.

 


How to Protect Circuits from Overcurrent Spikes | onsemi (3m1s, CSA into a comparator)

Current Sense Amplifiers | onsemi

Current Sense Amplifier ICs | Microchip Technology

 

ADC | tinyAVR® 2 Family

[bottom]

Table 5. Accuracy Characteristics with PGA Enabled(1)

...

1.These values are based on characterization and are not covered by production test limits.

OPAMP Specifications | AVR® DB Family

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
Maybe do a lot of averaging ...
AVRxt ADC has an accumulator; oversample-and-decimate is the next enhancement (software, hardware in XMEGA E)

 

Control B | ADC | tinyAVR® 1-series

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
Using a 0.05mOhm sense, I calibrated it to the following

Don't forget about the zero offset also.

 

All AVR datasheets contain a section about ADC Accuracy Definitions. You would step increase the current from zero and note where the conversion count changes form 0 to 1.

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sorted, it's working well even with a 30mOhm resistor for 25mA steps. I'm using the 64x accumulator to average out noise.

It probably helps the CPU is running at 250KHz mostly in sleep.

Very happy!