STM32 Development

No, the Irms is always a steady 2047.88
The Vrms is very changeable - I assume just noise because it’s not connected.
I need to get another set of CT’s and an AC/AC power adapter, then hopefully I’ll get some meaningful readings.

Paul

hmmm… I hope that’s not a bug :frowning:

Is the shield plugged into the Nucleo, or are the Nucleo inputs totally floating?

That’s what I thought too. However here’s a schematic

thinking that was a typo, I’ve buzzed out a pcb and found it is correct.

The wrong side of the CT/burden gets grounded, so instead of the expected behavior it is grounding the mid-rail and the ADC input is then pulled to ground via the 33R burden.

There is no such mechanism on the AC input so that ADC is left floating.

So now I too question the unconnected results as I would of expected the Irms to have been much lower.

As were my remaining 3 unpopulated CT inputs, they too were a fixed 2047.88 exactly. I’ll do some connected v unconnected comparisons in a bit

The shield is attached (as well as the link).

Paul

My shield hasn’t turned up yet, but I should be able to mimic that just with a resistor bung straight into one of the current input holes on the Nucleo. It might be something to do with the offset removal maths. Does a multimeter on any of the current inputs read 0V?

Both ends of the burden are 0v for me, if I ref to VCC they are both at 3.3v.

Yeh, I’ve replicated it by just grounding all my inputs. Looks like a maths issue. Expect a patch soon.

CPU temp: 29C, Vdda: 3304mV
0: Vrms: 1145.40, Irms: 41.06, Papp: 47028.46, Preal: 229.47, PF: 0.005
1: Vrms: 1145.40, Irms: 2047.88, Papp: 2345638.25, Preal: 2673.99, PF: 0.001
2: Vrms: 1145.40, Irms: 2047.88, Papp: 2345638.75, Preal: 2673.90, PF: 0.001
3: Vrms: 1145.39, Irms: 2047.88, Papp: 2345630.25, Preal: 2770.55, PF: 0.001
CPU temp: 29C, Vdda: 3304mV
0: Vrms: 1144.57, Irms: 40.84, Papp: 46745.62, Preal: 236.96, PF: 0.005
1: Vrms: 1144.57, Irms: 2047.88, Papp: 2343937.25, Preal: 1980.77, PF: 0.001
2: Vrms: 1144.57, Irms: 2047.88, Papp: 2343937.75, Preal: 1980.78, PF: 0.001
3: Vrms: 1144.54, Irms: 2047.88, Papp: 2343879.75, Preal: 2062.65, PF: 0.001
CPU temp: 29C, Vdda: 3304mV
3: Vrms: 668.60, Irms: 2047.88, Papp: 1369220.62, Preal: 2514.68, PF: 0.002
0: Vrms: 668.62, Irms: 40.71, Papp: 27217.23, Preal: 139.99, PF: 0.005
1: Vrms: 668.62, Irms: 2047.88, Papp: 1369244.50, Preal: 2432.89, PF: 0.002
2: Vrms: 668.62, Irms: 2047.88, Papp: 1369244.62, Preal: 2432.91, PF: 0.002
CPU temp: 29C, Vdda: 3302mV
2: Vrms: 62.37, Irms: 2047.88, Papp: 127720.05, Preal: 2871.00, PF: 0.022
3: Vrms: 62.40, Irms: 2047.88, Papp: 127797.09, Preal: 2951.69, PF: 0.023
0: Vrms: 62.37, Irms: 40.54, Papp: 2528.41, Preal: 87.57, PF: 0.035
1: Vrms: 62.37, Irms: 2047.88, Papp: 127720.03, Preal: 2870.98, PF: 0.022
CPU temp: 29C, Vdda: 3302mV
2: Vrms: 62.33, Irms: 2047.88, Papp: 127642.02, Preal: 2791.56, PF: 0.022
3: Vrms: 62.36, Irms: 2047.88, Papp: 127712.30, Preal: 2866.68, PF: 0.022
0: Vrms: 62.33, Irms: 40.41, Papp: 2518.43, Preal: 138.58, PF: 0.055
1: Vrms: 62.33, Irms: 2047.88, Papp: 127641.99, Preal: 2791.55, PF: 0.022

