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

  • Thread starter Thread starter Pagedown
  • Start date Start date
  • Tags Tags
    Voltage
Click For Summary

Discussion Overview

The discussion revolves around the challenges of calculating voltage sag/swell and Total Harmonic Distortion (THD) using an ATMEL AVR microcontroller in a project aimed at monitoring single-phase power (240V). Participants explore methods for data sampling, safety considerations, and the necessary equations for analysis.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested
  • Homework-related

Main Points Raised

  • Some participants suggest that sampling frequency needs to be higher than once per second to accurately capture voltage transients and THD.
  • There is a discussion about using a voltage divider and current sensing methods, including current sense resistors and current transformers.
  • Concerns are raised about safety when sampling AC mains, with recommendations for using isolation techniques such as optocouplers.
  • Participants mention the need for a basic approximation of voltage sag and THD, questioning the feasibility of calculations with an 8-bit microcontroller.
  • Some propose using digital data transmission across the optocoupler boundary rather than analog signals for safety and efficiency.
  • There are suggestions for utilizing signal processing techniques to compare sampled data to a pure sine wave for THD calculations.
  • A participant recalls previous experience with DSP code on an 8051 microcontroller, noting the importance of sampling rates and potential shortcuts for calculations.
  • Discussion includes the possibility of using metrology chips designed for power measurement to simplify the process.

Areas of Agreement / Disagreement

Participants express varying opinions on the feasibility of using an 8-bit microcontroller for the required calculations, and there is no consensus on the best approach to achieve accurate measurements of voltage sag and THD.

Contextual Notes

Participants highlight the lack of specific project specifications, which leads to uncertainty in determining the necessary sampling rates and calculation methods. Safety considerations regarding AC mains sampling are also emphasized.

Who May Find This Useful

This discussion may be useful for individuals working on power monitoring projects, particularly those involving microcontrollers, as well as those interested in understanding the complexities of measuring voltage transients and harmonic distortion.

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?
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
5K
Replies
38
Views
7K
  • · Replies 16 ·
Replies
16
Views
4K
Replies
2
Views
2K
Replies
18
Views
3K
Replies
7
Views
5K
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K