Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Frequency and RPM Counter

By Ashutosh Bhatt June 21, 2012

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
 

Next Article

← Previous Article
Next Article →

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.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

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!


RSS EDABOARD.com Discussions

  • How to generate and use large‑signal S‑parameter (LSSP) files for PA harmonic‑balance (HB) simulations?
  • Snooping Around is All
  • ADEM III ECM — No CAN Signal & Power Supply Issue
  • IGBTs without negative gate drive
  • SMPS feedback circuit

RSS Electro-Tech-Online.com Discussions

  • More fun with ws2812 this time XC8 and CLC
  • Pic18f25q10 osccon1 settings swordfish basic
  • Pickit 5
  • turbo jet fan - feedback appreciated.
  • I Wanna build a robot

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 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

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe