Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Frequency and RPM Counter

By Ashutosh Bhatt

Measuring frequency is one of the prime requirements for many applications. The most obvious method of measuring frequency is using CRO (or now a days using DSO). But this instrument is not handheld or available with all the students or hobbyists at any time. It is actually laboratory instrument and not the portable one. Also it is costlier. Also conventional CRO does not give the direct frequency value read out. One has to first set the waveform then find time/division and finely calculate time period and frequency. So it’s a long process that takes time. Another way is use frequency counter that will give us direct digital readout of frequency. In this no need of first adjusting the waveform into screen then find time / division and then calculate time period and frequency such as CRO. Just apply the signal input and get the read out of frequency. That’s why frequency counters finding their own place in measuring instruments.  

 
RPM counter also finds its importance in so many industries as it measures current RPM of any motor. Measuring current RPM of the motor and based on that take decision like to increase RPM or decrease it, is the prime requirement.  In certain application it is required to maintain the RPM of motor within desirable limits. So in that the RPM is continuously measured and taken as feedback. If this value deviates much out of the limits, immediate actions can be taken.
 
So here I am presenting a single circuit to measure frequency as well as RPM. This circuit can alternatively measures frequency or RPM using a switch. If switch is connected to
·         direct signal input –  it measures frequency
·         Sensor (opto-interrupt) output – it measures RPM.    
 
Also it measures either frequency or RPM only once or in continuous loop after every 5 second. Let us see some other features of this circuit
·         measures frequency from 50 Hz to 65 KHz
·         measures RPM from 5 to 9999
·         uses non contact type RPM sensor
·         digital output with text on 16×2 LCD
·         option for continuous measurement
 
Let us first see the block diagram of the system
 
System block-diagram: 
 
RPM Counter Block Diagram
 
The major building blocks are wave shaping circuit, sensor, micro controller and LCD
Wave shaping circuit: – It converts any input signal to pulses (unipolar square or rectangular) wave. Its output is between 0 to 5 V. So actually it converts the input signal shape into the type of shape that can be recognized by micro controller.
Opto interrupt sensor: – it converts each revolution of motor into a pulse. So we shall directly get the results as number of revolutions = number of pulses.
Micro controller: – it counts number of pulses (either from sensor or a direct signal) per fixed time (1 sec or 10 sec) and calculates frequency or RPM and displays them on LCD
LCD: – it is used to display text messages as well as the read outs of either frequency or RPM
Along with all these there are two SPDT switch inputs that selects frequency or RPM counter and decides to take single measurement or continuous in loop. One LED is also provided to indicate counting process is on.
 

Circuit Diagram & Connections

Now let us see the complete circuit.
Connections: –
·         As shown in figure from the two input connections of SPDT switch SW1 is the direct frequency input.
·         Another input of SW1 is connected with output of opto-interrupt sensor MOC7811. For more details or the connections of MOC7811 refer the datasheet of it.  
·         The output line of SW1 is connected to the base input of NPN transistor Q1 through current limiting resistor R1.
·         Q1 is configured in switch mode so its output is always 5V or 0V.
·         This output is connected to port 3 pins P3.3 and P3.4 that are INT0 pin and T0 pin
·         The data pins D0 – D7 (7 – 14) of LCD are connected with port P0
·         Two control pins Rs(4) and En (6) are connected with P2.7 and P2.6 respectively
·         Read/write pin (5) is permanently connected with ground
·         Pins 1 and 2 provides biasing voltage and pins 16 and 15 provides LED backlight
·         A 1K pot connected to pin 3 as shown to vary LCD brightness
·         One RED LED is connected on P2.5 as shown
·         SPDT switch SW2 connected to P2.0 in such a way that it can provide high and low logic input to the pin. Same for SW3 connected to P2.1
·         Capacitor C3 is connected between Vcc and reset input pin (9) to provide power on reset
·         A push button switch is connected in parallel with C3 to provide manual reset
·         A 12 MHz crystal along with two capacitors C1 and C2 connected to XTAL1 and XTAL2 provides necessary clock to micro controller 

Working

Working and operation: –
Both the input signals either direct frequency or pulse output from sensor are first fed to wave shaping circuit. As we can see it’s a simple transistor as a switch circuit its output is low when input is more than 0.7 V and it is high if input is less than 0.7 V. so when any type of signal is applied directly (sine wave or any other) it will be converted into pulses from 0 to 5 V. the output of sensor is in pulse form itself but it will be inverted by this circuit.
 
