eli5: At the most basic level, how is a computer programmed to know how long a unit of time is?

877 views

eli5: At the most basic level, how is a computer programmed to know how long a unit of time is?

In: 2404

39 Answers

Anonymous 0 Comments

>how is a computer programmed to know how long a unit of time is?

It’s the exact opposite, because no “programming” is needed. Just like people have a [Circadian Rhythm](https://en.wikipedia.org/wiki/Circadian_rhythm), computers have internal clocks too. Every instruction the computer executes takes a [specific number of clock cycles](http://6502.org/users/obelisk/6502/reference.html#LDA).

Very rarely, you can use this fact directly in code to make small delays. But most of the time it’s way too hard to count the instructions (and all the various paths that the code can take), so nearly every CPU comes with a register that [counts clock pulses](http://bauhausinteraction.org/opl/arduino-techniques-getting-rid-of-delays/) for you. You can read that to figure out when to do something, or set it to interrupt you every so often (usually a few milliseconds). This interrupt is often called a [tick](https://superuser.com/questions/101183/what-is-a-cpu-tick). Instead of “you run a program and it takes up the whole computer until it’s done”, it allow the computer to “look like” it was running many programs. But each one was only running for a small slice of time, then the others were running, making them “look” like they were all running at once. (Today’s computers still do that, but they also have many CPUs, so often many programs are running at once.)

Anonymous 0 Comments

>how is a computer programmed to know how long a unit of time is?

It’s the exact opposite, because no “programming” is needed. Just like people have a [Circadian Rhythm](https://en.wikipedia.org/wiki/Circadian_rhythm), computers have internal clocks too. Every instruction the computer executes takes a [specific number of clock cycles](http://6502.org/users/obelisk/6502/reference.html#LDA).

Very rarely, you can use this fact directly in code to make small delays. But most of the time it’s way too hard to count the instructions (and all the various paths that the code can take), so nearly every CPU comes with a register that [counts clock pulses](http://bauhausinteraction.org/opl/arduino-techniques-getting-rid-of-delays/) for you. You can read that to figure out when to do something, or set it to interrupt you every so often (usually a few milliseconds). This interrupt is often called a [tick](https://superuser.com/questions/101183/what-is-a-cpu-tick). Instead of “you run a program and it takes up the whole computer until it’s done”, it allow the computer to “look like” it was running many programs. But each one was only running for a small slice of time, then the others were running, making them “look” like they were all running at once. (Today’s computers still do that, but they also have many CPUs, so often many programs are running at once.)

Anonymous 0 Comments

>how is a computer programmed to know how long a unit of time is?

It’s the exact opposite, because no “programming” is needed. Just like people have a [Circadian Rhythm](https://en.wikipedia.org/wiki/Circadian_rhythm), computers have internal clocks too. Every instruction the computer executes takes a [specific number of clock cycles](http://6502.org/users/obelisk/6502/reference.html#LDA).

Very rarely, you can use this fact directly in code to make small delays. But most of the time it’s way too hard to count the instructions (and all the various paths that the code can take), so nearly every CPU comes with a register that [counts clock pulses](http://bauhausinteraction.org/opl/arduino-techniques-getting-rid-of-delays/) for you. You can read that to figure out when to do something, or set it to interrupt you every so often (usually a few milliseconds). This interrupt is often called a [tick](https://superuser.com/questions/101183/what-is-a-cpu-tick). Instead of “you run a program and it takes up the whole computer until it’s done”, it allow the computer to “look like” it was running many programs. But each one was only running for a small slice of time, then the others were running, making them “look” like they were all running at once. (Today’s computers still do that, but they also have many CPUs, so often many programs are running at once.)

Anonymous 0 Comments

its not programmed per se to understand units of time….thats part of what you have to supply to it. all computers have a timebase, typically a crystal oscillator installed. they basically operate on “clock cycles” you can provide it with the data on how fast the clock is operating at and then it will know about the passage of time, by counting clock pulses and translating that with the info provided on how long a clock pulse is

Anonymous 0 Comments

Adding to all the comments, that is how digital watches work too. Oscillating quartz crystals and particular 2^n frequency that can be used to count via digital logic and then display the time.

Anonymous 0 Comments

its not programmed per se to understand units of time….thats part of what you have to supply to it. all computers have a timebase, typically a crystal oscillator installed. they basically operate on “clock cycles” you can provide it with the data on how fast the clock is operating at and then it will know about the passage of time, by counting clock pulses and translating that with the info provided on how long a clock pulse is

Anonymous 0 Comments

its not programmed per se to understand units of time….thats part of what you have to supply to it. all computers have a timebase, typically a crystal oscillator installed. they basically operate on “clock cycles” you can provide it with the data on how fast the clock is operating at and then it will know about the passage of time, by counting clock pulses and translating that with the info provided on how long a clock pulse is

Anonymous 0 Comments

Adding to all the comments, that is how digital watches work too. Oscillating quartz crystals and particular 2^n frequency that can be used to count via digital logic and then display the time.

Anonymous 0 Comments

Adding to all the comments, that is how digital watches work too. Oscillating quartz crystals and particular 2^n frequency that can be used to count via digital logic and then display the time.