racklet / electronics-prototyping

Design files for electronic components for use in Racklet
Apache License 2.0
3 stars 0 forks source link

PSU power monitoring circuit experiments #1

Open chiplet opened 3 years ago

chiplet commented 3 years ago

Lab notes about adding power measurement circuitry in the the latest power supply board.

Some old notes about the PSU circuit design: https://github.com/luxas/special-computing-machine/issues/2

chiplet commented 3 years ago

The power supply is designed to output 5.1V. In reality, the output voltage is around 5.05V.

The jumper wires I have laying around have too high resistance for reliable power delivery. A single jumper wire has a resistance of over 1Ω. With two jumpers in parallel the measured resistance seems to vary in the range of 0.3Ω to 0.5Ω.

Based on some initial testing with a USB-C power monitor, a Raspberry Pi 4 draws around 0.5A when idle and around 1A while running a stress test on all four cores. The corresponding voltage drop over power wires is around 0.15V to 0.5V, which is enough to cause throttling due to too small input voltage (with this setup the measured voltage on power pins on the Pi side is about 4.7V).

chiplet commented 3 years ago

Proper wiring fixes the undervolting issue with idle load current. There's still a slight voltage drop over the wires and current sensors connected in series. Even with the additional current metering the voltage drop is only about 30mV and the Pi input voltage is around 5.02V which should be good enough. I still need to make sure that the voltage drop over the ammeter doesn't grow too large with full system load (over 1A current draw).

chiplet commented 3 years ago

ACS724TLLC-10A Measurements

I'm measuring the ACS724 sensor I have at hand to get more familiar with it. The measurement setup is simply a variable current source, which is used to drive the current to be measured, and a voltmeter measuring the sensor output. The PSU will most likely not use this exact model but it's nevertheless useful to see how sensors from this family perform.

When powered from the 5.1V rail, the output voltage conveniently maps to below 3.3V so the current sensor can be directly connected to a 3.3V microcontroller ADC without any analog circuitry in between. This model is a bidirectional current sensor, which is not required for this application. Unidirectional models have higher sensitivity and can thus measure current with higher precision. Based on a quick look, the ACS723XLCTR-10AU model would be much more suitable for this application.

ACS724TLLC-10AB_plot

luxas commented 3 years ago

Today myself and @chiplet met for a couple of hours to investigate the ACS in more detail.

TL;DR; There are errors everywhere hehe. We need to in a qualitative way be able to measure them.

Our test setup was as follows:

--------------      ---------------------------      ----------------
PSU Vcc       | -> | Vin    ACS  Vout          | -> |  ADC          |
        GND   | -> | GND                       |    |    RPi Pico   |
        Vcc   | -> | +                         |    |               |
        GND   | -> | +          -       -      |    |               |
--------------       -------------------------      -----------------
                                |       |
                            -----------------
                            | Vcc     GND   |
                            |     Load      |

i.e. the PSU powered both the ACS itself AND the load (e.g. the RPi or an adjustable resistive load). The Vout from the ACS was dependent on the Vin, which was connected to PSU's Vcc. The Vout from the ACS was connected to an ADC of the RPi Pico for analog reading.

Here are our findings:

  1. The 12-20V -> 5.1V step-down we used as Vcc for the ACS produced high-frequent ripple in the ACS output as well, because the offset of the ACS is calculated as 0.5*Vcc. The high-frequent ripple averaged out over time however, so by using a moving average, we were able to reach results close to the desired offset voltage 2.550V
  2. The RP2040 ADC also needs to be calibrated for the offset, e.g. when an oscilloscope shows that the average voltage is 2.550V over time, the RP2040 gave us the 2.575V average, which is an extra 25 mV error. The ACS might also have a +/- 10mV offset error, according to the datasheet. In order to mitigate this we need to in the software calibrate the readings by
    • making sure that there is no current going through the ACS
    • reading n samples to average out ripple
    • using the resulting voltage as the offset for all other readings
  3. The ACS accuracy is proportional to the current, which means that the more current there is, the larger the error. We observed that our tested ACS model, which had a min/max sensitivity error of +/- 2%, actually bounded the error in that range, for some sensible current readings we tested. There is also a nonlinearity factor around +/- 1%.
  4. The power usage of the Pi when idle seems to be periodic every ~2 seconds. Our hypothesis is that some kind of kernel background jobs or cleanups cause this.

One good article to read if you're interested in the Pico performance is https://hackaday.com/2021/03/15/raspberry-pi-pico-adc-characterized/

luxas commented 3 years ago

The periodicness mentioned in 4 can be seen in the following picture. The high-frequent ripple mentioned in 1 is also visible here: index Figure 1: Raw ADC readings from the Pico on the y axis, and time in seconds on the x axis. Sampled using 1 kHz. Blue is the raw readings and the orange is a low-pass-filtered signal.

In order to be able to calibrate the readings as mentioned in 2, we need to be able to switch the load off (i.e. I=0A) while still keeping the ACS on (i.e. Vout=Vin*0.5). To accommodate this, we concluded that the ACS should be connected to the USB 5.1V channel, instead of the PSU 5.1V rail, so that the Pico can turn off the PSU, but still read voltage from the ACS, as can be seen in the following picture:

Screenshot from 2021-05-03 21-42-29 Figure 2: Extract of the HAT design where the PSU, ACS and BMC (e.g. the Pico) are in the scope of this prototyping.

We concluded that the analog voltage read of the PSU output probably doesn't make any sense for figuring out the power usage (because it anyways averages out to 5.1V), but it might be very useful for diagnostics if the PSU for some reason does not work.

luxas commented 3 years ago

Two additional pieces of data:

1khz-cpu-stresstest Figure 3: At peak CPU load, the periodicity of the power usage as could be seen in Figure 1 is now not as visible anymore.

rpi-current-calibrated Figure 4: In this graph we can see four different stages. The sampling frequency is 500 Hz, and the data points are now reported once per second. At around 0.4A, the Pi is idling, with quite high variation as could be seen in Figure 1. At around 0.8A, the CPU is being stress-tested. As could be also seen in Figure 3, the variation in current is now smaller. At 0.16A, the Pi has halted, which means it's in a power-save mode but not completely shut down. Lastly, when it goes on minus, the Pi is actually shut off. This is a measurement error, we should figure out how to make this approach zero as expected.

Thanks @chiplet for all the great work!