Dangerous Prototypes

In development => Project logs => Topic started by: matseng on July 19, 2013, 05:07:55 am

Title: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 05:07:55 am
Yesterday I saw the "The Practical Meter" (http://http://www.kickstarter.com/projects/david-toledo/the-practical-meter-know-your-power) on Kickstarter  - a small unit that is placed inline with the USB when charging your phone and shows the actual charging power (in watts) on a row of LEDs.

I wanted to have a go at it as well so I did the following last evening.

[attachment=1]

[attachment=2]

[attachment=0]

First I did a version with one of the newer 8-pin PIC and a low side current sense resistor, but to get a bit better resolution I also had to include a low voltage (about 0.8-1.1 volts) vref/vreg. Then I realized that the golden oldie ATTiny85 is much better for this application because it can do differential ADC readings and it also have an internal 20x gain amplifier for the ADC. So I changed into the tiny85 and a high side current sense resistor.  And since the Reset pin on the Tiny can also double as one additional ADC input I could then also read the actual voltage for more accurate power calculation.

The schematics is easy enough.  R5 is the current sense resistor - I plan to use a 0.1ohm resistor to get a reasonably high drop to measure accurately at low power but still a not too high drop at 2 amps.  R6/R7 is a voltage divider for measuring the actual voltage being delivered to the output (after the drop caused by the sense resistor). And then there are 6 charlieplexed LEDs for displaying the power consumption plus a one power-on led.

I'll send for some boards in a couple of days unless someone here discovers a flaw in the design...
Title: Re: PAW17 - USB Spypow
Post by: Bertho on July 19, 2013, 11:22:38 am
Nice gadget.

Some thoughts:
The 0.1Ohm resistor will drop 100uV/mA (or 2mV/mA with x20 differential). That will cause a lot of noise to be picked up (also from the sense-resistor itself). I'd suggest to put a 100nF or 1uF across the sense resistor placed directly at the micro-controller to dampen the noise.

You have ADC[23] for the differential measurement. The datasheet specifies the accuracy at 4V reference and 5V Vdd (not the best of accuracy). I'm not entirely sure that the differential measurement can take the inputs all the way to Vdd (or very close) and still have some accuracy left. You may want to divide the absolute sense values down so that the differential amplifier has more wiggle-room wrt. the Vdd rail. Dividing might lose some measurement resolution, but will probably be compensated by a better measurement accuracy.
Title: Re: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 12:03:33 pm
Thanks for the comments. 

I was thinking about having a cap across the sense resistor, but then I thought that I can just as well do averaging in the firmware instead. But if I can squeeze in a cap there I'll do it - it can't hurt do have it there.

The Practical Meter have 0.5 W for the first LED, so that is 100mA giving a drop of 10mV over the sense. Not too bad, but filtering is probably needed anyways.

I build a prototype to test the accuracy of the ADC in differential mode.  It's a good thing that you can set both ref+ and ref- to the same pin for nulling out the offsets in the opamp.

[attachment=0]

It's so nice to have a decent inventory of parts in your home lab. For the prototype I needed the 0.1R resistor so I just rifled thru my box with "special" smd resistors and found a strip of 1206 1% 0.1R resistors that I bought some years ago "just in case" but haven't used until now. :-)
Title: Re: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 12:12:01 pm
[quote author="Bertho"]You may want to divide the absolute sense values down so that the differential amplifier has more wiggle-room wrt. the Vdd rail. Dividing might lose some measurement resolution, but will probably be compensated by a better measurement accuracy.[/quote]
What would the best way of doing that be?  I can't really brain today so the only way I can think of is to have two resistors in series with the wires to the ADC inputs and then a resistor across the ADC.
Title: Re: PAW17 - USB Spypow
Post by: Bertho on July 19, 2013, 12:53:42 pm
[quote author="matseng"]What would the best way of doing that be?  I can't really brain today so the only way I can think of is to have two resistors in series with the wires to the ADC inputs and then a resistor across the ADC.[/quote]
I'd suggest something like this:[attachment=0]
It reduces the line-levels to 0.5*Vdd, which is in the middle of the differential opamp. C1 and C2 lower the impedance for the ADC and C3 shorts out the immediate line noise. You can try without C3 (as C[12] take a bulk of the noise), but you will need the capacitively lowered impedance of C[12]. For R[1-3] you could use a simple x4 resistor network package, which saves a lot of space.

