This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer in autoload mode

I use Keil sometimes and while using a timer in autoload mode, the TH0 is loaded with the calculated value but TL0 starts incrementing from 00 instead of the calculated value F0.Am I missing something while using or configuring the keil simulator?

Parents
  • The code clearly states that its polling and interupt mode. Interupt register is not included as you can all see in the lines of the code. All it does is check the flag and reset it after stopping the timer and all I am getting are replies which does not solve my problem. Someone stated that "Why use autoload mode". Is there a ban in using autoload mode if the pulse duration is small. The above is for generating square wave and my question was the above code works perfectly well when run on keil simulator in mode 1. It does work when using mode 2. When running on mode 2, the TL0 register jumps directly to F3 and stops the timer in between. Anyone on this forum can run the code using keil simulator and see the difference when it runs in mode 1 and mode 2. Check the timer peripheral registers while running the debug.

Reply
  • The code clearly states that its polling and interupt mode. Interupt register is not included as you can all see in the lines of the code. All it does is check the flag and reset it after stopping the timer and all I am getting are replies which does not solve my problem. Someone stated that "Why use autoload mode". Is there a ban in using autoload mode if the pulse duration is small. The above is for generating square wave and my question was the above code works perfectly well when run on keil simulator in mode 1. It does work when using mode 2. When running on mode 2, the TL0 register jumps directly to F3 and stops the timer in between. Anyone on this forum can run the code using keil simulator and see the difference when it runs in mode 1 and mode 2. Check the timer peripheral registers while running the debug.

Children
  • I agree that whatever mode the timer runs on is irrelevant for your question. so let's move on from that distraction.

    "When running on mode 2, the TL0 register jumps directly to F3 and stops the timer in between. "

    but you wrote earlier: "while using a timer in autoload mode, the TH0 is loaded with the calculated value but TL0 starts incrementing from 00 instead of the calculated value F0."

    two comments:

    1) the two statements are inconsistent; so you may want to tell us which is accurate.
    2) as to the timer jumping to 0xf3 rather than 0xf0: because you are likely stepping through the code in C. each C statement may correspond to multiple asm instructions. so if you were to step through the disassembly, you should see TL0 starting from 0xf0, rather than 0xf3.

  • "so if you were to step through the disassembly, you should see TL0 starting from 0xf0, rather than 0xf3."

    stepping through the code in assembly, TF0 is set right after the roll over, and TL0 is at 0xf1.

    the reading of 0xf3 is likely because of the time lapse on testing the TF0 flag while the tmr0 continues to run and increment TL0.

  • The code clearly states that its polling and interupt mode.
    The code you show "clearly states" that no interrupt is involved

    Interupt register is not included as you can all see in the lines of the code.
    so, how did you imagine we would know

    All it does is check the flag and reset it after stopping the timer
    mixing polling and interrupt must be done with other means than the SFRs

    Someone stated that "Why use autoload mode". Is there a ban in using autoload mode if the pulse duration is small.
    absolutely not, but the code you show does not have any autoload use

    so, show some actual, complete, indented, commented code and someone will help you

    Erik

  • The code clearly states

    Nonsense. What "code" you showed us here doesn't state anything clearly.

    that its polling and interupt mode.

    And that's an obvious self-contradiction.

    all I am getting are replies which does not solve my problem.

    That's because you failed quite spectacularly at presenting what your problem even is.

    the above code works perfectly well when run on keil simulator in mode 1. It does work when using mode 2.

    So it works in both modes, you say. What was your problem, again?

  • "Nonsense."

    no reason to be so harsh.

    yes, his posts were not the clearest; and his mastery of english words wasn't as smooth as yours.

    but he got the gist of his points across after a few tries.

    maybe you can ask him for more clarification, but there is no point in beating down a newbie to establish your superiority, because everyone of us was a newbie in the not-so-distant past and will be a newbie in the not-so-distant future on some matters.

    so be kind and stop being an @#$@

  • "show some actual, complete, indented, commented code"

    his code is actual and complete, sufficient to get you to his "problem", as is.

    but here is his code presented in a nicer way, per your request.

    #include <reg51.h>
    
    void delay();
    sbit mybit = P1^5;
    
    main()
    {
            while(1)
            {
                    mybit = mybit^1;
                    delay();
            }
    }
    
    void delay()
    {
            TMOD = 0x02;
            TH0 = 0xF0;
            TL0 = 0xF0;
            TR0 = 1;
            while (TF0==0);
            TR0 = 0;
            TF0 = 0;
    }
    

  • "so be kind and stop being an @#$@"

    Oh brother! That from the like of you, who is without question the biggest, most overt "@#$*" we've had on this forum, the Microchip forum, and the HI-TECH forum! Sheesh!

  • his code is actual and complete,

    You're either deluding yourself, or you're deliberately talking nonsense. I'm sure of that because it's blatantly clear that you have no way of knowing what you just claimed.