The pulses are fed to external interrupt 1 and timer0 input pin of micro controller. So micro-controller will start counting these pulses. The LED remains ON till counting finishes. Now here there are two cases
1.      If its frequency counter, the pulses are counted for 1 sec time. We shall get direct value as number of pulses per sec.
2.      For RPM we know 1 RPM = 60 RPS. So as we get the value of number of revolutions per second we shall multiply it by 60. But because as RPM value is small, I am counting revolutions for 5 sec and then multiply it with 12. So finely we shall get 12×5 = 60 sec = 1 min that means we get revolutions per minute 
 
This value is then converted into ASCII format and then it is displayed on LCD
 
To change from frequency counter to RPM counter and vice versa, change SW2 and SW1 to gather and then press “RESET” button. So as the program detects change in logic level at pin P2.0, it will change the measuring parameter.
 
Every time when the counting finishes, the program will check the status of pin P2.1. If its logic 1 that means no further measurement now stop. For next measurement one has to press “RESET” again. If P2.1 is at logic 0 that means continue to take readings after every 5 second.     
 
Software logic: –
The program loaded into micro controller is written in C language and compiled using KEIL (IDE). Complete program is a collection of different functions.
The display function displays value of frequency or RPM in 4 digits. It first separates all four digits convert it into ASCII and display them one by one
Interrupt function calculates external pulses on T0 input pin for 1 sec or 5 sec.
Delay function is variable delay function that generates either 1 sec or 5 sec for counting frequency or RPM
 
Four functions are given for LCD operation
1.      writedata – it sends data to be displayed on LCD screen
2.      writecmd – it sends command to operate LCD
3.      writestr – it displays various text messages on LCD
4.      busy – it waits for LCD to become ready for accepting next data or command byte
Working Videos
Frequency Counter
RPM Counter

 

 

 

 

Project Source Code

###


#include<reg51.h>

#include<string.h>

 

sbit rs = P2^7;                                                 // rs pin of LCD

sbit en = P2^6;                                                            // en pin of LCD  

sbit led= P2^5;

sbit sw = P2^1;

sbit pin = P2^0;

unsigned int flag=0,d;                                                 // rpm flag

 

void delay(int a)                                                          // 1 sec or 5 sec delay

  {

            int k;

            TL1 = 0xBF;                                       // load value 15550=3CBF

            TH1 = 0x3C;

            TR1 = 1;

            for(k=0;k<a;k++)

              {

                        while(TF1==0);

                        TF1 = 0;

                        TL1 = 0xBF;

                        TH1 = 0x3C;

              }

            TR1 = 0;

  }

void busy()                                                     // check busy flag

{

            int x;

            for(x=0;x<1500;x++);

}

void writecmd(unsigned char a)                                 // send command byte to LCD

{

            busy();

            rs = 0;             

            P0 = a;

            en = 1;

            en = 0;

}

void writedata(unsigned char b)                                 // send data byte to LCD

{

            busy();

            rs = 1;             

            P0 = b;

            en = 1;

            en = 0;

}

void writestr(unsigned char *s)                                  // write string / message to LCD

{

            unsigned char l,i;

            l = strlen(s);

            for(i=0;i<l;i++)

            {

                        writedata(*s);

                        s++;                

            }

   }

void int1(void) interrupt 2                              // external interrupt 1 function

  {

            EA=0;                                                             // first disable interrupts         

            led=0;

            TH0=0x00;                                          // clear T0

            TL0=0x00;

            if(pin==0) d=20;                                             // for freq counter delay is 1 sec and 

            else d=100;                                          // for RPM counter delay is 5 sec

            TR0=1;                                                            // start timer 0

            delay(d);                                              // give 1 sec or 5 sec delay

            TR0=0;                                                            // stop timer    

            flag=1;                                                            // if not then set the flag

            led=1;

      }

