Search code examples
timerhardwarecpuclock

Is there a timer in the CPU?


We use timers in our code; I am just curious about the real implementation of it. Is there a timer in the CPU logic circuit or outside the CPU die – for example, an external clock or anything like that?

If not, then where is the timer? No need for any detailed explanation on how a hardware timer is made, just focus on locating the timer on the hardware board we have.


Solution

  • There are many different types of clocks and timers in computer hardware. All basic computers will have a crystal like a digital watch which is used to synchronise the CPU and forms the "clock speed" in Hz.

    Most CPUs have a number of timers built into them which use the clock speed to calculate the relative time between two points. This allows system programmers to set a timer that will "go off" in a certain number of clock cycles of the crystal. The timer alerts the CPU that the defined time has elapsed by raising an interrupt line, which the programmer attaches a piece of code to.

    Operating Systems and programming languages usually abstract the interrupt timers so you don't have to work directly with them.

    Most advanced computers like PCs have a Real Time Clock which can store the actual calendar time and date but is not often used for timing operations.

    In answer to your question:

    locating the timer on the hardware board we have

    it's very dependant on your hardware and which timer you're interested in. You won't be able to physically see most timers or clocks but the crystal is often easy to find and looks like a small metal capsule - See http://www.electronicrepairguide.com/how-to-test-crystal.html