Why is it preferable to use the built-in timer module rather than using assembly language coding to create delay loops?

I've gone through the entire "HCS12 Microcontroller and Embedded Systems" book, but cannot figure out why it is preferable to use the built-in timer module for the HCS12 microcontroller. I hope that someone can shed some light on this

  • \$\begingroup\$ How about I turn your question around - why would you dedicate your micro to executing a timing loop when you could just assign that task to the timer module and let the micro carry on doing something else? \$\endgroup\$ – brhans Feb 1 '19 at 4:27
  • \$\begingroup\$ That actually helped a lot! It makes sense now. \$\endgroup\$ – Carlos Feb 1 '19 at 4:30
  • \$\begingroup\$ Answer here: electronics.stackexchange.com/a/192635/6102. Doesn't matter if you use HCS12 or PIC, same problems. In addition to what's mentioned, add "programmer incompetence". A frightening amount of embedded programmers don't know how to declare the loop iterator for such a loop, with volatile. Then they enable optimization and poof it goes. \$\endgroup\$ – Lundin Feb 1 '19 at 10:38

Because the timer works asynchronously to the program. With a timer you can set up a periodic interrupt that always happens on time, regardless of what code is running -- if you tried to do that with assembly language loops or whatnot you'd always be chasing any changes in the code to change the timing of the loops.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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