0
\$\begingroup\$

I need to configure a display that updates its values with f = 50 Hz.

Since the CPU works with 16 MHz and the prescaler has a max. value of 256, the min. clock rate I can compute is 62.5 kHz.

How do you go about this? Do you concatenate several timers? If I would take the output of Timer0 and put it into Timer1 with another prescaler of 256, I would get 244.140625. Timer2 and another prescaler of 5, would result in 48.828125 Hz, which would be acceptable. Is this how you do it or is there an easier and better way?

\$\endgroup\$
  • \$\begingroup\$ A display updated 50 times-per-second? It may not make much sense to a human eye - just a blur of merged digits for those that change often. \$\endgroup\$ – glen_geek Jun 22 at 12:57
  • 1
    \$\begingroup\$ "TI micrcontrollers" is not meaningful; like most chip vendors they offer a wide range with completely different details. You'll have to be specific about which MCU. Or if you mean to be asking a general question, then "texas-instruments" as a tag on this is pointless; essentially there's no validity to having that tag on this question at all, as it is either insufficient or irrelevant. \$\endgroup\$ – Chris Stratton Jun 22 at 15:49
  • \$\begingroup\$ It's also worth keeping in mind that in quite a few MCU's it's traditional to the point of having specific hardware support to have a periodic timer interrupt anyway, which slower / more jitter-tolerant tasks can be chained off of via software, without using any additional timer for that purpose. \$\endgroup\$ – Chris Stratton Jun 22 at 15:53
0
\$\begingroup\$

You'd just use an integerin a timer interrupt, and increase it (count) as many times as necessary to reach 50 Hz.

In your case, your timer interrupt would count up to 62500 / 50 = 1250, then reset to zero, and also trigger the update.

pseudo-code:

global integer counter; //initialize to 0

void timer_interrupt_service_routine():
  counter = counter + 1
  if counter larger or equal 1025:
     counter = 0
     update_the_display()

It's as easy as that. Counting is cheap.

\$\endgroup\$
  • \$\begingroup\$ Well, I did not really get the concept with the prescaler, load and match value yet. I guess it is easy, once you have understood. \$\endgroup\$ – neolith Jun 22 at 13:10
  • \$\begingroup\$ there's nothing special here happening. In your timer interrupt, you count a variable up by one. If it's 1025, you update your display. \$\endgroup\$ – Marcus Müller Jun 22 at 13:51
  • \$\begingroup\$ @neolith - the point here is that a timer is only the first stage, the remainder is software. Using a chain of two timers is rarely required, except for the rare and unique realm of applications that are both slow and intolerant of even tiny jitter. Many traditional MCU stacks already have a timer interrupt you may be able to chain off of, such that you don't end up dedicating any hardware timers to this need beyond the one that would already be used even without this need. \$\endgroup\$ – Chris Stratton Jun 22 at 15:54

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.