delayMicroseconds in power logger sketch

I've had another look at the delayMicroseconds line. The reason it is there is to slow down the sample rate so that 1000 samples cover 1s of time.The reason it effects the value for frequency when its decreased is down to noise in the voltage waveform.

If we have a look at the frequency calculation part:

The first line tries to find the point at which the voltage waveform crosses the zero line. The program calculates frequency by counting the time between each time the voltage crosses 0 (going from - to +) it then takes an average by repeating the step several times.

if (fpVLastValue < 0 && instV >= 0)
      {
         vPeriod = millis() - vLastZeroMsec;

         if (vPeriod > 0) {
            vPeriodSum += vPeriod;
            vPeriodCount++;
         }
         vLastZeroMsec = millis();
      }
      fpVLastValue = instV;

The main problem is that "if (fpVLastValue < 0 && instV >= 0) = true" does not always happen once a cycle. There is a certain amount of noise in the voltage waveform and if we look at the point at which the voltage crosses zero in detail we will see that it actually dips back down over the zero line and back up again. The program cant distinguish between these small oscillations and the mains ac frequency cycle and so the frequency will be larger than the correct frequency.

But the program only sees these small oscillations when it looks at the crossing point in detail, a delay value of around 669 microseconds will skip over these small oscillations and so the program will only register the larger mains frequency variations.

There are therefore three ways we can minimise the error caused by these small oscillations

1) Have a large amplitude voltage waveform. If you can use the power sampler program to take a picture of the voltage waveform that would help identify if the voltage waveform is too week or noisy. What value resistors are you using for the voltage divider?

2) Skip the small oscillations by having a sufficiently high delayMicroseconds. Although this will also lower the accuracy of the power measurements.

3) I could look in to a better method of measuring the frequency altogether that does not rely on such a good quality waveform.

Let me know if I can clarify any of the above.
Hope that helps

Trystan
 

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options