STM32 Hardware Development

The schematic is slightly out of date. But I have the MCP1501 footprint on the existing prototype.
When I bypassed it things started working as expected.
I know where you’re coming from, but I think it either needs further buffering, or replacing with something capable of greater output or greater capacitive loading.
There could be something else going on I’m not aware of also of course.

@dBC
Edit. Looking through AN2834 again.

Screen Shot 2020-01-20 at 22.51.59
Two 10nF and one 1uF MUST be connected on VREF+ it says.

The MCP1501 was not capable of driving above 300pF.

There are better options of voltage reference out there.
https://uk.rs-online.com/web/p/voltage-references/7618289/
https://uk.rs-online.com/web/p/voltage-references/5236131/
Both device’s datasheets are explicit in their capability to drive the required capacitiance. I’ve had a look at prices, not too bad, worth it I think. I’ll double check tomorrow.

Other news.
I tried reading VOPAMP4 as I was interested in an alternative method of offset removal.
I set it up exactly like the other ADCs and set it off filling a buffer like the others.
For some reason, the first half of the buffer fills with values around 500. The second half of the buffer fills with values around the expected value of 2048.
I’ll have another go at it tomorrow.

Yes, well let me add an -ish to that. You certainly don’t want them adding a 16° net phase error that you then have to try to deal with in software. Given you’ve got CTs and VTs outside the box introducing their own phase errors, you’re never going to eliminate the need for phase error correction even if you completely nail the LPFs. So just ensure they’re close-ish so as not to exacerbate the problem. On a similar note, did you fix the problem whereby the ADCs weren’t starting at the same time?

Yep, there were two points actually. The divider was mucking with your filter frequency, and your filter was messing with your divider ratio. What voltage divider were you after, /13? I think you got /17 (at least using your original component values). Divide that too much and you waste ADC resolution.

It’s not really a debate. You need to decide your product requirements and then design the filter to match. The primary purpose of this filter is anti-aliasing. You need to decide what bandwidth you want to measure and what ADC sampling rate you plan running with, and then what anti-aliasing filter will allow that. Starting with an arbitrary cut-off frequency (like 2kHz ) is kinda’ working backwards. Decide what filter you need to meet your product requirements, and then build it.

When building a “precision” filter (precision in the sense that you want it stable with temperature and similar from sample to sample) the usual choice of dielectric material is NPO/C0G (assuming ceramic). 220nF in NPO/C0G are big and expensive. That’s why most filters of this type use capacitors around the 10nF to 33nF range. If you lower the C you’ll need to increase the R. That has the advantage that the burden resistor will be typically small by comparison, so becomes less significant in any phase error calculations. The limit if you go too far in that direction though is source impedance, which again relates back to sampling time. So basically it’s one big optimisation problem that needs solving.

I’d probably start with 10nF caps say, and then design the VT divider and the CT filter R to meet your design goals, whatever they turn out to be.

1 Like

I haven’t looked at the ADC start timing yet.

An unloaded AC-AC adaptor we use gives just under 35V peak-peak here with about 250V, mains is a little high here.

To divide by 11 with 100/10k could be adequate. Going through the analysis method you’ve used gives an overall reduction of VTx0.0883.

Matching the cutoff frequency using a 9100 Ohm resistor at the CT:

And double checking the allowable input impedance at the STM32 ADC input, page 41 of AN2834.

Using a 10k approx 32 cycles @ 72MHz until sample taken with 1/2LSB error. We have 614 cycles due to our settings so we have huge amounts of leeway, up to about 200k input impedance it seems.

I’ve soldered on the values to the board, including the 10nF caps for the CT and VT LPF each, and the above checks out, fine enough results coming through.

I’ll have to chat with Trys and Glyn about the cutoff frequency.

C0G(NP0) capacitors look interesting, you’re right they’re more expensive.

Edit: I’ve just realised the VT filter R can be dispensed with.

Edit Edit: Found Robert’s CT report, the frequency response has a couple of interesting characteristics which cause me not to be too concerned with getting much more out our unit, frequency response-wise. https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/files/YhdcCTReportIss6.pdf

Hi @TrystanLea,
Just noting that our STM32F303 we’ve chosen for this project does not have DFU via USB as per this doco; page 89 of AN2606.

1 Like

I usually design for up to 270V RMS before clipping starts just to allow a bit of headroom. I’m not sure basing it on your one specimen in the lab is a good move. There are a bunch of “supported” VTs, and I’m really not across all of them, and what voltages they output in various countries. Check out Robert’s reports on them all to determine worst case (i.e. highest voltage with a grid running well higher than spec).

Or @Robert.Wall might have a good rule-of-thumb for a suitable V divider for a 3.3V system across the range of VTs. Come to think of it, the OEM team have been using 3.3V systems for quite a while now, so unless you think they got it wrong, you could just stick with their divider ratio.

Speaking of clipping… it looks like you only have protection diodes on the negative swing on all the analog inputs. You may want to look at adding them for the positive swing as well.

I didn’t find much discouraging news in there:

At 2.5 kHz the amplitude error had risen to 3% whilst the phase error had increased to 10 degrees.

