Adjustable USB Power and Measurement Board

Tell us about your projects. Update us regularly.
Post Reply
parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Adjustable USB Power and Measurement Board

Post by parkview » Wed May 25, 2022 3:10 pm

As you can see from this Forum, I have been working on a number of ESP32 based projects. It would be really handy to be able to have a USB based power limiting function and at the same time, be able to measure power being used at high speed, say at least 20K Samples Per Second (SPS). This would help quantify low power usage on some of my projects.

In this project I have drawn ideas from this nice board: https://www.nordicsemi.com/Products/Dev ... ofiler-Kit
This first version of my board is an Alpha version to test out some of the circuitry that I might use going forward and to test out some of the software. Some of this is very similar to my USB Cable Tester Board, so it didn't take too long to put together some circuitry:
AUPMB.0_sml.jpg
AUPMB.0_sml.jpg (79.78 KiB) Viewed 22570 times
It's all laid out into a number of switched blocks. By switched, I mean under ESP32 control, I will be able to switch various paths and blocks on and off. I have included a set of three current calibration test loads: 1A, 500mA, 100mA

It includes an adjustable 1.8V to 5V Regulator based on an adjustable MCP1827 LDO and a 100mA to 1.1A current limiting switch based on the MIC2097. Both of these are adjustable via i2C based variable digital resistors. This will be a first for me, so it will be interesting to see how these work out.

The above adjustments can be bypassed via MOSFETs and I use either RU30L30 or WST2011 (dual MOSFETs back to back) high side MOSFET switching around the board. Each block has a WS2812 RGB LED to signify it's status. It looks quiet colourful when they are all lit up:
AUPMB.1_sml.jpg
AUPMB.1_sml.jpg (83.84 KiB) Viewed 22570 times
Funny story: So, some time back, I discovered that LCSC stock 2mm x 2mm WS2812 based RGB LEDs. These are a wonderful size to use when you have a pretty full PCB and not much spare space left for a bit of photon bling. I quickly used them in my next three projects with out closely examining the pinouts, I mean it kind of looks ok? Fast forward to the first PCB arriving and my dismay when the RGB LEDs would not light up! Yep, for some reason the manufacture has rotated the footprint by 90 degrees. You can still use them, but the footprints are a bit out and so you need to hold the LEDs in place while hot airing them down, otherwise the surface tension pulls them askew. Oh, and if you do power up a board with them out of place, it fries them out.

As you can see in the photo above, the adjustable voltage regulator is not the size I expected and I had space to mount it dead-bug style by scratching away some of the solder mask and hot airing it into place.

I have already learnt about some SPI based ADC IC's like the ADC124, so the next version will incorporate one of these, so that will give me a much faster current and voltage measurement in the next version of PCB. This journey has just begun!

parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Adjustable USB Power and Measurement Board

Post by parkview » Thu May 26, 2022 9:12 pm

The first version of the Adjustable USB Power and Measurement board had this kind of block diagram:
V0.5_Block-Diagram.jpg
V0.5_Block-Diagram.jpg (15.81 KiB) Viewed 22565 times
When I designed this, I didn't realise how slow i2C reading was on a ESP32. To save GPIO, I used i2c based INA219, which has a maximum of one thousand Samples per Second. I would like a greater resolution, so to heck with the expense, I will upgrade to a ADC128S102CIMTX, 8 channel SPI based ADC IC can read up to 1MSPS! Silicon shortages have driven the price up quite a bit, it's currently A$12.49/ea on LCSC.

Version 0.6 of this board will have something like this arrangement:
V0.6_Block-Diagram.jpg
V0.6_Block-Diagram.jpg (30.37 KiB) Viewed 22565 times
I think I can do it with a ESP32, but later, I could move to a ESP32-S3 for the extra GPIO, when they are more prevalent and cheaper. It would be exciting to be able to read sub-miliAmp currents, however I suspect it might be quite a bit noisy down there in the grass, so to speak.

I have yet to do a thorough voltage drop analysis of the current board, but I think I measured 0.6V drop across the board with a load of 480mA. Thats quite a lot, but the path does have quite a few switching MOSFETs and each one takes a tiny chunk. Also, I am not driving the P-channel MOSFETs fully on, so thats not helping. I wonder if it's worth while adding a negative 5+V regulator to help lower the MOSFET resistance? I wonder how much better the voltage loss might be?

I am using a standard 128x64 i2C based OLED Screen. I tend to use these on most projects, as they are cheap and easy to use, but it would be nice to have a larger screen with more pixels. This morning after a quick search, I discovered that for around A$12, I can get a 128x128 OLED screen. This will be really handy for the rotary encoder menu and data display.

parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Adjustable USB Power and Measurement Board

Post by parkview » Sat May 28, 2022 10:41 pm

Today I did a full path voltage loss measurement across all active components. With a USB 5.03V input and a load of around 490mA I measured a loss of 466.4mA across the voltage regulator path. I measured a loss of 355.6mA with the voltage regulator switched out.

