I'm a slightly overchallenged undergrad ee student. I'm working on a project where I'm supposed to build an automated setup to measure hard disk currents over time.

I want to use a Current Shunt Monitor (CSM) connected to an ADC which is connected to a Linux machine.

I've already picked a CSM (AD8211). I need an ADC now but I'm somehow failing to find a proper way to interface it to linux. I was thinking the EVAL-AD7091R might do. I found the libiio form analog devices but I'm not sure if it does what I want it to do. Can I control the eval board by python somehow through libiio? Just tell it to start sampling? Is there a library that I can use which let me do certain things with the board?

What needs to be done essentially is to plug in a HDD over SATA and run certain operations like start up the disk, read and write and measure the current simultaneously. I want to do this by fio. Since SDDs are very fast we agreed on a sampling rate of 1Msps. 200ksps is the absolute lower bound, however.

Sorry for my vague language. If anything is not clear please ask. I try my best to explain better.

Any help is hihgly appreciated.

  • \$\begingroup\$ learn.adafruit.com/raspberry-pi-analog-to-digital-converters/… \$\endgroup\$ Apr 4, 2018 at 13:22
  • \$\begingroup\$ You are looking for a DAQ (data acquisition), if you use it to google, you will find some boxes. Eg: dataq or advantech. \$\endgroup\$
    – Jeroen3
    Apr 4, 2018 at 13:59
  • \$\begingroup\$ I aggree with @Jeroen3 ... but if you MUST use an ADC ... there are some development boards ready to communicate with a PC .... since you are using a high sampling rate (quite high) get something that has a decent buffer size, or depending oif you are using an embedded board (raspberry pi, BBB, etc) maybe you could configure your linux to communicate with the board via DMA in a way that scheduling doesn't bother you \$\endgroup\$
    – morcillo
    Apr 4, 2018 at 16:50
  • \$\begingroup\$ Why do you need to know the current? Would lowpass filtering the current sense to get a moving rms be good enough? You'd be able to sample much slower. \$\endgroup\$ Apr 4, 2018 at 19:24
  • \$\begingroup\$ Thanks! I'm gonna look int DAQs. We need the current for system design that is holding several HDDs. \$\endgroup\$
    – aJazz
    Apr 5, 2018 at 8:57

3 Answers 3


we agreed on a sampling rate of 1Msps. 200ksps is the absolute lower bound, however.

The little detail that changes everything...

You can't do that by wiring an ADC to your computer directly. The computer uses a multitasking OS which is unable to interrupt 1 million times per second to trigger a conversion.

You need some hardware interfaced with your ADC, which will run it at 1 Msps, buffer the data, and forward it to the computer via a connection of suitable bandwidth like USB or Ethernet.

The easiest would be to use a digital storage scope with a record function, or a streaming USB scope, or a data acquisition (DAQ) system.

You can use a USB microcontroller too, provided it has enough USB bandwidth and power, and the proper interface for your ADC. This will be quite a bit of work though, but you can probably find an ADV eval board with all this stuff. This also needs software on the PC though.

If your computer has audio inputs, you can also use these as ADCs, but you will need to remove the AC coupling caps, and perhaps the software highpass filter, that depends on the chipset. That won't give 1Msps though.

Another solution would be to lowpass the signal to reduce the sample rate, but you'll lose time resolution.

Before designing (or buying) an acquisition system, it would be wise to check what the signal actually looks like. Especially its bandwidth. Therefore, try a digital scope first.

Now, about bandwidth... AD8211 has a pretty good bandwidth (300kHz) so if you use a low value shunt resistor you will be able to exploit the full bandwidth. However the resistor will be in series with the supply, which will cause the voltage to drop a little bit.

This should not be a problem as your SSD won't be powered by the +5/+12 lines directly, rather it will have a few switching regulators onboard to generate lower voltages. So if the supply drops by a fraction of a volt due to the sense resistor, it will still work fine. The current measurement will be a bit higher than without the sense resistor though, as a switching regulator powered from a lower voltage will draw more current at constant output power. So try to use a small resistor value.

If you include an additional regulator as suggested by Toni, then your measurement bandwidth will be that of the regulator (ie, a few kHz unless you take some desperate measures).

Whether you actually need this huge amount of bandwidth remains to be seen!...

  • 1
    \$\begingroup\$ 200ksps is totally possible with a Linux box if your CPU has multiple cores. You can hog one CPU in a kernel thread and sample as fast the CPU core allows it. \$\endgroup\$
    – Janka
    Apr 4, 2018 at 19:20
  • 1
    \$\begingroup\$ I'd look at why the OP needed to know this information. I suspect that low-pass filtering to capture something akin to rms would be a realistic option. Always ask WHY! \$\endgroup\$ Apr 4, 2018 at 19:24

With a sampling rate of at least 200ksps, you have to dedicate one CPU core exclusively for sampling data. This is possible with Linux, even within a user process, but you need a multicore CPU then. A Raspberry Pi 3 can do it as it has four cores available to the user. It also has an exposed SPI which may help you interfacing.

But, no chance to do that with python, you need a minimal C process with SCHED_FIFO priority and locked CPU and locked memory which bitbangs the necessary control signals to the ADC, then receives the data and buffers it into a shared RAM.

Another process with standard priority may then read the buffered data and store it to the harddisk.


(moved from comment to answer at operator's suggestion, though this is only a partial answer)

You will need some kind of circuit to keep the hard disk voltage constant, otherwise your results will be imprecise.

To do this yo will need some kind of "old design" linear regulator (not switching, linear) and place the measuring resistor at the entry of the regulator. You will need to also measure the current taken by the regulator itself, but that's fairly easy to do.

  • \$\begingroup\$ I don't understand why it is necessary to keep the disk voltage constant when the task is to log current over time. \$\endgroup\$ Apr 4, 2018 at 15:18
  • \$\begingroup\$ Because you probably want the disk to operate in "normal" conditions. If the input voltage goes down some hundred mV when it surges big current the disk operation will certainly not be "normal". You will be measuring a different behavior than the one you wanted to measure in the first place. \$\endgroup\$ Apr 4, 2018 at 21:39
  • \$\begingroup\$ I limited the voltage drop to 1% which lies below the tolerances of the psu (of 5%). Which means 50mV drop for 5V and 120mV drop for 12V. \$\endgroup\$
    – aJazz
    Apr 5, 2018 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.