EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • 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
  • Advertise
You are here: Home / Topics / Speed Calculation using 8051 uC

Speed Calculation using 8051 uC

|

Microcontroller › 8051 › Speed Calculation using 8051 uC

  • This topic has 4 replies, 3 voices, and was last updated 11 years, 2 months ago by Ashutosh Bhatt.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • July 9, 2012 at 12:02 am #3859
    talal
    Participant

    Hello everybody, 

    I am trying to measure the speed of a machine using IR sensor interfaced with the 8051 microcontroller. I am using proteus for simulation. While running the simulation, when I provide external interrupt using push button, the value displayed on LCD is in thousands while I am only using a counter to increment once for each external interrupt so that I can know the distance through number of interrutions and divede it with time(using a timer for this purpose) to calculate the speed. I don't seem to understand the problem. It is probably due to the reason that external interrupt duration should be only for a few microseconds !! 

    Need your help on this. Here is the code:

     

     
     
    #include <reg51.h>
    #include <stdio.h>
     
     sfr  output= 0x90;
     sbit RS= P2^0;
     sbit RW= P2^1;
     sbit EN= P2^2;   
     sbit test= P1^7;
     
     int timer;
     int counter;
     void InitializeLCD(void);
     void datadisplay(unsigned char value);
     void command(unsigned char num);
     void ready(void);
     void delay(void);
     
     
    void func_ext_intr() interrupt 2{
    counter = counter + 1;
    }
     
     
    void timer0(void) interrupt 1{
      TF0 = 0;
      TH0 = 0x00;
      TL0 = 0x00;
      TR0 = 1;
      timer = timer + 1;
      if (timer == 420){
      timer = 0;
      }
      }
     
     
     
     
    //////////////////////////////Main Routine////////////////////////////////
     
     int main(void)
      {
       int i=0;
       unsigned int count=0;
       unsigned int speed=0;
       unsigned int test;
       
       char onscreen[]="SPEED";
       char value[6];
       IE = 0x8E;   
     
     ////////////////////////////STARTING TIMER///////////////////////////////
     
        TMOD = 0x21; // setting timer 1 for serial communication and timer 0 for time
        TH0 = 0x00;  
        TL0 = 0x00;
        TR0 = 1;   
     
     
       InitializeLCD();
       
       
       for(i=0;onscreen!='';i++ )
     {
      datadisplay(onscreen);
     }
     
       
       while(1)
    {
     
     
    for(i=5;i>=0;i–)
       {
        value=(timer%10)+0x30;
        timer= timer/10;
       }
    command(0x86);
     
           for(i=0;i<6;i++)
             {
        datadisplay(value);
     
       }
    command(0x8D);
     
    //////////////////////////////for 2nd row////////////////////////
     
    command(0xC0);
    command(0xC6);
     
    for(i=5;i>=0;i–)
       {
        value=(counter%10)+0x30;
        counter=counter/10;
       }
     
         command(0xC6);
         for(i=0;i<6;i++)
            {
        datadisplay(value);
     }
     
    command(0xCD);
     
    speed = (counter)/(timer);
     
     
    ///////////////////////////for third row////////////////////
     
    command(0x90);
    command(0x96);
     
    for(i=5;i>=0;i–)
       {
        value=(speed%10)+0x30;
        speed=speed/10;
       }
     
         for(i=0;i<6;i++)
            {
        datadisplay(value);
     }
       }
     
        return 0;
      }
    ///////////////////////////LCD initializing Routine//////////////////////
     
     void InitializeLCD(void)
      {
       command(0x38);
       command(0x01);
       command(0x80);
       command(0x0F);
       command(0x06);
       
      } 
     
    /////////////////////////LCD Interfacing Routines/////////////////////////
     
     void command( unsigned char num )
      {
       ready();
       output= num;
       RS=0;
       RW=0;
       EN=1;
       delay();
       EN=0;
       return;
      }
     
     void datadisplay(unsigned char value)
      {
       ready();
       output= value;
       RS=1;
       RW=0;
       EN=1;
       delay();
       EN=0;
       return;
      } 
     
     void ready(void)
      {
       test=1;
       RS=0;
       RW=1;
       while(test==1)
    {
    EN=0;
    delay();
    EN=1;
    }
    return;
      }
        
       void delay(void)
      {
        unsigned int i,j;
    for(i=0;i<=8;i++)
    {
    for(j=0;j<=1275;j++);
    }
    return;
      }
     
     
    March 31, 2014 at 6:16 am #11429
    Ramkrishna
    Participant

    Bro can you give me detail about the ckt diagram of this project? I’m making this project and i need your help.

    April 3, 2014 at 5:08 pm #11461
    Ashutosh Bhatt
    Participant

    provide some delay in your interrupt subroutine. delay of around 100-200 ms.

    April 4, 2014 at 4:22 am #11462
    Ramkrishna
    Participant

    #A.M. Bhatt

    Hello sir, can you please help me in this project, i do not get the circuit diagram through this code. Can you give me some detail about the ckt diagram according to this code. I’ll be thankful to you. It is my major project and i’ve no idea how will i complete. My Email id is [email protected].

    April 5, 2014 at 1:20 pm #11470
    Ashutosh Bhatt
    Participant

    sorry i dont have circuit. search for circuit diagram on this site or on google

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What is correct names for GOOD user friendly circuit drawing program? June 18, 2025
  • Curved lines in PCB design June 18, 2025
  • using a RTC in SF basic June 18, 2025
  • Is AI making embedded software developers more productive? June 18, 2025
  • Why can't I breadboard this oscillator? June 18, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

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 | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • 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
  • Advertise