Hello,
I'm currently working a energy measurement/calculator type system. Basically, I need to measure and display voltage, current, power factor, and frequency to an LCD screen.
I am able to measure and display voltage and current readings, simply by using voltage dividers and current sensing resistors.
My next task is to obtain a frequency. My input voltage would be around 110-130V. I am having trouble grasping on how to program this in with C.
Here's what I know (from research): 1. Need to use a comparator. 2. Need to set up a timer and ISR 3. Need to to find zero crossing (how?)
I was looking into a A-F, like the LM331 to convert my voltage to a frequency, so I can have single logic level pulse stream. I've never used one of these badboys or even how to code this in.
Any direction would be greatly appreciated.
Thanks, Leon
What frequency to measure?
If you are doing the voltage measurements with a high enough sampling rate, then you can figure out the frequency from the voltage readongs, instead of hunting zero-crossings. Since you are going to compute a power factor, that implies that your sampling rate must already be high in relation to the expected base frequency, to allow correct measurements even at very high crest factors.
Another thing to think about if you use the comparator is the amount of noise - with too much noise, you may get multiple zero-crossings from a high-frequency signal being overlayed with the base frequency.
Thanks for the reply. I will be measure frequency of the line voltage. The comparator was an idea that came up from reading a couple books.
If there is a better/easier way to measure frequency, that would be great!
I am getting 120V and 3A. I am expecting approx. 60Hz as my frequency, but I'm not sure how to obtain this.
How would I measure it off of the voltage readings?
Thanks
When you measure the frequency, you do it by counting a number of zero crossings and measuring the time between them.
You may look at a hw comparator for the zero crossings.
But you may just as well compare the ADC readings of the voltage. Remeber that the ADC will measure an almost perfect sinusoidal signal unless you have used a bridge rectifier before the ADC. It is quite easy to process these ADC samples and detect the ingreasing or decreasing stages of the voltage. It isn't even required to specifically go for the zero-crossing. All you need is to try to detect everytime the voltage increases or everytime the voltage decreases a number of samples in a row (to filter away noise) and then count either half-waves or full waves and keep track fof the time.
But remember that if you are expected to read 3A RMS, then you must have an ADC that can read a lot stronger current than 3A, since some loads may produce crest factors of more than 10, i.e. the peak current may be more than ten times the RMS current. The power company does not like this, but a transformer with a rectifier bridge and a large capacitor and a resistive load will produce a very ugly current curve - try with an oscilloscope and you will be surprised.
At the same time, your current measurements must have a good resolution, so you can measure even small loads with a reasonable quality.
And if the base frequency is 60Hz, then you must sample the data (current and voltage) at many times this frequency, since the current curve may have very high-frequency components. Assume at least 4kHz frequency components with significant energy, so you should probably have at least 10kHz to 20kHz sampling rate.