Here is a sketch that will enable a precise measurement of the difference in phase errors of the a.c. adapter and current transformer. This is the value for phaseCal that is used by emonLibCM to compensate for the combined effect of the phase errors of the two transformers.
It works in a completely different way to the standard sketch, so unfortunately there is no realistic possibility of combining the two sketches, not least because of memory constraints.
Using the sketch
You must be prepared to compile and upload this sketch (ideally using the Arduino IDE – I cannot support platformio) to test and record the values that the “working” sketch needs, and afterwards to download from Github the “default” or working sketch that was in your emonTx when you received it, compile and upload that and then calibrate it using the values you have measured.
The zip file contains the sketch and documentation. Unzip the contents into your Arduino sketchbook directory, then configure the sketch according to the documentation.
The User Documentation PDF file can be moved or copied to a convenient location of your choosing.
I had a quick go - it was really straightforward. If you recall, I’ve got an arduino / raspberry pi 3 setup running emonLibCM / emonCMS (emonSD build). When I installed emonCMS, I also also installed the arduino IDE on to the PI so that I could remote on to the arduino to tinker so it was really staightforward.
Without any additional voltage / current calibration steps (I was a little short on time), I used your sketch to determine that my phase calibration was closer to 2 than the 4.2 it had been set at.
I’ve left it running a week with the modified phase calibration and the percentage difference between the calculated Wh and the pulse count is less than 0.3% at present. I’m off this week so will tinker a little more and perform a full calibration using this sketch.
That doesn’t surprise me. The phase error values aren’t specified in any data sheets, and they change - over time with different batches of materials, manufacturing changes, and in response to the actual current or voltage they are working at. So any preset value isn’t guaranteed to be accurate for the previous or the next batch, even when measured at the same voltage/current.
And of course, the value you measured is the difference between the v.t. and the c.t., so it’s influenced by both.