CrazyEngineers
  • About timer operation in 8051 micro controller

    sparsh sharma

    sparsh sharma

    @sparsh-sharma-6HWmix
    Updated: Oct 26, 2024
    Views: 1.3K
    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.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Harshad Italiya

    MemberNov 16, 2015

    #-Link-Snipped-# can you share your keil project .zip file here?
    Are you sure? This action cannot be undone.
    Cancel
  • sparsh sharma

    MemberNov 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.
    Are you sure? This action cannot be undone.
    Cancel
  • IanSiladi

    MemberNov 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-#
    Are you sure? This action cannot be undone.
    Cancel
  • sparsh sharma

    MemberNov 26, 2015

    IanSiladi
    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?
    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
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberNov 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.
    Are you sure? This action cannot be undone.
    Cancel
  • sparsh sharma

    MemberNov 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
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberNov 27, 2015

    sparsh sharma
    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
    I am still not getting you. Have you checked what is the difference between your code and the example code?
    Are you sure? This action cannot be undone.
    Cancel
  • sparsh sharma

    MemberNov 28, 2015

    Harshad Italiya
    I 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
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register