Sciencemadness Discussion Board

Stability and precision of Hall-based current sensors?

Fulmen - 12-11-2018 at 13:52

I'm planning a little Arduino-project, building a data-logger for measuring efficiency of a heat pump. This means measuring both voltage and current on 220V AC.
I can get suitable current transformers, but it seems like I have to make the interface myself. Shouldn't be too hard, some impedance matching and a little bias to get a DC signal.
On the other hand I can get ready made Hall-based sensors, but I'm not sure how sensitive they are to the surrounding magnetic field. Will this be a major nuisance in real-world application?

The rest of the unit seems fairly simple, voltage can be measured through a voltage divider (biased to DC). And temperature sensors come in all possible types imaginable. I'm going for K-elements as I have several probes (and a furnace) using it. Besides my beloved 2-chhannel K-thermometer crapped put, and I realized I could build a better unit myself. With the arduino I can add a data logger for 5$.

Sulaiman - 12-11-2018 at 16:03

Hall sensors drift in gain and offset over time,
these types of current sensor are common and clever
https://uk.rs-online.com/web/p/current-transducers/4362330/
the datasheet gives a good overview of the technology.

You supply +/- dc voltage and the third terminal is a voltage representation of the current to be measured/monitored,
internally they pass a current through a winding to keep the flux in the core at zero,
the core has a slot in it where a Hall sensor monitors the flux density.

The output voltage is proportional to the current in the winding which is proportional to the current being monitored.
There are many types and manufacturers offering different bandwidths, offsets etc.

Here in UK the brand LEM is to current transducers as Xerox is to photocopiers, or Biro to ballpen.
https://www.lem.com/en

Just in case it is not obvious, with a '20A' sensor,
full voltage outout will be at +/- 20 A if the wire being sensed passes through the hole once,
or at +/- 2 A if ten turns of thinner wire are used.
i.e. the hole senses amp.turns.

[Edited on 13-11-2018 by Sulaiman]

Fulmen - 12-11-2018 at 23:32

Looks like Hall-sensors are out. I like the sensor you linked to, but these are cheaper and easier to get:
https://www.dx.com/p/10a-1v-split-core-current-transformer-a...

I also noticed that this ADC should be able to measure negative input:
https://www.dx.com/p/16-bit-i2c-ads1115-module-adc-4-channel...

That simplifies wiring while also providing better resolution. Seems like a simple PnP-solution.

Fulmen - 13-11-2018 at 13:41

I could go for something like this (the current transformer would get a similar bias):
Arduino 220.png - 5kB

But by using this:
https://www.dx.com/p/16-bit-i2c-ads1115-module-adc-4-channel...

I can actually measure the straight AC signal using differential input. And at a better resolution then the board.

Twospoons - 13-11-2018 at 14:00

Have you considered some of the ASICs intended for exactly this purpose?
https://www.analog.com/en/parametricsearch/10577

Fulmen - 13-11-2018 at 14:52

Not really. A bit too advanced for me now, besides I have other uses for these components so the Arduino-route seems like the logical choice.

DavidJR - 13-11-2018 at 15:41

Do not forget that with AC you cannot simply measure RMS voltage and RMS current and then multiply - this gives the apparent power, which in many cases, may be significantly higher than the real power, depending on the load's power factor. Only for purely resistive loads are real and apparent power equal. Inductive or capacitive loads cause a shift in phase between the current and voltage waveform which throws off the power factor. And nonlinear loads - which are extremely common nowadays with switched mode power supplies - may result in totally non-sinusoidal waveforms which makes it even more difficult.

The correct way to do it is to sample instantaneous voltage and instantaneous current at a frequency significantly higher than the mains frequency - I'd say at least 10x but faster is better - then multiply to get an instantaneous power waveform. You can then compute the RMS power from this waveform and get an accurate measurement of real power.

Fulmen - 13-11-2018 at 15:55

David: That's exactly what I'm planning. The ADC has a max sample rate of 860sps, should be enough to measure 50Hz.

DavidJR - 13-11-2018 at 16:08

Quote: Originally posted by Fulmen  
David: That's exactly what I'm planning. The ADC has a max sample rate of 860sps, should be enough to measure 50Hz.


Yes, that should be more than enough. However:

