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 / question about digital clock project posted here.

question about digital clock project posted here.

|

Microcontroller › 8051 › question about digital clock project posted here.

  • This topic has 7 replies, 2 voices, and was last updated 14 years, 11 months ago by romel emperado.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • April 13, 2011 at 5:27 am #861
    romel emperado
    Participant

    guys pls explain to me how did they come up with this calculation for the timer to generate a delay of 1sec..

     

     

    this project is posted here: http://www.engineersgarage.com/microcontroller/8051projects/digital-clock-AT89C51-circuit

    void delay()        //Function to provide a time delay of approx. 1 second. using Timer 1.
    {
    int i;
    for(i=0;i<20;i++)
    {
    TL1=0xFD;
    TH1=0x4B;
    TR1=1;
    while(TF1==0);
    TR1=0;
    TF1=0;
    }
    }

    FD4B is 64843 in decimal  so pls tell me how would that calculation genarate 1 second? that is less that a second.. correct me IF am wrong but i think something wrong with the calculation..

     

     

    I have my own code here to generate 1second using 12Mhz crystal but i dont get it how the above code geraate a second delay..

     

     

    void delay(char k)
    {
      char i;
      TR1=0;
      for(i=0; i<k; i++)
      {
        TH1=0x3c;
        TL1=0xB0;
        TF1=0;
        TR1=1;
        while(TF1==0);
        TR1=0;
      }
    }

    April 13, 2011 at 7:29 am #5967
    dagakshay
    Participant

    hello romel,

     

    How does the code you have pased above (which which given on site) is giving 1 second…

     

    timer register is a 16 bit register since they are using it in mode1

     

    TH1=0x4B;

    TL1=0xFD;

     

    so 4BFD = 19453 in decimal

     

    65535 – 19453 = 46083;

     

    they using 12MHz crystal so freq./12clock

    12MH/12=1Mhz

    t=1/f=1 us in the case of 12 MHz crystal

    if they would have used 11.0592 Mhz it would be 1.085 us

     

    46083*1us*20 loops= 921660 us near about 0.92 second for 12Mhz

    46083*1.085us*20 loops= 1000001.1 micro second which is more closer to 1 second

     

    ideally they would have used or calculated it for 11.0592Mhz

     

    and the delay function(second one) which you have pasted will count = 49999 us*k (according to 12Mhz)

    if k=20 the total it will give around 0.99 second… so you delay in case of 12 Mhz will be more accurate..

    April 13, 2011 at 9:27 am #5971
    romel emperado
    Participant

    haha look at my previous post… My convertion is wrong that is why i said it’s less than a second.. hehe thanks so much yar :)

    April 15, 2011 at 1:09 am #5977
    romel emperado
    Participant

    hello again.. i have done actual hardware experiment about the accuracy of these values and i come up results.

     

     

    this value below is not realy accurate 1 second delay. i compared it to a real digital clock it will be late for 20secs after 48hours..

     

    TH1=0x3C;
    TL1=0xB0;

     

    i think this one would be better but its under observation :)

     

    TH1=0x3C;
    TL1=0xBB;

     

    its beter to use RTC… less hassle .. hihi

    April 15, 2011 at 5:40 am #5981
    dagakshay
    Participant

    it is delayed because the crystal we use that is why for higher research ppl generally you other clock source… exaclty i dont remember what is that term… “partially it is an atomic clock” which basically some of relation with the nuclear half life period i dont know its complete details…in the case of watch for more acuracy analog clock are prefered rather then the digital one… you yourself can see the difference.. buy a local digial clock and a standard one any branded digital clock… set them with same time just in few months you can notice the dealy b/w them.. that is why standard companies digital clock are more costaly than the local one… its a very nice concept i read a long back thanks for repolishing my old dead blocks… i will surly write an artical on it and send it to you as soon as possible…..

    April 15, 2011 at 6:47 am #5982
    romel emperado
    Participant

    yeah thanks for answering yar.. yes it is true…

     

    but for some hobbyist in embedded system using real time clock(RTC) and interface with controller is much better compared of using timer interrupt.. :)

     

    example of RTC use in some projects is DS 1307..

    April 15, 2011 at 7:43 am #5983
    dagakshay
    Participant

    Interfacing RTC again makes the ckt bulier and the code goes heavier… you can use the controller which would hae inbult RTC… but again id depends on kind of application you using… sor some small applications timer is more than sufficient

    April 20, 2011 at 4:44 am #6003
    romel emperado
    Participant

    I agree.. it depends on your application..

     

     

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

RSS Recent Posts

  • cpap change over circuit March 14, 2026
  • Fender rumble 100 base amp, power, light and overdrive light flash repeatedly when power turned on no output March 13, 2026
  • Phone to op amp circuit? March 13, 2026
  • Arduino standalone minimal March 13, 2026
  • Project boxes March 13, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

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