1
\$\begingroup\$

IN 8051, Timer 0 in mode 1, if the maximum count reaches, the timer should displayed with 0000H, and should stay 0000h until we stop it and start again . But with this program

 MOV TMOD,#01H
 MOV TH0,#0FFH
 MOV TH1,#0DCH
 SETB TR0

The timer counts up to FFFFH then again starts from 0000, is not it unexpected?

enter image description here

  1. in some internet reference it says, when it finishes counting to ffffh it "stops", does it really stop or is it just running in the background and pretending as if it has stopped by staying at 0000?

  2. after the counting is finished and when it is showing 0000, at this moment if we really stop the counter by CLR TR0, will it imply now the counter is really reset? and if just after that SETB TR0 is used, then will it count from 0000?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The 8051 timers definitely keep counting unless you explicitly stop them.1

So:

  • No, it is not unexpected.
  • No, it does not actually stop.
  • No, it does not guarantee that it is reset, because the counter may have advanced by one or more counts before the firmware actually got around to stopping it.

1 In fact, there's a technique called "precision reload" that takes advantage of this to eliminate accumulated error when using the timer repeatedly to create interrupts at regular intervals, despite some jitter in the interrupt latency.

\$\endgroup\$
3
  • \$\begingroup\$ does this applies to mode to auto reload too? means, after reaching 0000, will it again start counting from the value which has been loaded into THx instead of expecting stop and start the counter again? \$\endgroup\$
    – Sayan
    Aug 2, 2021 at 15:23
  • 1
    \$\begingroup\$ Yes, that is the whole point of auto-reload -- you set up the timer once and it just keeps going, generating the specified interval over and over. The "precision reload" technique is used in Mode 1, when you need a 16-bit counter. \$\endgroup\$
    – Dave Tweed
    Aug 2, 2021 at 15:25
  • 1
    \$\begingroup\$ so at anytime, "stopping " the counter should mean "pausing" the counter , whatever it counts for that moment, is not it? \$\endgroup\$
    – Sayan
    Aug 2, 2021 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.