If I’ve done the arithmetic correctly, your 1744 Hz cut-off would turn that 3% error into a 36% error. The reported 10 degree phase error at that frequency doesn’t matter at all - phase error only matters when you’re calculating real power. There’ll be no significant contribution to real power up at those frequencies because V is so close to pure sine wave, so the dot product effectively filters out all the harmonics in I for that calculation. Regardless of how distorted your I signal is, real power pretty much all happens at the fundamental, with the tiniest bit leaking in from the harmonics if your V is a bit distorted (flat tops etc).

The symptoms you’ll see if you filter too hard is an under-read on Irms and all the readings that derive from it: apparent power and power factor (over-read), but you’ll need a very distorted load to see it. You can see a few pics of my most distorted circuits here. That’s probably as good a starting point as any to decide how high you want to go. The CT seems up to the job whatever you decide.

I wouldn’t worry too much about using the full dynamic range of the ADC input for voltage. It isn’t as if the voltage itself varies over a wide range, whereas the current does.

It’s going to be far more important to cater for as wide a range of transformers as possible, and it would be nice to be able to use a “proper” designed-for-the-job voltage transformer, such as the http://www.magnelab.com/products/potential-transformer-output-proportional-input-spt-0375/ (though not as the default standard item, at £36 each from the UK distributor).

The original 120/10 works fine with that. Matching the CT input with a 10k will bring the cutoff even lower, however like you say there doesn’t seem to be a great loss in doing so.
If I were being picky I could go with something I worked out now; 91/8.2k (12.1 ratio) matching at the CT with the 8.2k gives us that 2kHz cutoff again.

I’ll look into that, thanks.

Doh! I’m still getting to grips with when phase shift occurs.

Seems in that case there’s only value in closing the cutoff frequency gap between the CT and VT filters for the sake of the phase-error native to the board.

It’s crossed my mind to have the 120k of the VT divider switched out by a DIP switch for this reason. I mentioned this in the lab yesterday, as we might in the future want to make a voltage sensing unit ourselves, one that’d help 3-phase users, not having to install 3 separate sockets for three AC-AC adaptors. I don’t see a reason to replace the 2.1mm barrel jacks for anything else fancy-for-the-purpose necessarily, as they can be reused in a cabling scheme, they’re just a type of connector.
I’ll at least add the footprint for a DIP switch, we’ll see how ideas develop on this.

I don’t think things are as tightly coupled as maybe you think they are. You get to choose your voltage divider and you get to choose your cut-off frequency. For example, 120/10 and 240/20 give you the exact same voltage divider but very different cut-off frequencies. Subject to R value availability, you can pretty much set each of them to whatever you want.

There’s also some value in providing a load for the v.t. - especially if it’s a normal transformer (aka a.c. adapter) and not designed for the purpose, as the load will lower the core flux and should reduce distortion. But the idea of wasted power is anathema to some and gets rejected out of hand.

What amount of load are we talking about? Say for our typical AC adaptor?

How do you envisage that working with regards getting to the three V signals? Some sort of electrician installed DIN-rail mounting?

I’ve never checked that, because I know it would be a non-starter.

Sounds like we’re in the 1.21 Jigawatts ballpark :wink:

I don’t have enough experience to suggest a solid and feasible idea.

The only idea which attracts my crazy inventor-self I wouldn’t dare suggest so late on a Tuesday night.

I think a sensible unit would be a voltage-sensing-transformer based unit. And I believe 4 connections would be necessary on the dangerous-side. The three phases and Neutral. Downstream, three cables would be coming from the output of this box 2.1mm plugs and jacks for simplicity’s sake, the cables terminate at the barrel jacks plugged into the stm32Tx unit we’re working on. These DIP switches would be switched in to bypass the 120k input impedance…
DIN rail mounted, sure why not.

edit: @dBC :wink:

I was mostly interested in how you do away with “not having to install 3 separate sockets”. I guess you install a 3-phase socket, or you whack it on the main DIN rail where you can get access to all 3 Vs.

Inside the consumer unit?
I really don’t have enough experience, Glyn would have some good ideas on this I bet.

What’s a 3-phase one of those? I don’t think one exists - you’d almost certainly be looking at a “small industrial” distribution board for 3-phase; or for domestic, I think 3 separate consumer units would be much more likely.

And then, if you have one consumer unit per phase, how do you have a 3-phase socket connected to those, because you need a linked circuit breaker for safety and to prevent single-phasing should a motor be connected. It gets very messy.

I believe you.
Hmm. There’s a 3-phase distribution board in one of the sheds here where I live. It serves the wood workshop machinery. I’ll have a look inside tomorrow. Poke around (not really).

Still alive.

I think it’s my common sense telling me, something like “don’t bloody touch anything”.

The question of what physical unit @dbc could be conceived to monitor voltage and current at a set up like this, I’m still not sure.

I guess one way of doing it could be to have a unit with…
. A strong enclosure with anti-tamper top.
. Chunky screw terminals for 25mm meter tails.
. Battery power, a year’s worth a data guaranteed, radio transmitted to an emonBase or stored locally.

That’s for something mounted in-line with the cables after the main breakers. Basically a matter of designing a 3-phase meter.

Beyond that, inside the large metal dist. board I imagine the DIN rail possibilities mentioned.