void display()                                                  // convert hex to desimal and 

       {                                                               // decimal to ascii

            unsigned int tmp1,tmp2,tmp3,tmp4,t,t1,i,j;

            unsigned char asci[5];

            tmp1 = (TL0 & 0x0F);

            tmp2 = TL0 >> 4;

            tmp3 = (TH0 & 0x0F);

            tmp4 = TH0>>4;

            tmp2 = tmp2*16;

            tmp3 = tmp3*256;

            tmp4 = tmp4*4096;

            t = tmp1+tmp2+tmp3+tmp4;

            if(pin==1) t=t*12;                               // for RPM multiply the value by 12 

            i=4;

            if(t>=10000)

              {

                        while(t>=10)

                          {                   

                                    t1=t%10;

                                    asci[i]=t1+0x30;

                                    t=t/10;

                                    i--;

                          }

                        asci[0]=t+0x30;

              }

            else if (t>=1000)

              {

                        while(t>=10)

                          {                   

                                    t1=t%10;

                                    asci[i]=t1+0x30;

                                    t=t/10;

                                    i--;

                          }

                        asci[1]=t+0x30;

                        asci[0]=0x20;

              }

            else

              {

                        while(t>=10)

                          {                   

                                    t1=t%10;

                                    asci[i]=t1+0x30;

                                    t=t/10;

                                    i--;

                          }

                        asci[2]=t+0x30;

                        asci[1]=0x20;

                        asci[0]=0x20;

              }

            writecmd(0x01);        

            if(pin==0) writestr("frequency:");        // display current RPM and

            else writestr("current RPM:"); 

            writecmd(0xC0);        

            for(j=0;j<5;j++)

                        writedata(asci[j]);                     // all four digits one by one

            if(pin==0) writestr(" Hz");

         }

void main()

    {

                        TMOD=0x15;            // timer 0 in 16 bit counter and timer 1 in 16 bit counter

                        P0 = 0x00;                   // P0 as output port                 

                        rs=0;                            // clear all LCD control pins

                        en=0;              

                        sw=1;

                        led=0;

                        led=1; 

                        pin=1; 

                        writecmd(0x3C);                                  // initialize LCD

                        writecmd(0x0E);

                        writecmd(0x01);

                        if(pin==0)       

                             {

                                    writecmd(0x84);                     // initially display message

                                    writestr("Frequency");             // frequency counter

                               }

                        else

                              {   

                                    writecmd(0x87);

                                    writestr("RPM");                     // or RPM counter

                             }

                        writecmd(0xC5);

                        writestr("Counter");                 

                        TH0=0x00;                                         // clear T0

                        TL0=0x00;

                        IT1=1;

                        IE=0x84;                                            // enable external interrupt 1

            next:     while(flag==0);                                              // remain within loop till rpm flag is clear

                        display();                                            // when flag is set display value         

                        flag=0;                                                 // reset the flag to 0 again

                        EA=1;                                                 // again enable interrupts

                        If(pin==0) {d=100;delay(d);}                        // for continuous freq measurement give 

                                                                                    // delay of 5 sec

                        if(sw==0) goto next;                          // again go for next measurement

                        while(1);

            }

 

 

###

 


Circuit Diagrams

RPM-Counter-Circuit


Filed Under: Electronic Projects
Tagged With: counter, frequency, rpm
 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • PS2 Keyboard To Store Text In SD Card Using Arduino Circuit Setup On Breadboard
    How To Use PS2 Keyboard To Store Text In SD Card Using Arduino- (Part 42/49)
  • Wireless Path Tracking System Using Mouse, XBee And Arduino Circuit Setup On Breadboard
    How To Make A Wireless Path Tracking System Using Mouse, XBee And Arduino- (Part 43/49)
  • How to Make a Wireless Keyboard Using Xbee with Arduino- (Part 44/49)
  • Making Phone Call From GSM Module Using Arduino Circuit Setup On Breadboard
    How to Make Phonecall From GSM Module Using Arduino- (Part 45/49)
  • How to Make a Call using Keyboard, GSM Module and Arduino
    How To Make A Call Using Keyboard, GSM Module And Arduino- (Part 46/49)
  • Receiving SMS Using GSM Module With Arduino Prototype
    How to Receive SMS Using GSM Module with Arduino- (Part 47/49)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What is a low power design?
  • Renesas partners with Tata to accelerate progress in advanced electronics
  • STMicroelectronics’ new touchscreen controller for smartphones enables longer runtime
  • Samsung unveils ISOCELL image sensor with industry’s smallest 0.56μm pixel
  • Renesas and Cyberon to deliver integrated voice-user interface solutions

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Atrduino IDE ompilation Error
  • Cadence Layout (LVS error in bulk connections)
  • FPGA LVDS with separate clock
  • Limits of duty cycle for ICM7555 IC?
  • 12V 5A needed

RSS Electro-Tech-Online.com Discussions

  • Bridge purpose in connecting the two functional circuit
  • How to quickly estimate lead acid battery capacity ?
  • ICM7555 IC duty cycle limit at high frequency?
  • intro to PI
  • writing totals in Eprom
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering