# Pump Shaft Monitor: Current Sensing #1

30 Dec 2020embeddedelectronics

One thing I need to do for my pump monitor is to determine when the pump is running. I’m going to do this by measuring the current flowing in the power cable to the pump. That seems like it ought to be an easy thing to do, but doing it safely (it’s a 240V AC mains cable to the pump) and reliably is more complicated than I expected. There might be a simpler way to do things than what I’m trying to do, but this is a good opportunity to do a little bit of analogue electronics and to learn some things. (My analogue electronics skills are negligible, so I’m always on the lookout for small projects or parts of projects that have the right “challenge level” to help me get better!)

## Measuring current

If you have a varying current running in a wire, that current produces a magnetic field around the wire. If you put another wire in that magnetic field, you can measure the induced current in this second wire and so infer the current in the first wire. Sounds easy, right?

First problem: a normal mains power cable has three conductors inside it, the live wire, the neutral return path wire, and an earth connection to ground. The currents flowing in the live and neutral wires are (more or less) opposite and equal, so their magnetic fields cancel out. If you get close enough to the individual conductors in the cable, you can measure the field around the live conductor, but it’s not easy.

This isn’t such a big problem in my application because I need to split the incoming power cable anyway—I need power to run the electronics I’m using as well as the pump, so I was planning to have a normal domestic junction box to do the splitting. That means the three conductors in the power cable will be accessible, so I can do something with the live conductor on its own.

That basically means some sort of current transformer around or next to the live conductor to produce a sense current signal I can measure.

## Rogowski coils

When I started this, I didn’t know anything about the options here, but a bit of reading and searching for parts on Mouser led me to Rogowski coils. These are toroidal coils that you wrap around the conductor whose current you want to measure. The arrangement of the Rogowski coil means that the voltage at the output terminals is proportional to the rate of change of current in the conductor being measured. That seems weird, but it’s fine for my use case because I’m measuring 50 Hz AC current, which is a sinusoidal signal, so that time rate of change will also be a sinusoidal signal.

One of the manufacturers of these things is a company called Pulse Electronics. Here’s a datasheet for some of their coils: I’m using the PA3208NL. The transfer coefficient between the sensed current and the output voltage is 383 μV/A, so these are going to be small voltages! (The pump I have is a 400W model, so at 240VAC, that means a current of about 1.7A, or a coil output voltage of 638 μV.)

So, the basic plan is: put the live conductor from the power cable through the centre of the Rogowski coil, then... do something with the output voltage from the coil. There are integrated devices you can buy to do the processing for these things, but they feel like overkill for my application. I only really care about whether the pump is on or off, while all the monitoring chips I could find are intended for use in metering applications, so they’re much more sophisticated than I need.

For what I need, it seems obvious that the first thing to do is to amplify that signal from the coil, then there needs to be some sort of thresholding to decide whether the pump is on or off. The signal from the coil is an AC signal, so it seems as though it might be easiest to rectify it, filter it, then threshold it with a comparator to get an on/off output signal. I had only vague ideas how all this would work, so I did some simulations in LTSpice to figure things out.

## Analogue front-end simulations

### Simulated Rogowski coil signal

The first thing to think about is how to simulate the coil output voltage. I set this up as a 600 μV peak-to-peak 50 Hz signal, centred at 2.5V. I’m going to power all this from a single 5V supply, so to allow the maximum swing for amplified signals, I want all the AC signals to be referenced to 2.5V.

I use the delay and cycle count parameters in LTSpice’s SINE voltage source to generate a signal that simulates a switch on and switch off of the pump:

The simulated signal looks like this (click for large view):

To generate the 2.5V mid-point supply that this is referenced to (and that’s used as a reference for the later processing stages), I use a simple follower circuit—the Vmid net is held at 2.5V:

### Coil voltage amplification

The first step to processing the coil output voltage is to amplify the 600 μV peak-to-peak signal to a more reasonable range. This is done with two non-inverting op-amp amplification stages, set up give a total gain of 3312. This gives about a 4V peak-to-peak output. The opamps are biased to amplify the signal about the 2.5V mid-point:

The amplified signal looks like this (click for larger view). It’s identical to the coil output voltage signal plotted above, except that the amplitude of the variations is much larger.

### Rectification