Basically it comes down to I loose 58mV for every WS2011 (Dual P-MOSFET) and 6.4mV for the RU30L30 (single P-MOSFET). They worked out to have a resistance of around 120m Ohm and 13m Ohms respectively. This is quite below the datasheet maximum values. Here are some common types I use:

WST2011: RDS = 80-85m Ohm each @ 4.5V (dual MOSFET)
RU30L30: RDS = 20-34m Ohm @ 4.5V
AO3401: RDS = 53-60m Ohm @ 4.5V
EMF20B02V: RDS = 15-20m Ohm each @4.5V (dual MOSFET)


I spent some time this afternoon hunting around LCSC for some better dual P-MOSFETs and found the EMF20B02Y. This one looks great so I will buy a bunch of them and it comes in a very tiny 3mmx3mm package and is rated for 8.4A, so sounds very handy for other projects too. It means I will really reduce my voltage loss across the PCB. Talking of that, after comparing the measured voltage drop across the board, to adding up all the voltage drops across the components, I was missing around 40mV. I measured a few PCB power traces and found 20mV for half the length. The others where short traces, but I am sure they account for the missing 20mV or so.

Segway - Graph of the day:
MCP1827 Output.1sml.jpg
MCP1827 Output.1sml.jpg (17.78 KiB) Viewed 22558 times

Above, is a graph of the ESP32 outputting binary 1 to 127 to the 100K ohm i2C digital resistor with no load. This is connected to the MCP1827 adjustable regulator, so the graph is comparing the 1 to 127 inputting to the resistor and the resultant voltage out of the regulator. I was unsure how this would turn out so I added a 0 ohm resistor in series with the digital one just in case it might be needed. To lessen the initial dip, I placed a 6.2K ohm resistor and with a 490mA load, this is the graph I get now:
MCP1827 Output.3sml.jpg
MCP1827 Output.3sml.jpg (22.39 KiB) Viewed 22558 times

It looks a bit better. I think I can get rid of the initial dip all together with a 6.8K ohm resistor, but will do that on the next version as it's a pain to hot air off due to the regulator bodge leads on the PCB. I have started designing up the next version of the PCB, but I do want to have a go at trying to record a ESP32 dev board powering up and connecting to WiFi, so lots still to do.

parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Adjustable USB Power Profiler Board

Post by parkview » Wed Jun 22, 2022 8:20 pm

Amongst everything else going on, I managed to get the (Now calling it) USB Power Profiler Board sent off to JLCPCB this morning. It ended up being a bit more complex than the V0.6 block diagram, so it should be interesting to see how it turns out. It would be great if it can measure down to the 10's of micro Amps, but that might be pushing things a bit.
USB Profiler V0.6_sml.jpg
USB Profiler V0.6_sml.jpg (90.67 KiB) Viewed 22353 times

I don't have much in the way of calibrated test equipment, so I am not sure yet on how to actually test it properly. There are 19 odd zones on the board and each circuit has it's own 2mm WS2812 LED, so if nothing else, it will be very colourful when it's all lit up.

The Nordic Profiler II board seems to do automatic voltage adjustments and the MCU only has to read the switches to figure out the current flowing through it. In that regard, this board is dumb, in that the MCU will switch the different current sensors in and out, which is not ideal, but it is a good start for this version. The ADC128 sensor can do at least 40K SPS, so there will be a lot more data coming from this board. I ran out of GPIO, so there's no SD card on board. I am hoping to be able to stream the data to a computer via UDP packets.

parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Adjustable USB Power and Measurement Board

Post by parkview » Fri Aug 26, 2022 5:19 pm

The blank PCB arrived back and after laser cutting a plastic stencil, I placed and hot plated the components into place. I am really happy with it so far. I certainly looks colorful when all of the 19 RGB LEDs are lit up. Here, I only have them set at 25% brightness:
USB-Profiler-PCB_V0.6.jpg
USB-Profiler-PCB_V0.6.jpg (165.4 KiB) Viewed 22048 times

I am now re-writing the old V0.5 version of software for the new V0.6 board functions. The onboard PCF85063 RTC IC works really well, digital control over the adjustable voltage regulator and current limiter works well. There is a lot more to do though.

parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Adjustable USB Power and Measurement Board

Post by parkview » Thu Jan 05, 2023 2:22 pm

I spent a lot of time playing around with this board. Writing code to test out functionality (it works well), and then to see how low it could measure currents. Ideally I was hoping to get down into the 10's of uA, however I discovered a few design flaws:

