About timer operation in 8051 micro controller

sparsh sharma

sparsh sharma

@sparsh-sharma-6HWmix Oct 26, 2024

I AM STUDYING MICROCONTROLLER 8051 SUBJECT, WHILE DOING PROGRAM OF TIMER OPERATION, I HAVE FOUND SOME PROBLEM IN THE MODE 2 OF TIMER OPERATION IN WHICH CONTENTS PRESENT IN THx IS AUTO RELOADED INTO THE TLx AND WHEN TLx BECOMES 00H TFx FLAG GOES HIGH AND CONTENTS AGAIN AUTO RELOADED INTO THE TLx FROM THx.
BUT THERE IS A PROBLEM WHEN TIMER STARTS BY SETTING THE TRx BIT HIGH, THE TLx STARTS FROM 00H INSTEAD OF STARTING WITH THE CONTENTS OF THx. TLx ALWAYS STARTS WITH 00H.
I HAVE ALSO ATTACHED THE IMAGE OF MY PROGRAM THAT I HAVE WRITTEN IN KEIL SOFTWARE WHERE IN THE RED CIRCLE I HAVE SHOWN THE CONTENTS OF THE TH AND TL REGISTER.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Harshad Italiya

    Harshad Italiya

    @harshad-ukH5ww Nov 16, 2015

    #-Link-Snipped-# can you share your keil project .zip file here?

  • sparsh sharma

    sparsh sharma

    @sparsh-sharma-6HWmix Nov 17, 2015

    Harshad Italiya#-Link-Snipped-# can you share your keil project .zip file here?

    #-Link-Snipped-#
    i have written just a small program to check the working of timer in mode 2.

  • IanSiladi

    IanSiladi

    @iansiladi-j6K893 Nov 26, 2015

    The problem is looking in your code. Are you enable to put the count that should be copied into the TL from the TH?
    Also what about your interrupt handling?
    Are you using any kind of the hardware interrupt here, specially for your timer-counter?

    #-Link-Snipped-#

  • sparsh sharma

    sparsh sharma

    @sparsh-sharma-6HWmix Nov 26, 2015

    IanSiladiThe problem is looking in your code. Are you enable to put the count that should be copied into the TL from the TH?
    Also what about your interrupt handling?
    Are you using any kind of the hardware interrupt here, specially for your timer-counter?

    This code is written just for the purpose of understanding the Timer operation in MODE 2 of 8051uc. i have also simulate it on keil uvision3 software. the snap shot of the output i have attached.
    and count in TL0 is loaded with TH0 contents only if TF0 is made high internally, initially TL0 starts with 00h.
    and about interrupt i am using the polling/status check method not using any hardware interrupt.
    just checking the TF0 bit status

  • Harshad Italiya

    Harshad Italiya

    @harshad-ukH5ww Nov 26, 2015

    #-Link-Snipped-# :
    <a href="https://www.keil.com/download/docs/96.asp" target="_blank" rel="nofollow noopener noreferrer">8051 Timer 0 Mode 1 Example Program</a>
    <a href="https://www.keil.com/download/docs/97.asp" target="_blank" rel="nofollow noopener noreferrer">8051 Timer 1 Mode 2 Example Program</a>
    You can find Timer 0 example code from KEIL. Try this and see if this is working for you properly or not.

  • sparsh sharma

    sparsh sharma

    @sparsh-sharma-6HWmix Nov 27, 2015

    Harshad Italiya#-Link-Snipped-# :
    <a href="https://www.keil.com/download/docs/96.asp" target="_blank" rel="nofollow noopener noreferrer">8051 Timer 0 Mode 1 Example Program</a>
    <a href="https://www.keil.com/download/docs/97.asp" target="_blank" rel="nofollow noopener noreferrer">8051 Timer 1 Mode 2 Example Program</a>
    You can find Timer 0 example code from KEIL. Try this and see if this is working for you properly or not.

    yes its working but with the same way as i have mentioned, there is a need to load the TLx register first, there is no auto reload initially in this mode2. auto reload happens only after the generation of Timer Flag internally.
    Thanks

  • Harshad Italiya

    Harshad Italiya

    @harshad-ukH5ww Nov 27, 2015

    sparsh sharmayes its working but with the same way as i have mentioned, there is a need to load the TLx register first, there is no auto reload initially in this mode2. auto reload happens only after the generation of Timer Flag internally.
    Thanks

    I am still not getting you. Have you checked what is the difference between your code and the example code?

  • sparsh sharma

    sparsh sharma

    @sparsh-sharma-6HWmix Nov 28, 2015

    Harshad ItaliyaI am still not getting you. Have you checked what is the difference between your code and the example code?

    yes i checked, there is no difference, both are same
    thank you sir