with v5 loaded I get pretty similar results to Paul. I have a CT plugged in “ct1” with no load and initially I had a 9v AC input too for the first 2 printed blocks, then I whipped it out, so the last 2 blocks are with a floating AC input.

I quickly scanned your maths and it didn’t look right, but it was late…
I’ll look again later today.

Yeh, I got the divide and the sqrt() around the wrong way in the RMS calculation!

OK, I’ll release a new v6 tarfile later tonight, but in the meantime, the fix to power.c is pretty simple so @pb66 you might just want to patch it into your github, or wait for the v6, whichever is easiest. I also bumped the Version number to 1.2 in the startup banner (not shown here).

*** power.c.v5	2018-03-27 21:04:45.632134108 +1000
--- power.c	2018-03-27 21:25:38.706592139 +1000
***************
*** 118,131 ****
        //
        // And remove its RMS from the accumulated RMS
        //
        local_stats.sigma_v_sq -= (float)(Vmean * Vmean);
        local_stats.sigma_i_sq -= (float)(Imean * Imean);
  
        //
        // Calculate the RMS values and apparent power.
        //
!       Vrms = sqrt(local_stats.sigma_v_sq/(float)count);
!       Irms = sqrt(local_stats.sigma_i_sq/(float)count);
        Papp = Vrms * Irms;
  
        //
--- 118,133 ----
        //
        // And remove its RMS from the accumulated RMS
        //
+       local_stats.sigma_v_sq /= count;
+       local_stats.sigma_i_sq /= count;
        local_stats.sigma_v_sq -= (float)(Vmean * Vmean);
        local_stats.sigma_i_sq -= (float)(Imean * Imean);
  
        //
        // Calculate the RMS values and apparent power.
        //
!       Vrms = sqrt(local_stats.sigma_v_sq);
!       Irms = sqrt(local_stats.sigma_i_sq);
        Papp = Vrms * Irms;
  
        //

It’s improved my PF with the signal generator too. It was just slightly off 1 (at about the 3rd decimal place) and I put that down to some uncorrelated noise that was showing up in the RMS number, but not in the dot product. But with that fix in place, Real and Apparent are insanely close…

emonTxshield Demo 1.2                                                                                        
Patch PA0 through to PB14 for V!!!                                                                           
CPU temp: 38C, Vdda: 3304mV                                                                                  
CPU temp: 38C, Vdda: 3302mV                                                                                  
0: Vrms: 1199.63, Irms: 1199.38, Papp: 1438808.88, Preal: 1438810.75, PF: 1.000                              
1: Vrms: 1199.63, Irms: 1199.06, Papp: 1438419.75, Preal: 1438394.62, PF: 1.000                              
2: Vrms: 1199.63, Irms: 1199.05, Papp: 1438417.88, Preal: 1438419.25, PF: 1.000                              
3: Vrms: 1199.59, Irms: 1199.05, Papp: 1438368.00, Preal: 1438352.62, PF: 1.000                              
CPU temp: 38C, Vdda: 3302mV
1 Like

so I have put the corrections into another (fix_maths) branch pending review. (see fix_maths · stm32oem/stm32tests@66a87d9 · GitHub) [branch now deleted as the changes are in the master branch]

This is my output after flashing