The R3C1 and R5C2 combinations will also reduce the dynamic sensitivity (RC~1ms), but that will be a good thing without interfering much with reaction speed.
Title: Re: PAW17 - USB Spypow
Post by: Bertho on July 19, 2013, 01:10:59 pm
[quote author="matseng"]Ugly as crap soldering job for the prototype :-)[/quote]
That is a brilliant version of "need to hack a job to test my hypothesis".
Title: Re: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 01:26:27 pm
Thanks, I'll try the attenuator - and good idea with using a resistor array.  I got plenty of 4P 10K arrays but I wouldn't have remembered to use them without you reminding me.

It would be cool if there was capacitor arrays as well - is there? I have to look for them. :)
Title: Re: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 01:28:55 pm
And in this configuration I don't need the R6/R7 for doing the output voltage measurement. I can just take a reading in single ended mode here - absolutely excellent!
Title: Re: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 01:42:09 pm
[quote author="matseng"]It would be cool if there was capacitor arrays as well - is there? I have to look for them. :)[/quote]
How can I have missed that there are cap arrays for so long?!?  I guess that if you're not looking for it specifically you normally don't find them by chance.

There are both SIP -thru hole versions that looks pretty much the same as the resistor-version of it.
http://my.element14.com/bourns/4610m-90 ... dp/2112961 (http://my.element14.com/bourns/4610m-901-104lf/capacitor-array-0-1uf-50v-x7r-sip/dp/2112961)
[attachment=1]

As well as SMD versions http://my.element14.com/yageo-phycomp/c ... dp/1779474 (http://my.element14.com/yageo-phycomp/ca0508krx7r7bb103/capacitor-array-0508-10nf-16v/dp/1779474)
[attachment=0]

Now I have to get a handful of them and try to use them in some projects - cool.
Title: Re: PAW17 - USB Spypow
Post by: Bertho on July 19, 2013, 02:16:18 pm
[quote author="matseng"][quote author="matseng"]It would be cool if there was capacitor arrays as well - is there? I have to look for them. :)[/quote]
How can I have missed that there are cap arrays for so long?!?  I guess that if you're not looking for it specifically you normally don't find them by chance.[/quote]
You have to be very careful using cap-arrays. Most have a significantly lower voltage rating than the single counterparts. The problem that bring is the reduced capacitance at steady DC levels (remember, U*C=constant). Be sure to pick a rating where the (residual/effective) capacitance is at the level you require.
Title: Re: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 04:08:14 pm
New version with Bertho's attenuator/filter.  Can't fit the main filter capacitor though.  I have to put that across on top of the other two if I really need it :-)

[attachment=0]

[attachment=1]
Title: Re: PAW17 - USB Spypow
Post by: scicior on July 19, 2013, 07:02:40 pm
Are the eagle files available anywhere?  I'm having some boards made on Monday and I'd like to GerbMerge one of these in with the others.

Thanks!

- Steve
Title: Re: PAW17 - USB Spypow
Post by: matseng on July 19, 2013, 07:40:42 pm
Sure thing...  Repo at https://github.com/SmallRoomLabs/Spypow (https://github.com/SmallRoomLabs/Spypow)

So far completely untested. The left (male) USB connector is a common model easily found on ebay. The right (female) usb you might want to change into some model you have available.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01192116232session_write_close ( )...(null):0
20.01222247824ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01222248600Database_MySQL->query( ).../DatabaseHandler.php:119
40.05582387336Database_MySQL->error( ).../Db-mysql.class.php:273