i know that there are two types for clock in a Timer in a micocontroller one of them is the counter and i wonder how the counter can be a clock ?

  • \$\begingroup\$ Do you know how many different microcontrollers out there? \$\endgroup\$
    – Eugene Sh.
    Apr 8, 2016 at 14:20
  • \$\begingroup\$ sorry for not being specific ... i'm using PIC microcontroller more specifically 18F4520 \$\endgroup\$
    – user94838
    Apr 8, 2016 at 14:24
  • \$\begingroup\$ If the counter counts clock pulses, and the pulses are of a known duration, your counter is behaving as a timer. \$\endgroup\$ Apr 8, 2016 at 14:30

1 Answer 1


It is very usual for a microcontroller timer to have two possible clock sources:

  • First is the internal clock (probably with some kind of frequency dividers)
  • Second is a pulsed signal from an external source, connected through an input digital port.

Independently of the source, the timer counts the incoming pulses into an internal register called the counter. When the counter overflows, then the timer raises the interrupt flag. If interrupts are active, then the microcontroller stops the main thread and executes the interrupt routine, to perform whatever action is needed.

If the source is the internal clock, then the pulses are regular, the counter will overflow at equal intervals: it actually behaves as a timer.

If the source is external, then pulses may not be regular. This is often by design; for example pulses could be generated by cars passing in front of a sensor. In this case, as the previous, the timer counts the pulses and eventually overflows. But the overflow is not regular any more.

To reflect this difference, timer is called a counter when source is external.

diagram of a timer / counter


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