Ideally you want the samples for a pair of voltage/current measurements to be taken as close to simultaneously as possible. If you use the input multiplexing of the ADS1115, then not only will your effective sample rate be halfed to 430sps but you will also introduce a phase error in the measurements.

In this case the time elapsed from one reading to the next is 1/860s = 1.16ms. Assuming 50Hz input (which has T=1/50s=20ms) then this is 5.8% of a cycle. In other words, this is a phase error of 20.88 degrees.

That's a bit too high for my liking. How much of an error in final power reading that will cause depends on the load, of course. I'd either use two independent synchronized ADCs to get truly simultaneous sampling; or alternatively pick an ADC with a much higher sampling rate such that the phase error is acceptably low.


[Edited on 14-11-2018 by DavidJR]

Vomaturge - 13-11-2018 at 16:12

If you're making your own current sensor, you could also just put a low value resistor (preferably a few percent or less of the load impedance) in series with the load, and measure the voltage across that. Keep in mind that the whole voltage measuring circuit will be at 110* volts above ground voltage, so don't connect any other grounded circuits (power supplies, displays, etc.) to it, and certainly don't touch it:o But, if you can easily isolate this "shunt resistor" (and the circuit reading its voltage) from the data logger, then this is probably the simplest current transducer there is.

*I'm assuming you have a US style electrical service, with a grounded center tap and two "live" conductors which are at 110vac relative to ground, and 220vac relative to each other.

DavidJR - 13-11-2018 at 16:26

Quote: Originally posted by Vomaturge  

*I'm assuming you have a US style electrical service, with a grounded center tap and two "live" conductors which are at 110vac relative to ground, and 220vac relative to each other.


Given that they mentioned they are in a 50Hz country using 220VAC it is incredibly unlikely that they have a bizzarre US-style two-phase supply.

Vomaturge - 13-11-2018 at 18:02

Oops. Didn't notice the 50Hz part. In the US, a big load like a heat pump uses both phases, and that is sometimes called "220v," but the voltage is supposed to be 240v, and is not usually supposed to drop below 228v under load (233v for lighting circuits). Seems like a lot of switches and fixtures have "125v" and "250v" ratings, just to be sure. I debated whether to say "240v" or "220v" in my post; one would fit with what Fulmen called his supply (50Hz aside,) and what many Americans call the big outlets behind the stove and clothes dryer, while the other would be what the US mains is officially supposed to be.

Anyhow, if your outlet has 220v with one terminal grounded, definately put the shunt resistor on that side of the load. But remember that this neutral terminal can still gain voltage relative to ground if it gets disconnected from ground for any reason. It happens more than you might think!

