This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Frequency Measurement with C

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

Parents
  • 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.

Reply
  • 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.

Children
No data