emonTxshield Demo 1.1
Patch PA0 through to PB14 for V!!!
CPU temp: 30C, Vdda: 3306mV
CPU temp: 30C, Vdda: 3302mV
0: Vrms: 0.03, Irms: 0.02, Papp: 0.00, PrCPU temp: 30C, Vdda: 3302mV
0: Vrms: 0.03, Irms: 0.02, Papp: 0.00, Preal: 93.21, PF: 145989.391
1: Vrms: 0.03, Irms: 0.23, Papp: 0.01, Preal: 2643.36, PF: 355324.750
2: Vrms: 0.03, Irms: 0.23, Papp: 0.01, Preal: 2643.36, PF: 355313.250
3: Vrms: 0.03, Irms: 0.23, Papp: 0.01, Preal: 2795.30, PF: 365186.438
CPU temp: 30C, Vdda: 3302mV
0: Vrms: 0.47, Irms: 0.02, Papp: 0.01, Preal: 63.16, PF: 7055.821
1: Vrms: 0.47, Irms: 0.23, Papp: 0.11, Preal: 1175.71, PF: 10830.193
2: Vrms: 0.47, Irms: 0.23, Papp: 0.11, Preal: 1175.71, PF: 10830.193
3: Vrms: 0.47, Irms: 0.23, Papp: 0.11, Preal: 1266.90, PF: 11672.945
CPU temp: 30C, Vdda: 3304mV
0: Vrms: 2.98, Irms: 0.02, Papp: 0.06, Preal: 227.31, PF: 3590.232
1: Vrms: 2.98, Irms: 0.23, Papp: 0.68, Preal: 1222.68, PF: 1791.838
2: Vrms: 2.98, Irms: 0.23, Papp: 0.68, Preal: 1222.77, PF: 1792.022
3: Vrms: 2.98, Irms: 0.23, Papp: 0.68, Preal: 1378.88, PF: 2020.809
CPU temp: 30C, Vdda: 3304mV
3: Vrms: 2.97, Irms: 0.23, Papp: 0.68, Preal: 2416.33, PF: 3542.793
0: Vrms: 2.97, Irms: 0.02, Papp: 0.06, Preal: 248.25, PF: 4068.411
1: Vrms: 2.97, Irms: 0.23, Papp: 0.68, Preal: 2259.68, PF: 3313.200
2: Vrms: 2.97, Irms: 0.23, Papp: 0.68, Preal: 2259.62, PF: 3313.120

Empty CT plugged into ct1, first 2 blocks with no AC, second 2 blocks with AC connected.

Irms looks much better, presumably the connected empty CT is closer to zero than the absent CT’s because the unused inputs are only grounded via the 33R burdens.

What is the 2.97 Vrms value though?

I’d almost expect it to be the other way round, due to pick-up by the c.t itself and on the input cables. The c.t. at around 100 Ω plus some inductance will only pull the parallel impedance down to about 25 Ω, so it should improve the low frequency noise a little. But the series inductance of the secondary will reduce the effect at higher frequencies.

I think you might have missed some of the patch? If you scroll down in the patch window you’ll see a change down below as well. If I’m reading your diffs correctly, I think you’re now dividing by count twice?

It just looked better to me, I have no idea if it’s right, I’ve not even started looking at the code itself, I’ve only just got the environment stuff sorted (less PIO which I’m not fussed about) and now just started looking at the possible tandem PLL sampling theory.

My bad, I’m on it now!

Thanks, I’ll hold off making the v6 tarfile until you give it the thumbs up. Once my shield arrives, I should be able to do local testing as well.


