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
  • void delay()
    {
      TMOD = 0X20; /*Timer 1 operation in mode 2*/
      TH1 = -184;
      TR1 = 1;
      while(TF1==0);/*Polling mode is used instead of interupt mode*/
      TR1 = 0;
      TF1 = 0;
    }
    

    It works in autoload mode and the TL1 starts intially from 00 and later gets

    loaded by the value in TH1 register.The problem is that it doesnt leave the delay routine

    to go back to main program again

    how can it 'work' when "The problem is "

    for the first delay you depend on whatever is in TL1 for your delay no autoload takes place before the timer roll over. for the next delay you will get the autoload value plus whetever counts happened before TR1=0. You are confusing the whole issue by using autoload. With a lot of feniggeling I have no doubt this could be done with autoload but why use auotoload when only one run in the routine. Using illogical modes does nothing but make the issue confusing, complex. less maintainable, less understandable, and error prone.

    why not just straight code

    void delay()
    {
      TMOD = 0X10; /*Timer 1 operation in mode 1*/
      TH1 =  0xff;
      TL1 = -184;
      TR1 = 1;
      while(TF1==0);/*Polling mode is used instead of interupt mode*/
      TR1 = 0;
      TF1 = 0;
    }
    

    Erik

Reply
  • void delay()
    {
      TMOD = 0X20; /*Timer 1 operation in mode 2*/
      TH1 = -184;
      TR1 = 1;
      while(TF1==0);/*Polling mode is used instead of interupt mode*/
      TR1 = 0;
      TF1 = 0;
    }
    

    It works in autoload mode and the TL1 starts intially from 00 and later gets

    loaded by the value in TH1 register.The problem is that it doesnt leave the delay routine

    to go back to main program again

    how can it 'work' when "The problem is "

    for the first delay you depend on whatever is in TL1 for your delay no autoload takes place before the timer roll over. for the next delay you will get the autoload value plus whetever counts happened before TR1=0. You are confusing the whole issue by using autoload. With a lot of feniggeling I have no doubt this could be done with autoload but why use auotoload when only one run in the routine. Using illogical modes does nothing but make the issue confusing, complex. less maintainable, less understandable, and error prone.

    why not just straight code

    void delay()
    {
      TMOD = 0X10; /*Timer 1 operation in mode 1*/
      TH1 =  0xff;
      TL1 = -184;
      TR1 = 1;
      while(TF1==0);/*Polling mode is used instead of interupt mode*/
      TR1 = 0;
      TF1 = 0;
    }
    

    Erik

Children