Home / Home made Projects / Microcontroller Projects / Digital Frequency meter for sine waves

Digital Frequency meter for sine waves

This article describes the design and construction of microcontroller based digital frequency meter. The circuit is specially designed for sine waves. The auxiliary components for the conversion of sine waves to square, connection diagram and program are presented. The assembly is tested in ISIS Proteus and results are displayed.

Introduction

Frequency is an important terminology in various Engineering fields however it is of great significance in Electrical Electronics and associated fields. It can be defined as

In general terms

Frequency is the number of waves passing through a fixed point in 1 second

In electrical terms

It is the number of cycles of alternating current in one second

The standard frequency of Electrical power (Alternating) around the globe is 50Hz or 60Hz. To power electrical devices, it is very important to maintain the frequency with in specified limits. Due to its importance, it is continuously monitored. Frequency meter is therefore an important member of electrical meters family.

Microcontroller is one of the widely used controllers in various projects. It is an intelligent controller used to accomplish automation tasks. The purpose of this article is to use microcontroller to measure frequency of sine waves.

Block Diagram

Following figures shows the block diagram of the digital frequency meter using microcontroller. The important blocks are active filter, zero crossing detector, microcontroller and LCD for Display. The description and purpose of each block is given in the following sections.

 block diagram showing digital frequency meter

Active filter

Since waves contain noise which usually results in incorrect measurement of frequency. Therefore it was very important to filter the harmonics form the voltage and current signal before measurement. For this purpose, an active filter is designed using operation amplifier which eliminates the noise from the input signal before it is measured.

The details of active filters can be studied in active low pass filter

Zero crossing detectors.

Microcontroller can measure the frequency of square waves more accurately than pure sine waves because of its sharp edges. Therefore sine wave after filtration is converted into square waves using zero crossing detectors. Zero crossing detectors are analogue comparators. which can be implemented using operational amplifiers. Zero crossing detectors compare input voltage with the reference voltage The reference voltage is 0 volts in given project so when the input voltage is greater than 0V, output is +5 and when input is less than 0V output is -15V. So in this way input sine wave is converted into square wave.

To have complete understanding of zero crossing detectors please click op-amp zero crossing detector

Schematic Diagram of digital frequency meter

The components required for digital frequency meter

  • Capacitors (2.5uF, 1.25 uF)
  • Resistors (1k, 2K) etc.
  • Op-Amps (741)
  • Microcontroller 16F877
  • LCD (16×2)

The above items are connected as shown in the figure.

Schematic of digital frequency meter

It can be seen from the above figure that signal is first filtered by active filter to remove any noise from the signal.  The Low pass filters are implemented using 741 op amp. The cut off frequency is 100 Hz which can be set by selecting appropriate values of the resistors and capacitors.

 …….. (i)

Where R, R2, C1 and C2 are capacitors in the low pass filter.

It is followed by zero crossing detectors using the ideal op-amp model in ISIS (real 741 should be used in hardware). It converts the sine wave into square wave by using zero crossing points.

After achieving square wave from sine wave, it is fed into CCP pin of microcontroller to measure frequency. The measured frequency is displayed on the LCD screen.

Results.

The digital frequency meter for sine waves is tested in ISIS Proteus environment. Signal of various frequencies is applied to the digital frequency meter and the result is observed on the LCD screen.

For 50Hz input signal, the output of the microcontroller is

Freq meter simulation result 1

The frequency measured by digital frequency meter is 49Hz which is an acceptable value.

Now for 70Hz input signal, let’s observe the results.

freq meter simulation result 2

The value shown by LCD is 71 Hz which is very much near to 70Hz.

Code

The code of digital frequency meter is written in C languge and complied in MIKRO C Compiler.

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
   unsigned int freq_result;
    char txt[5];
void main() {
  ANSEL = 0x00; // Configure AN pins as digital I/O
  ANSELH = 0x00;
  C1ON_bit = 0; // Disable comparators
  C2ON_bit = 0;
  PORTB = 0; // Initialise PORTB
  TRISB = 0; // PORTB is output
  //T1CON = 3; // Timer1 on, external input RC0
  //TMR1IF_bit = 0; // clear TMR1IF
  TMR1H = 0x00; // Initialize Timer1 register
  TMR1L = 0x00; // Initialize Timer1 register
  //TMR1IE_bit = 1; // enable Timer1 interrupt
  TRISC = 0xff; // all input
 // cnt =   0;  // initialize cnt
 // INTCON = 0xC0; // Set GIE, PEIE
  Lcd_Init(); // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR); // CLEAR display
  Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
  do {
    TMR1H = 0; // reset high byte of timer 1 (takes effect when low byte written)
    TMR1L = 0; // reset low byte of timer 1 (also loads in high byte now)
      T1CON= 0B00000011;
      Delay_ms(1000);
     T1CON= 0B00000010;
    freq_result = TMR1L; // get low byte of timer 1 count (and read high byte to buffer)
    freq_result += TMR1H*256-12; // add in the high byte from buffer
     IntToStr(freq_result,txt);
      Lcd_Cmd(_LCD_CLEAR);
      Delay_ms(200);
      Lcd_Out(1,1,”FREQUENCY IS”);
      Delay_ms(200);
      Lcd_Out(2,0,txt);
      Delay_ms(200);
      Lcd_Out(2,7,”Hz”);
// show the result on LCD
  }while(1);  // Infinite loop
}

Along with microcontroller, we have also explained how to measure frequency using Arduino controller.

If you have any question regarding digital frequency meter please ask in comments.

About Syed Noman ud din

Syed Noman ud din is an Electrical Engineer and working in Industry from last 3 years. He writes technical articles for electrical and electronic engineers. He has also published several research publications in renowned international journals.

Check Also

Power Factor measurement using Microcontroller

The article will help the readers to use microcontroller for power factor measurement using a …

Leave a Reply

Your email address will not be published. Required fields are marked *

*