Skip to content

Phase Correction Theory

David00 edited this page Feb 3, 2021 · 10 revisions

Phase Correction Theory

Oh great, it's theory time! If the title hasn't scared you away, you might actually find this section quite helpful! Towards the end of the Hardware 1 page, I said that you'll need a purely resistive load. What the heck is a purely resistive load?

Simply put, it's a device that consumes all of the energy that goes to it. It has no motors and no capacitors. Resistors dissipate energy in the form of heat, so a purely resistive load is one that puts out heat. But wait! Not all devices that put out heat are purely resistive. Electric heaters often have motors (fans), and other devices that get hot might have some sort of digital temperature selection.

When it comes time to correct for phase error (on the next page), you'll need to have a device that puts out a lot of heat and does so very, very steadily. I highly recommend you acquire a halogen work lamp. The higher power consumption it has, the better. I personally used this one from Home Depot.

Phase (Explained)

Consider the following diagrams of resistive, inductive, and capacitive loads:

These hypothetical plots show how the voltage and current wave-forms of the three different types of loads relate to each other. You can see that for a resistive load, the voltage and current waves line up on top of each other perfectly. Their amplitude may not match, but their peaks, troughs, and zeroes all happen at the same time. These waves are said to be in phase with each other. In the inductive and capacitive loads, there is some difference between the voltage and current wave forms. This difference means that these two loads are out of phase. The amount that the current and voltage wave forms are out of phase is called Phi (ฮฆ), and it's measured in degrees. Since power is equal to Voltage x Current, any difference in phase when there isn't supposed to be one will introduce a measurement error in the calculations. Remember: a resistive load has a power factor equal to 1.0.

Consider the instantaneous power at any given moment in time. Instantaneous power is the instantaneous current * the instantaneous voltage, as shown below:

If our measured current wave is slightly out of phase when compared to the voltage wave, our power calculation will not be accurate. Please note that I am talking specifically about resistive loads and not capacitive or inductive loads. Capacitive and Inductive loads will always have a phase difference between the voltage and current waves. However, with our purely resistive load, we can assume that the voltage and current wave form are in fact in phase with each other.

Where Does Phase Error Come From?

Now that we've reviewed the characteristics of a purely resistive load... imagine that you are the Raspberry Pi. Here are the instructions that you send to the analog to digital converter (ADC):

  1. Change ADC channel to the A/C voltage channel
  2. Read a single instantaneous voltage value
  3. Change ADC channel to the CT0 input channel
  4. Read CT0's instantaneous current value
  5. Change ADC channel to the CT1 input channel
  6. Read CT1's instantaneous current value
  7. Change ADC channel to the CT2 input channel
  8. Read CT2's instantaneous current value
  9. Etc... all the way through CT5.

Sending these instructions takes TIME. A very, very, very small amount of time, but one that is measurable and calculable nonetheless. In fact, I have calculated that on my Raspberry Pi 3B+, it takes about 32ยตs to switch ADC channels and read the value. The difference in time between reading the voltage and current inputs is our biggest source of phase error.

It follows that our largest phase error will come from the measurement that takes the longest amount of time between current and voltage readings. We can reduce the error as much as possible by simply reducing the amount of time between current and voltage readings - not by speeding the processor up, but by changing the order in which current and voltage are sampled. Instead of reading the voltage first, then all the current sensors, I sample the voltage wave in the middle of all the current samples. Here (lines 37 through 43) is the part of the code that specifies the order in which samples are read.

From the code linked above, you can see that the order of sampling is ct0, ct4, ct1, VOLTAGE, ct2, ct3, ct5. Therefore, ct0 and ct5 will have the largest amount of phase error since they are the furthest away in time from the voltage sample, whereas ct1 and ct2 will have the smallest amount of phase error).

Here is exactly what it looks like using real data from my board. First, CT5, with the largest phase error. Remember, these samples are from a purely resistive load, so they should line up with each other if everything was perfect:

And here is CT2 with the smallest phase error:

See how much closer the CT2 wave is to the voltage wave when compared to the CT5 wave in the first chart?

How Do We Correct Phase Error?

For each individual set of CT data, the voltage wave needs to be shifted by a fixed amount. In the first chart showing the real data from CT5, it appears that the voltage wave needs to be shifted to the left to put it in phase with the voltage wave. Similarly, looking at the plot for CT2, it also needs to be shifted to the left, but not as much. This means that we have to shift the single voltage wave differently for each CT data set. We can't actually shift the wave left or right, but we CAN change the amplitude at each specific point which will have the same effect as shifting the wave left or right. Also, we can't adjust the current wave because devices with inductors and capacitors use current in odd, unpredictable ways. The only consistently steady wave is the voltage wave, so this is what we can reliably adjust to correct for phase errors.

Note: The discussion so far has been only on the phase error introduced from the time delay between samples. The transformers themselves actually have their own native phase error and ratio error. We don't need to be concerned with either of these errors in this project.

This means that while one voltage sample wave is taken, 6 copies are made from the source wave, then each one is adjusted in a unique way to correct for the phase error. The unique voltage wave is then paired with the corresponding CT wave for the power calculations.

Using the 6 corrected voltage waves, the software can then calculate the power factor for each set of measurements per CT. Since you will have measured a purely resistive load, the power factor is supposed to be 1.0. If the software calculates something other than 1.0, then we can adjust the phase correction variable for each CT to help bring the P.F. closer and closer to 1.0.

See the next page for the phase correction procedure.

Clone this wiki locally