CPU temp: 30C, Vdda: 3304mV
0: Vrms: 1140.34, Irms: 6.93, Papp: 7901.74, Preal: 241.39, PF: 0.031
1: Vrms: 1140.34, Irms: 87.93, Papp: 100267.67, Preal: 3075.66, PF: 0.031
2: Vrms: 1140.34, Irms: 87.93, Papp: 100267.67, Preal: 3075.61, PF: 0.031
3: Vrms: 1140.30, Irms: 87.93, Papp: 100263.55, Preal: 1203.43, PF: 0.012
CPU temp: 30C, Vdda: 3302mV
2: Vrms: 1140.69, Irms: 87.92, Papp: 100294.92, Preal: 2824.84, PF: 0.028
3: Vrms: 1140.68, Irms: 87.93, Papp: 100297.37, Preal: 2987.30, PF: 0.030
0: Vrms: 1140.69, Irms: 7.10, Papp: 8093.51, Preal: 227.87, PF: 0.028
1: Vrms: 1140.69, Irms: 87.92, Papp: 100294.92, Preal: 2824.81, PF: 0.028
CPU temp: 30C, Vdda: 3302mV
0: Vrms: 1139.44, Irms: 6.96, Papp: 7935.04, Preal: 199.46, PF: 0.025
1: Vrms: 1139.44, Irms: 87.93, Papp: 100187.74, Preal: 1439.45, PF: 0.014
2: Vrms: 1139.44, Irms: 87.92, Papp: 100184.50, Preal: 1439.48, PF: 0.014
3: Vrms: 1139.42, Irms: 87.93, Papp: 100186.66, Preal: 1605.12, PF: 0.016
CPU temp: 30C, Vdda: 3304mV
0: Vrms: 1139.08, Irms: 6.83, Papp: 7778.77, Preal: 191.96, PF: 0.025
1: Vrms: 1139.08, Irms: 87.92, Papp: 100153.16, Preal: 1202.67, PF: 0.012
2: Vrms: 1139.08, Irms: 87.92, Papp: 100153.16, Preal: 1202.67, PF: 0.012
3: Vrms: 1139.07, Irms: 87.92, Papp: 100152.16, Preal: 1353.30, PF: 0.014
CPU temp: 30C, Vdda: 3302mV
0: Vrms: 1139.32, Irms: 7.33, Papp: 8356.42, Preal: 208.91, PF: 0.025
1: Vrms: 1139.32, Irms: 87.92, Papp: 100174.58, Preal: 1674.92, PF: 0.017
2: Vrms: 1139.32, Irms: 87.92, Papp: 100174.58, Preal: 1674.92, PF: 0.017
3: Vrms: 1139.31, Irms: 87.93, Papp: 100176.61, Preal: 1833.66, PF: 0.018
CPU temp: 30C, Vdda: 3304mV
0: Vrms: 1139.57, Irms: 7.47, Papp: 8515.12, Preal: 246.38, PF: 0.029
1: Vrms: 1139.57, Irms: 87.93, Papp: 100199.66, Preal: 2588.98, PF: 0.026
2: Vrms: 1139.57, Irms: 87.92, Papp: 100196.41, Preal: 2589.04, PF: 0.026
3: Vrms: 1139.56, Irms: 87.93, Papp: 100198.80, Preal: 2775.41, PF: 0.028

there is now a 0.01 fluctuation in the grounded ct values which is more realistic.

Thanks, those numbers are roughly what I see. I’ve grounded all my inputs via a 780R and I get:

CPU temp: 38C, Vdda: 3304mV                                                                                  
0: Vrms: 84.77, Irms: 86.05, Papp: 7294.06, Preal: 7284.25, PF: 0.999                                        
1: Vrms: 84.77, Irms: 101.44, Papp: 8599.33, Preal: 8728.25, PF: 1.015                                       
2: Vrms: 84.77, Irms: 85.83, Papp: 7275.81, Preal: 7244.25, PF: 0.996                                        
3: Vrms: 82.10, Irms: 81.46, Papp: 6688.04, Preal: 6602.75, PF: 0.987  

Those mid-80s represent about 68mV of noise at the pin and the scope sees that and then some (Green trace):

I also dumped out some of the raw ADC values on those pins and they’re not all 0 so for now I’ll just assume it’s noise. I’ll do some more tests once my shield arrives. Thanks again for the assistance.

New tar file to fix the RMS maths bug discussed in the last few posts:
txshield_demo_6.tar.gz (883.3 KB)

Just tried it (v5r3) again with the 1 CT attached to a small 900w(ish) kettle.