The next step is to decide how to distinguish between “pump off” and “pump on”. When the pump is off (i.e. there’s no varying voltage output from the Rogowski coil), the amplified signal sits at the 2.5V DC midpoint. When the pump is on, the average DC level is the same, but we have this 4V peak-to-peak 50 Hz sinusoid superimposed on it. Filtering the amplified signal at this point won’t give us anything we can use to distinguish between the on and off states. Instead, we’re going to rectify the signal about the 2.5V mid-point, using an active rectification circuit based on a couple of opamps (copied from The Art of Electronics, Figure 4.63 in the third edition, to be precise).

The output of the rectifier looks like this. It’s what you’d expect: the signal is “folded” around the 2.5V mid-point. We now have something suitable for distinguishing between the on and off states. When the pump is off, the average level of the rectified signal is 2.5V. When the pump is on, the average level of the rectified signal is significantly greater than 2.5V, so we can use some sort of comparison to a threshold to determine the pump state.

### Filtering and thresholding

So now we can low-pass filter the rectified signal, and threshold it with a comparatoer (with the threshold set to 2.75V, which should be a good level for distinguishing between on and off):

The filtered (green) and thresholded signals (cyan) look like this. The thresholded output looks like a pretty good on/off indicator!

## Current sense circuit

So, to my eye, the simulations look really good. That caused me to do a stupid thing. I pressed ahead and designed a circuit and incorporated it into an interface board for this pump monitor, sent the design to Aisler, got the boards, assembled them, and... they didn’t work!

Here’s the circuit design (click to embiggen):

and here’s the PCB layout with the current sensing portion highlighted (it’s designed to sit on top of a Raspberry Pi):

Board assembly went fine (it’s not very complicated), and I was pretty pleased with coming up with a solution for this. But that didn’t last very long, because testing was a big disappointment.

## Testing

To test the thing, I took an mains power extension cable, split the outer insulation somewhere in the middle for about 15 cm, then pulled out the live conductor, cut it and stripped the ends. The neutral and earth conductors I wrapped with some insulating tape to keep things tidy. I could then thread the live conductor through the centre of the Rogowski coil and connect the ends of the live conductor back together using a standard domestic cable clamp. (This will all be inside a junction box when it’s in use, so it’s not a bother having the individual conductors from the cables split out).

I’ve crimped a 0.1” connector to the cable from the Rogowski coil and that plugs in to the connector on the board. I’ve got test points in a bunch of convenient places on the board so I can look at the amplified signal from the coil, the rectified signal, the filtered signal and the eventual output.

I used the split power cable to connect a desk fan to the mains power, just to have a load I can switch on and off, and used my Analog Discovery 2 in oscilloscope mode to look at the signals at some of those test points.

Here’s what the amplified signal looks like, measured between the AMPL test point and ground, when the fan is switched on (click for a big version):

What?! That’s totally different to the simulations! The signal should be a sinusoid centred on 2.5V, but instead it’s an AC signal centred on ground! And when the fan is off, the signal at the AMPL test point looks like this—just noise about ground, instead of being a steady 2.5V DC level:

As you’d expect, that means that nothing else works right, since the rectifier is set up to rectify a signal centred around 2.5V and the comparator is set up to use a threshold of 2.75V from the filtered rectified signal...

I tried to capture the signal directly from the Rogowski coil, but the small amplitude of the signal from the coil is a bit of a challenge for the AD2’s scope inputs. The best I could get looks like this with the fan on:

You can sort of see a small 50 Hz signal (of the expected amplitude, as far as I can tell), but it’s centred near to ground (there is a small offset), rather than around 2.5V.

## What went wrong?

It looks like I made a false assumption right from the start. I assumed that biasing one end of the Rogoswki coil at 2.5V would mean that the output signal from the coil would be a 600 μV peak-to-peak sinusoid centred on 2.5V. That appears not to be the case, and I need to understand why. Instead the output signal from the coil doesn’t seem to depend on that DC bias at all!

What should I have done? I should have breadboarded the circuit to make sure that it really did work like the simulations! And why didn’t I do that? Because I was impatient and wanted to order all the parts in one go, so I didn’t have the Rogowski coil to hand to do any testing. So now I’m going to need to respin the board, wasting time and money. Pretty silly. I thought that it might be possible to bodge something in software for the moment, since I thought there was a slight difference in the current sense final output signal between the on and off states, but more careful testing indicates that that’s not the case, so this is a total loss.

Anyway, lessons learned. Simulation is fine, breadboarding is better. I’m not good enough at analogue electronics yet to go straight from simulations to schematic to PCB. At least not if I expect things to work!