Why am I recommending a shunt, and then saying it's dangerous? Because it's good in certain applications. In a mains powered sensor inside a closed case, it should be just fine. The more options the merrier, and in the end, only Fulmen can narrow them down based on what other parts of the unit he can design around the sensor, vs what parts the sensor must be designed around (or selected, more likely. Just another suggestion how to avoid integrating a current transformer or calibrating a finicky hall sensor.

Fulmen - 13-11-2018 at 23:21

David: You make a good point. Using the bias circuit I can use the internal ADC, 10bit should be accurate enough.
There are also better ADCs out there, like this one: http: //mayhewlabs.com/products/extended-adc-shield

Yes, it's 230V/50hz single phase. I'd rather not use a shunt as the heat pump is permanently wired.

Twospoons - 14-11-2018 at 17:03

Quote: Originally posted by Fulmen  
the heat pump is permanently wired.


So you ideally want a split core CT, or perhaps a Rogowski coil. The second option is a little more complex as it needs an integrator.

wg48 - 15-11-2018 at 00:41

Quote: Originally posted by Twospoons  

So you ideally want a split core CT, or perhaps a Rogowski coil. The second option is a little more complex as it needs an integrator.


Can someone explain the functional difference between a current transformer and a Rogowski coil?

I know what the difference in construction is . In particular that the to toroidal winding is not complete ie the winding does not form a single turn round the conductor being sensed. In typical description of Rogowski coils that is emphasised which appears to be a practicality but irrelevant to its function.

Putting it differently is Rogowski coil nothing more than air cored current transformer operated with a high impedance load on its sense winding unlike the usual low impedance load of a current transformer?


Fulmen - 15-11-2018 at 06:40

Twospoons: I did glance at Rogowski-coils, and while they look simple enough in theory I expect it will take some time to figure out the optimal design. So I'll start with a ready-made CT and keep the Rogowski for future experiments.

Twospoons - 15-11-2018 at 14:38

Quote: Originally posted by wg48  

Putting it differently is Rogowski coil nothing more than air cored current transformer operated with a high impedance load on its sense winding unlike the usual low impedance load of a current transformer?



Pretty much. Except that with the Rogowski coil the terminal voltage is proportional to dI/dt - hence the need for the integrator. The other major difference is the Rogowski will present a much smaller load on the circuit being measured.
The lack of a rigid core can also be a big advantage in some situations.
I'd imagine the Rogowski coil would be a much cheaper option where you have to measure current in a really fat cable - big ferrite cores don't come cheap.

[Edited on 15-11-2018 by Twospoons]

Fulmen - 16-11-2018 at 12:10

Progress so far: I want to do a "feasibility-test" before ordering components, so I have started with the voltage measurements. I ended up using a 24V transformer and a 1:10 divider, and except for some weird waveforms it seems to be working. The real challenge seems to be data transfer. Even at 115k dumping each measurements pair (A0 and millis) causes excessive delays, so I've opted for reading multiple measurements into an array and then transmit that package. A set of 50 reads seems to take appr. 0.08ms, so in the range of 10ksps.
So far it seems to be doable without too much work. Next is to test a prototype ct. I will of course buy a spit-core once I know what I need, but winding a solid core for testing purposes shouldn't be too hard. Will ferrite cores work?

Sulaiman - 16-11-2018 at 12:56

If you are in a mood to wind 1000 or so turns on a small ferrite toroid then ok
if not then just buy some of these;
https://www.ebay.co.uk/itm/5Pcs-Current-Transformer-Sensor-M...:ohcAAOSwxLdb1dXr
basically a (MnZn) ferrite toroid with 10A/5ma = 2000 turns.

Twospoons - 16-11-2018 at 13:38

Quote: Originally posted by Fulmen  
winding a solid core for testing purposes shouldn't be too hard.

Not hard, just unbelievably tedious to do by hand. Especially using fine wire.

Quote: Originally posted by Fulmen  
Will ferrite cores work?

Yes they should.

Really they are cheap enough to just buy one, and save yourself a lot of time. I wouldn't bother making one unless you need something special.

What do you mean by "weird waveforms"? You should be getting sine waves. If not then something is out of wack.

[Edited on 16-11-2018 by Twospoons]

Fulmen - 17-11-2018 at 04:19

Quote: Originally posted by Twospoons  
If not then something is out of wack.


Most definitively. But I just threw the circuit together using a very long cable so I might be picking up some stray signals. I'll rework the circuit to see if that solves the problem.
I also got another problem, after reworking the code it no longer reads the voltage. This is my current code:

Code:
void loop() { int n=20; // Array size int f=1; // Delay per cycle int s=1; // Delay per array int voltage[n]={0}; int current[n]={0}; int timestamp[n]={0}; for (int i=0; i<n; i++){ voltage[i]=analogRead(A0); current[n]=analogRead(A1); timestamp[i]=millis(); delay(f); } for (int i=0; i<n; i++){ Serial.print(timestamp[i]); Serial.print("\t"); Serial.print(current[i]); Serial.print("\t"); Serial.println(voltage[i]); } Serial.println(); delay(s); }


Edit: Never mind, found it: current[n]
That's a weird one, it worked before the rewrite and I didn't touch the for-loops. Oh well...

[Edited on 17-11-18 by Fulmen]

Arduino power meter (was: Stability of Hall-based...)

Fulmen - 17-11-2018 at 04:49

I also changed A1 to A0, reading the voltage twice until I get a ct. Here's the resulting data:


Attachment: logg.csv (3kB)
This file has been downloaded 564 times

[Edited on 17-11-18 by Fulmen]

Sulaiman - 17-11-2018 at 05:55

Some bits of relevant information ;

. the linear output voltage range of a current transformer is limited.
The small c.t. that I pointed to for example is specified for a burden resistance <= 250 Ohms
so maximum output voltage is 1.25 Vrms to maintain linearity.

. you could use 50 Ohm co-ax cable with 50 Ohms terminating each end of the cable.
This would give a nett burden resistance of 25 Ohms,
with an output of 125 mVrms representing 10 Arms sensed.
The cable would be shielded against noise and terminated against reflections.

. the maximum usable output voltage increases proportional to frequency,
. operating frequency is limited by the MnZn core and/or self-resonance.

Vomaturge - 17-11-2018 at 10:50

Quote: Originally posted by Sulaiman  

you could use 50 Ohm co-ax cable with 50 Ohms terminating each end of the cable.
This would give a nett burden resistance of 25 Ohms,
with an output of 125 mVrms representing 10 Arms sensed.
The cable would be shielded against noise and terminated against reflections


You're treating it like a transmission line (traveling waves). The transformer's output is 50Hz, and is being carried a few tens of meters as far as I know. Even a whole kilometer of coax cable is about .025% as long as a 50Hz wave inside it. There's just not enough inductance and capacitance to make a noticeable impedance or reflection for such a short run and such a low frequency.

Edit: Although the inductance/capacitance/transit time of his cable isn't a problem, shielding from external noise is a good idea, if a shorter cable can't be used.

[Edited on 17-11-2018 by Vomaturge]

Fulmen - 17-11-2018 at 12:02

Quote: Originally posted by Twospoons  
Not hard, just unbelievably tedious to do by hand.

You and I might have different definitions of tedious. I just did 100 turns because there wasn't anything good on TV.

WGTR - 17-11-2018 at 13:11

Yeah, I understand the situation. I once square-braided eight feet of 128 strands of copper wire by hand. It took me an entire week, but I didn't have much to do back then.

<disclaimer> This post is likely the theoretical ramblings of a neurotic chipmunk, and holds no weight whatsoever until verified thoroughly in a lab environment. I was never a TV personality, and never played one on TV. I am also not a lawyer, and never stayed at a Holiday Inn. <end disclaimer>


IMG_4623.JPG - 1.9MB IMG_4624.JPG - 1.7MB

If you want to roll your own current sense transformer for DIY reasons, I think it would work with a reasonable number of turns in the toroid. It doesn’t have to be 1,000’s of turns so far as I can tell, although one with 1,000 turns would ironically be easier to work with once it was all put together.

Based on memory, I have a ferrite toroidal core in the lab that gives about 10 x turns2 uH (Al= 0.000,01H/t2). The minimum cross-sectional area of the magnetic path is about 1 cm2, or 0.000,1 m2.

For a current sense transformer, we don’t want the voltage response to increase with frequency. Since an inductor has a frequency-dependent impedance, we want to minimize the effects of this element as much as possible. One way to do this is to swamp it out with a real resistance (i.e., a resistor), that is ideally not frequency-dependent.

Suppose that we have our ferrite toroid with a single turn primary. At 50Hz its impedance would be +0.003,142jΩ. If we want to “short” out this element, let’s say that we add a resistor in parallel that is about 100x less in value (0.000,033Ω). It becomes easier to see what happens when we mathematically convert this circuit to its equivalent series circuit. The resistor value is about 100x greater than the inductor impedance. It’s like the inductor isn’t even there.

We have to make sure that we aren’t saturating our toroidal core, otherwise the output voltage of our circuit won’t step linearly with the input current. If the 0.000,033Ω resistor is removed, then our inductor is unloaded. With 20ARMS at 50Hz going into the inductor, 0.06284VRMS appears across it. Solving for Webers and flux density in Teslas, we can see that with our current transformer unloaded, flux density is about 11 Teslas (accounting for the fact that our sine wave is bipolar, flux density would actually be half, at 5.5T). Since typical ferrite can handle around 0.3T before saturating, we are operating way into the non-linear region. This isn’t a safety problem because the transformer is in series with the actual load (air conditioner in this case), but the measurement would be meaningless.

If we re-add our 0.000,033Ω load resistor, then things change. Taking the value from our series equivalent circuit, our effective inductor impedance becomes 0.000,000,347jΩ, and the voltage across it at 20ARMS drops to 0.000,006,94VRMS. Flux density then drops to 0.001,25T maximum, about 300x lower than our saturation limit.

Great, now where to get a 0.000,033Ω resistor? Adding a 55 turn secondary gives a voltage transformation of 55, but an impedance transformation of 3,025. Shorting the secondary with a 0.1Ω resistor would reflect this value to the primary. The secondary winding itself may be 0.1Ω itself or even more, so take care to use sufficiently-sized wire to keep from both introducing a frequency-dependent measurement error, and raising the flux in the core. The primary turn itself may have more than 0.000,033Ω of resistance anyways, but this shouldn’t matter, as we’re measuring input current, not voltage. The current going through the primary winding won’t change noticeably regardless of whether its resistance is 0.000,001Ω or 0.1Ω.

Secondary output voltage across the 0.1Ω load would be low, 0.36VRMS max at 20ARMS in, and may need to be amplified for your application.

If you can sample your ADC using an ISR triggered by a timer, then you should be able to get samples at predictable intervals. Obviously, with only one ADC you won’t be able to sample both voltage and current at exactly the same time...but wait, you can. If you can determine the exact time between samples, then it’s possible to add an RC delay line to whichever measurement comes second. If you sample the voltage, and then 5ms later sample the current, then we need a 5ms delay on the current transformer output. This is not difficult to do. It would take at least a few RC stages, because we’re trying to emulate a lossless transmission line with a distributed resistance and capacitance. We don’t want the voltage response or delay to be sensitive to frequency within our bandwidth of interest. A single RC stage alone may provide enough shift for the fundamental frequency, but the harmonics may arrive too soon, and their amplitudes may be inaccurate.

Your ADC sample rate needs to be fast enough to capture the 50Hz fundamental, and whatever harmonics that contain significant enough energy to affect measurement accuracy. I'm not sure how high it would be necessary to go, maybe the 3rd or 5th harmonic. The utility transformer probably isn't going to pass much power above those frequencies. I would hope that any rapidly-switching inverter-type compressors would be reasonably well-filtered in the unit itself.

Sulaiman - 17-11-2018 at 13:20

@Vomaturge : you are correct, there is no need to terminate the cable at 50/60 Hz,
probably the 'optimum' burden resistance is chosen for maximum ADC input voltage at maximum anticipated current.

Fulmen - 18-11-2018 at 03:32

WGTR: You certainly know more than me about ct's. But that's part of my reasoning for making one, it's usually very educational.
Nevertheless I think I have come far enough to say that this is doable. I get decent sampling rates without any special tricks and the programming isn't too hard. Last time I played with the board my problem was C++. I'm no programmer, and something abut that language turned me off the entire thing. But sometimes you just have to let things simmer in the back of the brain for a bit.

Fulmen - 22-11-2018 at 22:57

What is the best approach for timing the sampling? Perhaps a "while" or "do while" loop?

Would this work for a 1ms sample interval?

timer = micros()
for (int i=0; i<n; i++){
while(micros()<timer+i*1000){};
voltage=analogRead(A0);
current[n]=analogRead(A1);
timestamp=millis();
}


JJay - 23-11-2018 at 00:14

You might want to stick a delay into that loop to reduce power consumption.

DavidJR - 23-11-2018 at 02:45

Quote: Originally posted by JJay  
You might want to stick a delay into that loop to reduce power consumption.


No - do not do that. You want to sample the input waveform as fast as possible for the reasons I detailed in a previous post. Most of the time is going to be spent in the blocking ADC read calls anyway.

More to the point - sticking a delay call in will not reduce the power consumption. All a delay call does is has the processor spin doing nothing useful for a given time. It does not turn off the processor. It is possible to do that, but it's more complicated than just adding in a delay.

The power consumption is going to be low enough for you to not care about it at all for a mains powered application. If it was a battery-powered device, then sure, you may want to consider power consumption. But it really doesn't make much sense to spend a lot of effort trying to shave off a few microwatts if it is mains powered.

[Edited on 23-11-2018 by DavidJR]

Fulmen - 23-11-2018 at 06:20

Agreed. As long as I don't burn the board I couldn't care less about the power consumption for this application. So, back to the topic. What would be the best way to control the timing?

WGTR - 23-11-2018 at 08:56

What board and processor are you using? Can you provide a link to the board that you have?

Fulmen - 23-11-2018 at 10:49

Right now I'm using the Duemilanove: https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove

But I will probably switch to one of these in due time:
http://www.dx.com/p/produino-atmega328p-improved-pro-microco...

WGTR - 23-11-2018 at 12:04

OK, assuming the ATmega168 controller, here's a link to the datasheet:

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2545-8...

There's a list on page 88 of the various interrupts that are available for you to use. I've never used Atmel devices, but have used MSP430's and SiLabs devices. These are going to be very different in the types of features that they offer, but all micro-controllers operate in a similar basic way. I normally use C instead of C++ for things like this. You'll notice that the datasheet offers examples in both C and assembly.

When I've needed to use an on-board A-D converter, what I did was first set up an on-board count-up timer that would auto-reload with a pre-programmed value. This variable value allowed one to divide the system clock by a specific value, producing a specific time period that could be used to trigger ADC conversions. When the timer reached its maximum (0xFFFF) and rolled over to zero, it would trigger an ADC conversion and its own auto-reload. When the ADC conversion was complete, the ADC itself would trigger an interrupt, which was then serviced by the ADC ISR. You can see these various interrupt sources on page 88, and the ADCSRA and ADCSRB registers in the ADC allow you to set up auto-triggering from a timer source (pages 326 and 332).

As a "pro" tip, don't enable an interrupt unless you have the associated ISR in your code to service it. Some interrupts are cleared automatically when the ISR is called, others you may have to clear manually in the ISR so that you don't end up re-entering the ISR in perpetuity.

Page 332 shows you the different stimuli that are available to trigger an ADC conversion. It looks like you can use both a timer rollover to zero, and a comparator match.

You have your work cut out for you, but you have everything you need in this microcontroller to grab a sample from the ADC on a given input channel on a very specific time interval, at a maximum of about 15ksps.

Fulmen - 23-11-2018 at 12:32

Whoa, easy there. That's way out of my league for now, this is my first real attempt at this and I ain't no coder. It doesn't have to be perfect as long as I can use simple code.
I don't need absolute timing between sample sets as long as I can get them timestamped with a reasonable accuracy. I'm after average power consumption (testing efficiency at full power), so small timing errors shouldn't cause any problems.

JJay - 23-11-2018 at 18:44

Quote: Originally posted by Fulmen  
Agreed. As long as I don't burn the board I couldn't care less about the power consumption for this application. So, back to the topic. What would be the best way to control the timing?


WGTR really has it down, but if you change your mind, this is an easy approach that actually does decrease power consumption. It should be abundantly obvious that you shouldn't use delay(), but it's certainly not the only delay call that is available: http://www.kevssite.com/arduino-power-consumption-delay-vs-s...


Fulmen - 24-11-2018 at 00:48

Thanks. It might come in handy for future projects, but I won't use any time on it for this project.

Fulmen - 24-11-2018 at 10:43

I have to say this has been an eye opener when it comes to instrumentation. I am going to give the induction mag-stirrer (using 4 electromagnets and a stepper-driver) a try for sure, hell I might even rewire my dead ICA stirrer/heater for arduino. It has a DC motor and an optical counter, should be dead-easy to interface using cheap shields. The hotplate should be easy to figure out. Either replace or identify the temp sensor, then a SSR and a PID-library.

I've also been looking for an excuse to build test-equipment for rocket and propellant testing. The arduino should work well for data capture, and most sensors can be interfaced with existing shields. The only real investments will be a 10+MPa transducer and a decent load cell.

wg48 - 27-1-2019 at 17:25

Fulman: If you want a ready made front end for your project, there is a V,A.kW and kWh meter with a USB interface available on Banggood for £15.68. https://www.banggood.com/Peacefair-AC80-260V100A-Monitoring-...

V,A and Ah meter

wg48 - 28-1-2019 at 02:32

I found a £4 V,A and charge meter on ebay usefull for charge monitoring of batteries or perhaps electrolysis experiments. The max V and A are high at 120V DC and 20A DC but apparently its auto-ranging down to two decimal place though I doubt it has a comparable accuracy. No USB interface but it is only £4.

https://www.ebay.co.uk/itm/120V-20A-Digital-DC-Voltmeter-Vol...

[Edited on 28-1-2019 by wg48]