What is the exact input frequency of the 8253 timer chip on a PC?
Many books say that the output frequency of timer #0 of the 8253 on a PC is 18.2 times per second (triggering once every 55ms), but all say this is only an approximate value, and the exact value has a long string of decimals. Computers should rely on integer operations, and those decimal values should just be the result of converting to real time. So I wanted to know the exact frequency, so I looked up a lot of materials, and it turned out that there were some differences:
1. The exact value (counter #0) as said in many books:
F: 18.2064819336 times per second
T: once every 54.925ms.
2. Terrv Dettmann's "DOS Programmer's Reference":
H: The system clock is called about 18.2 times per second (65536 times per hour).
D: The 00h function of int 1Ah: This interrupt obtains the system clock counter, which starts from zero and counts 18.2065 times per second. The total number of counts in a full day (from midnight) is 1573040 counts, and the elapsed time is 86399.9129 seconds.
3. Mazid's "Assembly Language, Design and Interface Technology": The 8284 chip is connected to a 14.31818MHz crystal oscillator source. The Clr pin output is the main frequency of the CPU, memory (system bus) in 8088, divided by 3, 4.772776MHz. PClk is connected to the 8253/54 timer, divided by 6, 2.386383MHz. There is a 72LS175 D flip-flop between the 8284 and the 8253, so the frequency is divided by 2 again, 1.1931817MHz.
4. Some interface technology books say that the frequency period of the crystal oscillator source is 70ns, matching the memory speed.
5. On many computers, the return value of QueryPerformanceFrequency (Win32 API) is 3579545. 3579545 * 4 = 14318180, which matches 3.
Constant Analysis
~~~~~~~~
Now analyze these constants:
The first type, according to the frequency (18.2064819336 times per second)
Crystal oscillator source frequency: 18.2064819336Hz * 65536 * 12 = 14,318,160.0000049152Hz
Period: 1s / 14,318,160.0000049152Hz = 0.000000069841376266200176256402804053989s = 69.841376266200176256402804053989ns
8253 input frequency: 18.2064819336Hz * 65536 = 1,193,180.0000004096Hz
Period: 1s / 1,193,180.0000004096Hz = 0.00000083809651519440211507683364864787s = 838.09651519440211507683364864787ns
Timer #0 output frequency: 18.2064819336Hz
Period: 1s / 18.2064819336Hz = 0.054925493219780337013675369997787s = 54.925493219780337013675369997787ms
Timer #0 triggers 65536 times: (1s / 18.2064819336Hz) * 65536 = 65536s / 18.2064819336Hz = 3599.597123651524166528229048175s
Timer #0 triggers 1573040 times: (1s / 18.2064819336Hz) * 1573040 = 1573040s / 18.2064819336Hz = 86399.997854443261335991904021318s
The first type, according to the period (once every 54.925ms)
Crystal oscillator source frequency: (1s / 54.925ms) * 65536 * 12 = (65536 * 12)s / 0.054925s = 14,318,288.575329995448338643604916Hz
Period: 54.925ms / (65536 * 12) = 0.000000069840749104817708333333333333333s = 69.840749104817708333333333333333ns
8253 input frequency: (1s / 54.925ms) * 65536 = 65536s / 0.054925s = 1,193,190.7146108329540282203004096Hz
Period: 54.925ms / 65536 = 0.0000008380889892578125s = 838.0889892578125ns
Timer #0 output frequency: 1s / 54.925ms = 18.206645425580336822940373236231Hz
Period: 54.925ms
Timer #0 triggers 65536 times: 54.925ms * 65536 = 3599.5648s
Timer #0 triggers 1573040 times: 54.925ms * 1573040 = 86399.222s
The second type, according to the hour (65536 times per hour)
Crystal oscillator source frequency: 1s / (3600s / 65536 / 65536 / 12) = (65536 * 65536 * 12)s / 3600s = 14,316,557.653333333333333333333333Hz
Period: 3600s / 65536 / 65536 / 12 = 3600s / (65536 * 65536 * 12) = 0.000000069849193096160888671875s = 69.849193096160888671875ns
8253 input frequency: 1s / (3600s / 65536 / 65536) = (65536*65536)s / 3600s = 1,193,046.4711111111111111111111111Hz
Period: 3600s / 65536 / 65536 = 3600s / (65536 * 65536) = 0.0000008381903171539306640625s = 838.1903171539306640625ns
Timer #0 output frequency: 1s / (3600s / 65536) = 65536s / 3600s = 18.204444444444444444444444444444Hz
Period: 3600s / 65536 = 0.054931640625s = 54.931640625ms
Timer #0 triggers 65536 times: 3600s
Timer #0 triggers 1573040 times: (3600s / 65536) * 1573040 = (3600s * 1573040) / 65536 = 86409.66796875s
The second type, according to the day (clock counts 1573040 times, elapsed time is 86399.9129 seconds)
Crystal oscillator source frequency: 1s / (86399.9129s / 1573040 / 65536 / 12) = (1573040 * 65536 * 12)s / 86399.9129s = 14,318,174.078622248240715529702808Hz
Period: 86399.9129s / 1573040 / 65536 / 12 = 86399.9129s / (1573040 * 65536 * 12) = 0.000000069841307593336928084579328349353s = 69.841307593336928084579328349353ns
8253 input frequency: 1s / (86399.9129s / 1573040 / 65536) = (1573040 * 65536)s / 86399.9129s = 1,193,181.1732185206867262941419007Hz
Period: 86399.9129s / 1573040 / 65536 = 86399.9129s / (1573040 * 65536) = 0.00000083809569112004313701495194019224s = 838.09569112004313701495194019224ns
Timer #0 output frequency: 1s / (86399.9129s / 1573040) = 1573040s / 86399.9129s = 18.206499835487681377049165983592Hz
Period: 86399.9129s / 1573040 = 0.054925439213243147027411890352439s = 54.925439213243147027411890352439ms
Timer #0 triggers 65536 times: (86399.9129s / 1573040) * 65536Hz = (86399.9129s * 65536) / 1573040 = 3599.5935842791028835884656461374s
Timer #0 triggers 1573040 times: 86399.9129s
The third type (8284 chip connected to a 14.31818MHz crystal oscillator source)
Crystal oscillator source frequency: 14.31818MHz = 14,318,180Hz
Period: 1s / 14,318,180Hz = 0.000000069841278710003645714748662190306s = 69.841278710003645714748662190306ns
8253 input frequency: 14,318,180Hz / 12 = 1,193,181.6666666666666666666666667Hz
Period: 1s / (14,318,180Hz / 12) = 12s / 14,318,180Hz = 0.00000083809534452004374857698394628368s = 838.09534452004374857698394628368ns
Timer #0 output frequency: 14,318,180Hz / 12 / 65536 = 14,318,180Hz / (12 * 65536) = 18.206507364908854166666666666667Hz
Period: 1s / (14,318,180Hz / 12 / 65536) = (12 * 65536)s / 14,318,180Hz = 0.054925416498465587106741219903647s = 54.925416498465587106741219903647ms
Timer #0 triggers 65536 times: (1s / (14,318,180Hz / 12 / 65536)) * 65536 = (12 * 65536 * 65536)s / 14,318,180Hz = 3599.5920956434407166273925876054s
Timer #0 triggers 1573040 times: (1s / (14,318,180Hz / 12 / 65536)) * 1573040 = (12 * 65536 * 1573040)s / 14,318,180Hz = 86399.877168746307142388208557233s
The fourth type (the frequency period of the crystal oscillator source is 70ns, matching the memory speed)
Crystal oscillator source frequency: 1s / 0.00000007s = 14,285,714.285714285714285714285714Hz
Period: 70ns = 0.00000007s
8253 input frequency: 1s / (0.00000007s * 12) = 1,190,476.1904761904761904761904762Hz
Period: 0.00000007s * 12 = 0.00000084s = 840ns
Timer #0 output frequency: 1s / (0.00000007s * 12 * 65536) = 18.165225074404761904761904761905Hz
Period: 0.00000007s * 12 * 65536 = 0.05505024s = 55.05024ms
Timer #0 triggers 65536 times: (0.00000007s * 12 * 65536) * 65536 = 3607.77252864s
Timer #0 triggers 1573040 times: (0.00000007s * 12 * 65536) * 1573040 = 86596.2295296s
Total Table
~~~~
Crystal oscillator source frequency (Hz):
1F: 14,318,160.0000049152
1T: 14,318,288.575329995448338643604916
2H: 14,316,557.653333333333333333333333
2D: 14,318,174.078622248240715529702808
3 : 14,318,180
4 : 14,285,714.285714285714285714285714
Crystal oscillator source period (ns):
1F: 69.841376266200176256402804053989
1T: 69.840749104817708333333333333333
2H: 69.849193096160888671875
2D: 69.841307593336928084579328349353
3 : 69.841278710003645714748662190306
4 : 70
8253 input frequency (Hz):
1F: 1,193,180.0000004096
1T: 1,193,190.7146108329540282203004096
2H: 1,193,046.4711111111111111111111111
2D: 1,193,181.1732185206867262941419007
3 : 1,193,181.6666666666666666666666667
4 : 1,190,476.1904761904761904761904762
8253 input period (ns):
1F: 838.09651519440211507683364864787
1T: 838.0889892578125
2H: 838.1903171539306640625
2D: 838.09569112004313701495194019224
3 : 838.09534452004374857698394628368
4 : 840
Timer #0 output frequency (Hz):
1F: 18.2064819336
1T: 18.206645425580336822940373236231
2H: 18.204444444444444444444444444444
2D: 18.206499835487681377049165983592
3 : 18.206507364908854166666666666667
4 : 18.165225074404761904761904761905
Timer #0 output period (ms):
1F: 54.925493219780337013675369997787
1T: 54.925
2H: 54.931640625
2D: 54.925439213243147027411890352439
3 : 54.925416498465587106741219903647
4 : 55.05024
Timer #0 triggers 65536 times (s):
1F: 3599.597123651524166528229048175
1T: 3599.5648
2H: 3600
2D: 3599.5935842791028835884656461374
3 : 3599.5920956434407166273925876054
4 : 3607.77252864
Timer #0 triggers 1573040 times (s):
1F: 86399.997854443261335991904021318
1T: 86399.222
2H: 86409.66796875
2D: 86399.9129
3 : 86399.877168746307142388208557233
4 : 86596.2295296
Conclusion
~~~~
Personally, I think the statement in "Assembly Language, Design and Interface Technology" is the most credible, with a crystal oscillator source frequency of 14,318,180Hz, because it matches many numbers.
PS: I have always had this question, but I never studied it. Until a few days ago, I saw an article by Fengyun "Not Very Accurate Clock" (http://blog.codingnow.com/2006/05/iaeeoeo.html) and then realized the seriousness of this problem, which caught my attention.
[ Last edited by zyl910 on 2006-6-3 at 12:44 ]
Many books say that the output frequency of timer #0 of the 8253 on a PC is 18.2 times per second (triggering once every 55ms), but all say this is only an approximate value, and the exact value has a long string of decimals. Computers should rely on integer operations, and those decimal values should just be the result of converting to real time. So I wanted to know the exact frequency, so I looked up a lot of materials, and it turned out that there were some differences:
1. The exact value (counter #0) as said in many books:
F: 18.2064819336 times per second
T: once every 54.925ms.
2. Terrv Dettmann's "DOS Programmer's Reference":
H: The system clock is called about 18.2 times per second (65536 times per hour).
D: The 00h function of int 1Ah: This interrupt obtains the system clock counter, which starts from zero and counts 18.2065 times per second. The total number of counts in a full day (from midnight) is 1573040 counts, and the elapsed time is 86399.9129 seconds.
3. Mazid's "Assembly Language, Design and Interface Technology": The 8284 chip is connected to a 14.31818MHz crystal oscillator source. The Clr pin output is the main frequency of the CPU, memory (system bus) in 8088, divided by 3, 4.772776MHz. PClk is connected to the 8253/54 timer, divided by 6, 2.386383MHz. There is a 72LS175 D flip-flop between the 8284 and the 8253, so the frequency is divided by 2 again, 1.1931817MHz.
4. Some interface technology books say that the frequency period of the crystal oscillator source is 70ns, matching the memory speed.
5. On many computers, the return value of QueryPerformanceFrequency (Win32 API) is 3579545. 3579545 * 4 = 14318180, which matches 3.
Constant Analysis
~~~~~~~~
Now analyze these constants:
The first type, according to the frequency (18.2064819336 times per second)
Crystal oscillator source frequency: 18.2064819336Hz * 65536 * 12 = 14,318,160.0000049152Hz
Period: 1s / 14,318,160.0000049152Hz = 0.000000069841376266200176256402804053989s = 69.841376266200176256402804053989ns
8253 input frequency: 18.2064819336Hz * 65536 = 1,193,180.0000004096Hz
Period: 1s / 1,193,180.0000004096Hz = 0.00000083809651519440211507683364864787s = 838.09651519440211507683364864787ns
Timer #0 output frequency: 18.2064819336Hz
Period: 1s / 18.2064819336Hz = 0.054925493219780337013675369997787s = 54.925493219780337013675369997787ms
Timer #0 triggers 65536 times: (1s / 18.2064819336Hz) * 65536 = 65536s / 18.2064819336Hz = 3599.597123651524166528229048175s
Timer #0 triggers 1573040 times: (1s / 18.2064819336Hz) * 1573040 = 1573040s / 18.2064819336Hz = 86399.997854443261335991904021318s
The first type, according to the period (once every 54.925ms)
Crystal oscillator source frequency: (1s / 54.925ms) * 65536 * 12 = (65536 * 12)s / 0.054925s = 14,318,288.575329995448338643604916Hz
Period: 54.925ms / (65536 * 12) = 0.000000069840749104817708333333333333333s = 69.840749104817708333333333333333ns
8253 input frequency: (1s / 54.925ms) * 65536 = 65536s / 0.054925s = 1,193,190.7146108329540282203004096Hz
Period: 54.925ms / 65536 = 0.0000008380889892578125s = 838.0889892578125ns
Timer #0 output frequency: 1s / 54.925ms = 18.206645425580336822940373236231Hz
Period: 54.925ms
Timer #0 triggers 65536 times: 54.925ms * 65536 = 3599.5648s
Timer #0 triggers 1573040 times: 54.925ms * 1573040 = 86399.222s
The second type, according to the hour (65536 times per hour)
Crystal oscillator source frequency: 1s / (3600s / 65536 / 65536 / 12) = (65536 * 65536 * 12)s / 3600s = 14,316,557.653333333333333333333333Hz
Period: 3600s / 65536 / 65536 / 12 = 3600s / (65536 * 65536 * 12) = 0.000000069849193096160888671875s = 69.849193096160888671875ns
8253 input frequency: 1s / (3600s / 65536 / 65536) = (65536*65536)s / 3600s = 1,193,046.4711111111111111111111111Hz
Period: 3600s / 65536 / 65536 = 3600s / (65536 * 65536) = 0.0000008381903171539306640625s = 838.1903171539306640625ns
Timer #0 output frequency: 1s / (3600s / 65536) = 65536s / 3600s = 18.204444444444444444444444444444Hz
Period: 3600s / 65536 = 0.054931640625s = 54.931640625ms
Timer #0 triggers 65536 times: 3600s
Timer #0 triggers 1573040 times: (3600s / 65536) * 1573040 = (3600s * 1573040) / 65536 = 86409.66796875s
The second type, according to the day (clock counts 1573040 times, elapsed time is 86399.9129 seconds)
Crystal oscillator source frequency: 1s / (86399.9129s / 1573040 / 65536 / 12) = (1573040 * 65536 * 12)s / 86399.9129s = 14,318,174.078622248240715529702808Hz
Period: 86399.9129s / 1573040 / 65536 / 12 = 86399.9129s / (1573040 * 65536 * 12) = 0.000000069841307593336928084579328349353s = 69.841307593336928084579328349353ns
8253 input frequency: 1s / (86399.9129s / 1573040 / 65536) = (1573040 * 65536)s / 86399.9129s = 1,193,181.1732185206867262941419007Hz
Period: 86399.9129s / 1573040 / 65536 = 86399.9129s / (1573040 * 65536) = 0.00000083809569112004313701495194019224s = 838.09569112004313701495194019224ns
Timer #0 output frequency: 1s / (86399.9129s / 1573040) = 1573040s / 86399.9129s = 18.206499835487681377049165983592Hz
Period: 86399.9129s / 1573040 = 0.054925439213243147027411890352439s = 54.925439213243147027411890352439ms
Timer #0 triggers 65536 times: (86399.9129s / 1573040) * 65536Hz = (86399.9129s * 65536) / 1573040 = 3599.5935842791028835884656461374s
Timer #0 triggers 1573040 times: 86399.9129s
The third type (8284 chip connected to a 14.31818MHz crystal oscillator source)
Crystal oscillator source frequency: 14.31818MHz = 14,318,180Hz
Period: 1s / 14,318,180Hz = 0.000000069841278710003645714748662190306s = 69.841278710003645714748662190306ns
8253 input frequency: 14,318,180Hz / 12 = 1,193,181.6666666666666666666666667Hz
Period: 1s / (14,318,180Hz / 12) = 12s / 14,318,180Hz = 0.00000083809534452004374857698394628368s = 838.09534452004374857698394628368ns
Timer #0 output frequency: 14,318,180Hz / 12 / 65536 = 14,318,180Hz / (12 * 65536) = 18.206507364908854166666666666667Hz
Period: 1s / (14,318,180Hz / 12 / 65536) = (12 * 65536)s / 14,318,180Hz = 0.054925416498465587106741219903647s = 54.925416498465587106741219903647ms
Timer #0 triggers 65536 times: (1s / (14,318,180Hz / 12 / 65536)) * 65536 = (12 * 65536 * 65536)s / 14,318,180Hz = 3599.5920956434407166273925876054s
Timer #0 triggers 1573040 times: (1s / (14,318,180Hz / 12 / 65536)) * 1573040 = (12 * 65536 * 1573040)s / 14,318,180Hz = 86399.877168746307142388208557233s
The fourth type (the frequency period of the crystal oscillator source is 70ns, matching the memory speed)
Crystal oscillator source frequency: 1s / 0.00000007s = 14,285,714.285714285714285714285714Hz
Period: 70ns = 0.00000007s
8253 input frequency: 1s / (0.00000007s * 12) = 1,190,476.1904761904761904761904762Hz
Period: 0.00000007s * 12 = 0.00000084s = 840ns
Timer #0 output frequency: 1s / (0.00000007s * 12 * 65536) = 18.165225074404761904761904761905Hz
Period: 0.00000007s * 12 * 65536 = 0.05505024s = 55.05024ms
Timer #0 triggers 65536 times: (0.00000007s * 12 * 65536) * 65536 = 3607.77252864s
Timer #0 triggers 1573040 times: (0.00000007s * 12 * 65536) * 1573040 = 86596.2295296s
Total Table
~~~~
Crystal oscillator source frequency (Hz):
1F: 14,318,160.0000049152
1T: 14,318,288.575329995448338643604916
2H: 14,316,557.653333333333333333333333
2D: 14,318,174.078622248240715529702808
3 : 14,318,180
4 : 14,285,714.285714285714285714285714
Crystal oscillator source period (ns):
1F: 69.841376266200176256402804053989
1T: 69.840749104817708333333333333333
2H: 69.849193096160888671875
2D: 69.841307593336928084579328349353
3 : 69.841278710003645714748662190306
4 : 70
8253 input frequency (Hz):
1F: 1,193,180.0000004096
1T: 1,193,190.7146108329540282203004096
2H: 1,193,046.4711111111111111111111111
2D: 1,193,181.1732185206867262941419007
3 : 1,193,181.6666666666666666666666667
4 : 1,190,476.1904761904761904761904762
8253 input period (ns):
1F: 838.09651519440211507683364864787
1T: 838.0889892578125
2H: 838.1903171539306640625
2D: 838.09569112004313701495194019224
3 : 838.09534452004374857698394628368
4 : 840
Timer #0 output frequency (Hz):
1F: 18.2064819336
1T: 18.206645425580336822940373236231
2H: 18.204444444444444444444444444444
2D: 18.206499835487681377049165983592
3 : 18.206507364908854166666666666667
4 : 18.165225074404761904761904761905
Timer #0 output period (ms):
1F: 54.925493219780337013675369997787
1T: 54.925
2H: 54.931640625
2D: 54.925439213243147027411890352439
3 : 54.925416498465587106741219903647
4 : 55.05024
Timer #0 triggers 65536 times (s):
1F: 3599.597123651524166528229048175
1T: 3599.5648
2H: 3600
2D: 3599.5935842791028835884656461374
3 : 3599.5920956434407166273925876054
4 : 3607.77252864
Timer #0 triggers 1573040 times (s):
1F: 86399.997854443261335991904021318
1T: 86399.222
2H: 86409.66796875
2D: 86399.9129
3 : 86399.877168746307142388208557233
4 : 86596.2295296
Conclusion
~~~~
Personally, I think the statement in "Assembly Language, Design and Interface Technology" is the most credible, with a crystal oscillator source frequency of 14,318,180Hz, because it matches many numbers.
PS: I have always had this question, but I never studied it. Until a few days ago, I saw an article by Fengyun "Not Very Accurate Clock" (http://blog.codingnow.com/2006/05/iaeeoeo.html) and then realized the seriousness of this problem, which caught my attention.
[ Last edited by zyl910 on 2006-6-3 at 12:44 ]
人类存在的目的就是试图理解人类为何存在