1) the 10uA test load is done by placing a 500K ohm resistor across the 5V output:
10uA-load.png
10uA-load.png (14.65 KiB) Viewed 21333 times
However, the current monitoring sensor was placed BEFORE the path switch. In the switch section I have a 100K ohm resistor in the USB line voltage path, so when a path is switched on, it places a 100K ohm resistor to GND, yet I am trying to measure a 500K ohm load:
100k-Ohm.png
100k-Ohm.png (39.87 KiB) Viewed 21333 times
This does not work. Even swapping it out for a 1M ohm Resistor didn't help much. The best fix was to A) move the switch to the otherside of the current sensor; B) tie the P-MOSFET gate resistor to a separate 5V source, eg: one that we are not measuring - the ESP32 power supply:
updated-100K.png
updated-100K.png (38.55 KiB) Viewed 21333 times
2) when I am attempting to measure small USB output currents, I could also measure the output voltage by a 20K + 50K ohm voltage divider. Once again this is permanently placing a relatively large load (41.6uA) on the line:
USB-Output.png
USB-Output.png (45.94 KiB) Viewed 21333 times
The fix for this was to switch the voltage divider so I can stop current measurements when I read the line voltage etc:
switch_volt-divider.png
switch_volt-divider.png (52.15 KiB) Viewed 21333 times
The ESP32 MCU was replaced with a ESP32-S3 which gave me a few extra GPIO pins so I managed to shoehorn in a SD card. I had purchased a i2C based 128x128px OLED, but found the drawing rate too slow for what I wanted, so I swapped the i2C display out for a SPI based 240x240px LCD screen. More pixels to boot :-)

The PCB should arrive week, so exciting times ahead.

parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Adjustable USB Power and Measurement Board

Post by parkview » Sun Feb 05, 2023 10:58 am

Well this version of thew board turned out to be quite usable. There are still two errors with the design:

1. kind of small, but I have two voltage dividers, one to measure the input voltage and the other to measure the output voltage. They are switched, so as not to load down the USB line, or at least do it in a managed manor. The input divider switch MOSFET is around the wrong way, so it's powered on all the time. Easy to fix.

2. in the photo below, you can see the right hand green LED (text hidden behind the screen). It indicates that the ~10uA load (510 ohm resistor) is switched on. I was surprised to see that the current sensor was reading ~488uA!! There is not much going on in the circuit now so the only thing left was maybe the quiescent current of the INA180 sense amplifiers? I hot aired one off and sure enough the current reading dropped by 138uA. Re-reading the datasheet, it says the quiescent current should be around 80uA from a non-used INA180. By the time I had removed all three non-used INA180's the reading was down to 69uA. Therefore with a 5.2V USB / 510 ohm load = 10.196uA the active INA180 must be drawing around 58.8uA. A partial hardware fix for this would be to place each INA180 between the two isolation MOSFETs. This would reduce the stray currents by 3 x 138uA = 414uA, just leaving the active INA180. I could also look around for a better sense amplifier.

Lit up like a xmas tree:
UPP_v0.8_running.jpg
UPP_v0.8_running.jpg (190.02 KiB) Viewed 21240 times

At least each INA180 was drawing a consistent 138uA. This meant I could just subtract 478uA from the reading and I get 11uA. If I made some better measurements, I would be able to narrow that down a bit closer to the expected 10.19uA. As it stands the readings do fluctuate by +-1uA. I am happy if I can measure in the range of 2-3 uA.

If I increase the 20 ohm sense resistor to 80 ohms or maybe even 100 ohms, it would help with more reliable low current readings too. This is something to investigate once I have better software up and running.

Talking of software, at the moment it's just a display State Machine. A LOT more work is needed on this front.

You can find the PCB design files and example code here: https://gitlab.com/parkview/usb_power_measurement_board

parkview
Guru Maker
Posts: 603
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Adjustable USB Power and Measurement Board

Post by parkview » Fri Oct 20, 2023 1:16 pm

Visited the Penang Science Cluster Makerspace recently and was fortunate to be able to spend three weeks working there on a few projects, one being my USB Power Profiler PCB but mostly working on the software side. Had lots of fun with the latest v0.8 version of the board:
2023-09-10_09-34-50_sml.1.jpg
2023-09-10_09-34-50_sml.1.jpg (95.33 KiB) Viewed 19788 times
The INA180 current draw issue has been fixed, but there is still some noise issues when measuring low currents. Some of this is due to me using a noisy power bank to power the board. Too much noise is getting into the ADC area, so there will be another PCB version 0.9 being produced in early 2024.

I can now record data to the built in SD card. Unfortunately it only works in SPI mode, so I am only able to record 1100 readings per second and sending data over the Serial port is slow as well. Time to get the wifi Access Port mode up and running. After a a few dead ends, I managed to get a rudimentary webpage showing a reading and I could send the current datetime and send a IP address to the board. All the settings are now stored in the ESP32-S3 NVS Flash. This means the board with start back up in the last used configuration. Very handy.

Later I managed to stream data via TCP packets from the PCB to a host Python script running on my laptop. I have been focused on the board functionality, but thinking about it further, I think I might have a go at controlling the board from a remote webpage, that then send control data over to the PCB. It collects the data and then sends it wirelessly back to the remote computer for display. There would be less need for a display and encoder and button switches etc on the board.

Spent a few days exploring different data graphing techniques on the remote computer. The current favorite Python library combo is: Polars + Matplotlib + mpld3, with maybe Steamlit for some extra interactivness.

Post Reply