CPU temp: 30C, Vdda: 3302mV
0: Vrms: 1137.42, Irms: 75.08, Papp: 85395.60, Preal: -84809.77, PF: -0.993
1: Vrms: 1137.42, Irms: 87.93, Papp: 100010.84, Preal: 2102.52, PF: 0.021
2: Vrms: 1137.42, Irms: 87.93, Papp: 100010.84, Preal: 2102.52, PF: 0.021
3: Vrms: 1137.42, Irms: 87.93, Papp: 100010.33, Preal: 2303.70, PF: 0.023
CPU temp: 30C, Vdda: 3306mV
2: Vrms: 1138.95, Irms: 87.93, Papp: 100144.80, Preal: 1130.48, PF: 0.011
3: Vrms: 1138.94, Irms: 87.93, Papp: 100144.45, Preal: 1299.57, PF: 0.013
0: Vrms: 1138.95, Irms: 75.09, Papp: 85525.23, Preal: -84989.55, PF: -0.994
1: Vrms: 1138.95, Irms: 87.93, Papp: 100144.80, Preal: 1130.48, PF: 0.011
CPU temp: 30C, Vdda: 3302mV
3: Vrms: 1142.20, Irms: 87.93, Papp: 100431.00, Preal: 2736.95, PF: 0.027
0: Vrms: 1142.21, Irms: 75.31, Papp: 86015.60, Preal: -85435.15, PF: -0.993
1: Vrms: 1142.21, Irms: 87.93, Papp: 100431.71, Preal: 2527.40, PF: 0.025
2: Vrms: 1142.21, Irms: 87.93, Papp: 100431.71, Preal: 2527.38, PF: 0.025
CPU temp: 30C, Vdda: 3304mV
3: Vrms: 1142.40, Irms: 87.93, Papp: 100448.07, Preal: 1855.66, PF: 0.018
0: Vrms: 1142.41, Irms: 75.78, Papp: 86570.04, Preal: -85453.34, PF: -0.987
1: Vrms: 1142.41, Irms: 87.93, Papp: 100449.20, Preal: 1684.68, PF: 0.017
2: Vrms: 1142.41, Irms: 87.93, Papp: 100449.20, Preal: 1684.68, PF: 0.017

Not sure what the 75.xx values relate to exactly, ct1 input voltage RMS perhaps? (I’m fairly sure it’s not Amperes because my kettle lead didn’t melt :smile:)

It was a purely resistive load so I assume the small error on PF to be down to the difference in phase error between the CT and VT?

I also tried switching the orientation of the CT on the wire, the results were pretty much the same but with an inverted power value as expected.

CPU temp: 30C, Vdda: 3302mV
0: Vrms: 1139.33, Irms: 75.50, Papp: 86024.19, Preal: 85118.44, PF: 0.989
1: Vrms: 1139.33, Irms: 87.93, Papp: 100178.91, Preal: 1487.95, PF: 0.015
2: Vrms: 1139.33, Irms: 87.93, Papp: 100178.91, Preal: 1487.95, PF: 0.015
3: Vrms: 1139.31, Irms: 87.93, Papp: 100177.07, Preal: 1684.30, PF: 0.017
CPU temp: 30C, Vdda: 3304mV
0: Vrms: 1138.51, Irms: 74.95, Papp: 85336.25, Preal: 84940.29, PF: 0.995
1: Vrms: 1138.51, Irms: 87.93, Papp: 100106.68, Preal: 2675.94, PF: 0.027
2: Vrms: 1138.51, Irms: 87.93, Papp: 100106.68, Preal: 2675.94, PF: 0.027
3: Vrms: 1138.49, Irms: 87.93, Papp: 100104.48, Preal: 2896.34, PF: 0.029
CPU temp: 30C, Vdda: 3304mV
1: Vrms: 1138.36, Irms: 87.93, Papp: 100092.98, Preal: 2016.21, PF: 0.020
2: Vrms: 1138.36, Irms: 87.93, Papp: 100092.98, Preal: 2016.21, PF: 0.020
3: Vrms: 1138.35, Irms: 87.93, Papp: 100092.12, Preal: 2240.19, PF: 0.022
0: Vrms: 1138.36, Irms: 74.97, Papp: 85346.75, Preal: 84903.35, PF: 0.995