Power measurement with SCT-013

1,648 views
Skip to first unread message

FransOv

unread,
May 16, 2021, 10:28:52 AM5/16/21
to TasmotaUsers
Over the past few months, I've tested mains power measurement with the SCT-013 current transformers in Tasmota. The tests have been hampered by the inaccuracy of the esp8266 and esp32 ADC inaccuracies. I used the esp32 as I needed two adc's. 

I would like to share the results of these experiments and if you can agree with my findings, I could perhaps submit a request to implement the changes I made.

I've tried simple circuits like this:
R952070991ac4508cb7f5af3c1b961498.jpg
and circuits with true RMS LTC1966 based modules like this one:
Picture1.jpg
In both cases the results were far from satisfactory, especially at low power levels. Even giving the output of the LTC1966 module a voltage offset with an opamp did not help much. The result was a significant signal at zero input and strongly fluctuating output at all input levels.
As adding hardware did not noticeably improve the situation, probably even introducing extra noise, I returned to the simple schema with only the voltage divider and the capacitor and the ADC__CT_POWER module of Tasmota.

The Tasmota xsns_02_analog.ino module reads the power level every second by reading the analog value 32 times with a 1 ms interval and measuring the peak-to-peak voltage by subtracting the minimal value obtained from the maximum value. From this peak to peak value the current is calculated by means of the parameters given in AdcParamx.

I made some changes to the xsns_02_analog module to improve stability and accuracy:
  1. I changed the interval from 1 to 2 ms, thus extending the 32 measurements over three cycles instead of one and a half cycle (one cycle of the 50Hz net frequency is 20 ms).
  2. In an ideal world, the average of the max and min value measured should always be the same, at the level of the virtual ground of the voltage divider. The difference between this average value and the nominal value can therefore be considered as a quality measure and measurements with a big difference should be discarded. However, the nominal value also fluctuates. Assuming that most measurements will be somewhat correct, and assuming otherwise would make this whole exercise without sense, I made the nominal value a weighted average of past values, starting at one half of the ANALOG_RANGE value. As this  virtual ground level  can vary per ADC depending on the circuit that is attached to the ADC, I extended the ADC structure with a virtual_ground variable. I reject measurements that differ from the nominal in virtual ground level by 0.5% of ANALOG_RANGE. 
  3. If you measure the peak to peak value by recording the maximum and the minimum of 32 measurements, you are going to err on the plus side. A minimal value that is to low or a maximal value that is to high is going to have an effect, the inverse will not. Therefore I subtract one percent of  ANALOG_RANGE   from the peak to peak value before using it tot calculate the current.
Using these changes and an ADCParam value of AdcParam1 7,0,1000,0.23. I get fairly consistent results. It took a lot of time, including waiting for the LTC1966 modules to arrive from China, learning how to make a voltage adder with an opamp, soldering 4 variants of the boards and checking those boards for shortcuts and bad joins. 

There probably is a good hardware solution to this problem, using a better quality external adc instead of the esp's adc, but I'm more at ease with my programming pencil then with the soldering gun. Programming pencil because when I started with computers, we had to write our programs with a pencil on 80 column sheets of paper that were then transcribed to a bunch of punched cards that you read into a computer. Mostly at night because the computer was used for production purposes in the daytime. I'm that old.

Philip Knowles

unread,
May 16, 2021, 12:45:33 PM5/16/21
to FransOv, TasmotaUsers

The problem with all of these is that you are trying to hit a ‘moving target’. Even with a 1ms sample time you are only measuring at 20 points in a cycle and, by definition, each sample is going to different and you can’t guarantee that you will hit the same points in the cycle every time – if you miss the peak your results will go haywire.

Full wave rectification of the output with a smoothing capacitor would be best because you would be measuring a true DC signal (but impossible due to the voltage drop over the rectifier) so the LTC1966 should give you the best results – adding the op-amp would just give further inaccuracy.

Your issues are why I ended up using the PZEM-004 which, over 2 years, has resulted in a 13kWh reading error between it and my electricity meter over just under 6000kWh.

 

Regards

 

Phil K

 

Sent from Mail for Windows 10

 

From: FransOv
Sent: 16 May 2021 15:28
To: TasmotaUsers
Subject: Power measurement with SCT-013

 

Over the past few months, I've tested mains power measurement with the SCT-013 current transformers in Tasmota. The tests have been hampered by the inaccuracy of the esp8266 and esp32 ADC inaccuracies. I used the esp32 as I needed two adc's. 

 

I would like to share the results of these experiments and if you can agree with my findings, I could perhaps submit a request to implement the changes I made.

 

I've tried simple circuits like this:

and circuits with true RMS LTC1966 based modules like this one:

In both cases the results were far from satisfactory, especially at low power levels. Even giving the output of the LTC1966 module a voltage offset with an opamp did not help much. The result was a significant signal at zero input and strongly fluctuating output at all input levels.

As adding hardware did not noticeably improve the situation, probably even introducing extra noise, I returned to the simple schema with only the voltage divider and the capacitor and the ADC__CT_POWER module of Tasmota.

 

The Tasmota xsns_02_analog.ino module reads the power level every second by reading the analog value 32 times with a 1 ms interval and measuring the peak-to-peak voltage by subtracting the minimal value obtained from the maximum value. From this peak to peak value the current is calculated by means of the parameters given in AdcParamx.

 

I made some changes to the xsns_02_analog module to improve stability and accuracy:

  1. I changed the interval from 1 to 2 ms, thus extending the 32 measurements over three cycles instead of one and a half cycle (one cycle of the 50Hz net frequency is 20 ms).
  2. In an ideal world, the average of the max and min value measured should always be the same, at the level of the virtual ground of the voltage divider. The difference between this average value and the nominal value can therefore be considered as a quality measure and measurements with a big difference should be discarded. However, the nominal value also fluctuates. Assuming that most measurements will be somewhat correct, and assuming otherwise would make this whole exercise without sense, I made the nominal value a weighted average of past values, starting at one half of the ANALOG_RANGE value. As this  virtual ground level  can vary per ADC depending on the circuit that is attached to the ADC, I extended the ADC structure with a virtual_ground variable. I reject measurements that differ from the nominal in virtual ground level by 0.5% of ANALOG_RANGE. 
  3. If you measure the peak to peak value by recording the maximum and the minimum of 32 measurements, you are going to err on the plus side. A minimal value that is to low or a maximal value that is to high is going to have an effect, the inverse will not. Therefore I subtract one percent of  ANALOG_RANGE   from the peak to peak value before using it tot calculate the current.

Using these changes and an ADCParam value of AdcParam1 7,0,1000,0.23. I get fairly consistent results. It took a lot of time, including waiting for the LTC1966 modules to arrive from China, learning how to make a voltage adder with an opamp, soldering 4 variants of the boards and checking those boards for shortcuts and bad joins. 

 

There probably is a good hardware solution to this problem, using a better quality external adc instead of the esp's adc, but I'm more at ease with my programming pencil then with the soldering gun. Programming pencil because when I started with computers, we had to write our programs with a pencil on 80 column sheets of paper that were then transcribed to a bunch of punched cards that you read into a computer. Mostly at night because the computer was used for production purposes in the daytime. I'm that old.

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/cb05ed05-7977-46aa-ae3f-90b2e483b7f0n%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages