How Can I Calculate Voltage Sag and THD with an AVR Microcontroller?

  • Thread starter Thread starter Pagedown
  • Start date Start date
  • Tags Tags
    Voltage
AI Thread Summary
To calculate voltage sag and Total Harmonic Distortion (THD) using an ATMEL AVR microcontroller, it's essential to sample voltage and current at a rate significantly higher than once per second, ideally at least 16 times per 60Hz cycle. Safety precautions must be taken when interfacing with AC mains, such as using optocouplers for isolation. For THD calculations, the microcontroller will need to process samples against a pure sine wave reference, which may require additional hardware support or DSP techniques. While an 8-bit microcontroller can handle basic calculations, more complex measurements may necessitate specialized metrology chips. The project allows for flexibility in specifications, but accurate voltage sag and THD measurements will require careful design and sampling strategies.
Pagedown
Messages
92
Reaction score
0
Hi everyone, thanks for your viewing my thread.

I am doing a project to monitor a single phase(240V) power using a ATMEL AVR microcontroller, and I face some difficulties :-

1. How do I calculate the voltage transients : voltage sag/swell? What is the analysis method?

2. How do I calculate the Total Harmonic Distortion (THD) ?

what are the equations if I have the microcontroller senses the data of voltage and current every second and display useful information?
 
Engineering news on Phys.org
Pagedown said:
Hi everyone, thanks for your viewing my thread.

I am doing a project to monitor a single phase(240V) power using a ATMEL AVR microcontroller, and I face some difficulties :-

1. How do I calculate the voltage transients : voltage sag/swell? What is the analysis method?

2. How do I calculate the Total Harmonic Distortion (THD) ?

what are the equations if I have the microcontroller senses the data of voltage and current every second and display useful information?

You're going to need to sample a lot faster than once a second, I would think. What sensors are you using? What are your ADC channels? Can you pull in ADC samples quickly in an ISR and do the calculations as time allows?
 
I am not really good about microcontrollers.But I will learn through it. A simple voltage divider for voltage sensing and still deciding -current sense resistor/current transformer for the current sensing.

Is it possible I can sample at 60Hz? Will it be tough?

Basic question first:
If I can have samples of data of voltage and current amplitudes, what are the equations that or analysis method to calculate the voltage sag& THD?
 
Pagedown said:
I am not really good about microcontrollers.But I will learn through it. A simple voltage divider for voltage sensing and still deciding -current sense resistor/current transformer for the current sensing.

Is it possible I can sample at 60Hz? Will it be tough?

Basic question first:
If I can have samples of data of voltage and current amplitudes, what are the equations that or analysis method to calculate the voltage sag& THD?

Since you are sensing the AC Mains, you need to think about safety in your design. You can't just be sampling the AC Mains directly and make connection to your AVR circuit, if the AVR circuit is human-accessible (can be touched). That would be a bad shock hazard.

Instead, you would usually use some sort of isolation technique to get the sampled data (or the analog waveforms, but more usually the digitized data) into the AVR. You can use optocouplers to safely couple the digital control and data signals across a barrier, for example. The sensing and ADC circuitrty would be on the AC Mains side, and the AVR would be on the SELV (Safety Extra Low Voltage) side of the optocoupler boundary.

There are current sense transformers (CTs) that can be used to sense the series current. These are inherently isolated, so you would not need to isolate the sensing and digitizing circuit for the current measurement, if you use a CT.

Beyond the safety aspects, it sounds like you need to be sampling many times per 60Hz cycle. Especially if you want to be able to calculate THD. What kind of specification do you have for your measurements of "voltage transients"?
 
Yup, I forgot to mention I will be using optocoupler in between the sensing circuitry and the AVR. I'm using the ADC of AVR, and I dun't know whether it is possible.

It doesn't need to be a high-tech measurement, but just a basic approximation of voltage sag and THD. That's why I really don't know where to calculate this and present it in a useful form.Maybe in percentage?
 
Pagedown said:
Yup, I forgot to mention I will be using optocoupler in between the sensing circuitry and the AVR. I'm using the ADC of AVR, and I dun't know whether it is possible.

It doesn't need to be a high-tech measurement, but just a basic approximation of voltage sag and THD. That's why I really don't know where to calculate this and present it in a useful form.Maybe in percentage?

It's easier to pass digital data across the opto boundary, rather than try to send analog information across the boundary for digitizing after.

For the THD, you will need to do the signal processing of the samples to compare them to a pure sine wave (of the same phase):

http://en.wikipedia.org/wiki/Total_harmonic_distortion

.
 
So should I built another ADC circuitry for both sensing?

Okay, can the 8bit-microcontroller handle all this calculations?

How about the voltage sag?
 
Pagedown said:
Okay, can the 8bit-microcontroller handle all this calculations?

That depends on the specifications for accuracy, etc. What exactly are the specs for this project? And have you been given some safety guidance by the instructor? I hope s/he didn't just say, "Go measure the AC Mains", and turn you loose!
 
he just asked me to include THD and voltage sag in my measurements.

It is a power monitor & control using a microcontroller to measure voltage and current, power consumption, power factor etc..

He did not give me exact specs, thus it means I can make my own specs. But, I still can't as I'm struggling to calculate both of this, even by using hand.
 
  • #10
Pagedown said:
he just asked me to include THD and voltage sag in my measurements.

It is a power monitor & control using a microcontroller to measure voltage and current, power consumption, power factor etc..

He did not give me exact specs, thus it means I can make my own specs. But, I still can't as I'm struggling to calculate both of this, even by using hand.

Doing it with an 8-bit uC will be challenging. I wrote some DSP code on an 8051 one time a while back, to calculate EEG spectra in real-time. I don't recall the sample rate offhand, but you will be sampling much faster, at least 16x 60Hz, and preferably faster.

You can use some shortcuts to help out, like using table look-ups for some things instead of actually calculating them. Does your AVR at least have a hardware multiply?

You can use other tricks like including zero crossing circuitry on the V(t) and I(t) channels, instead of calculating the zero crossings from the full digitized waveforms. That will give you an approximate power factor, just from the zero crossings.

You can also look at "metrology" chips, which are made for measuring power in these kinds of circuits. They will give you some idea of what-all is involved in these measurements. Also, you can compare the accuracy available from the metrology chips (and interfacing them to the AVR uC with SPI or whatever), to the best that you can do with your uC by itself. The difference will be quite large.

If you could assume that the THD was low, then you could use peak sensed values for V(t) and I(t), along with the zero-crossing data, to estimate all of the numbers that you mentioned. But to measure / calculate THD, I think you will need the sample rate that I mentioned (16x or higher).

Maybe others know of some tricks for calculating THD without full sampling of the waveform?
 
Back
Top