{"id":338,"date":"2015-07-24T06:13:18","date_gmt":"2015-07-24T10:13:18","guid":{"rendered":"http:\/\/72.167.111.237\/wpecsdump\/?page_id=338"},"modified":"2020-12-09T06:22:45","modified_gmt":"2020-12-09T11:22:45","slug":"82538254-pit-programmable-interval-time","status":"publish","type":"page","link":"https:\/\/www.ecsdump.net\/?page_id=338","title":{"rendered":"8253\/8254 PIT &#8211; Programmable Interval Time"},"content":{"rendered":"<p><em>Original source: <a href=\"http:\/\/heim.ifi.uio.no\/~stanisls\/helppc\/8253.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/heim.ifi.uio.no\/~stanisls\/helppc\/8253.html<\/a><\/em><\/p>\n<p>Spec documentation:&nbsp; <a href=\"https:\/\/www.ecsdump.net\/wp-content\/uploads\/2020\/12\/8254.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">8254 PROGRAMMABLE INTERVAL TIMER<\/a><\/p>\n<div class=\"indent\">Port 40h, 8253 Counter 0 Time of Day Clock (normally mode 3)<br \/>\nPort 41h, 8253 Counter 1 RAM Refresh Counter (normally mode 2)<br \/>\nPort 42h, 8253 Counter 2 Cassette and Speaker Functions<br \/>\nPort 43h, 8253 Mode Control Register, data format:<\/div>\n<div class=\"code\">\n<pre>\t|7|6|5|4|3|2|1|0|  Mode Control Register\n\t | | | | | | | `---- 0=16 binary counter, 1=4 decade BCD counter\n\t | | | | `--------- counter mode bits\n\t | | `------------ read\/write\/latch format bits\n\t `--------------- counter select bits (also 8254 read back command)<\/pre>\n<\/div>\n<div class=\"indent\">Bits<br \/>\n76 Counter Select Bits<br \/>\n00 select counter 0<br \/>\n01 select counter 1<br \/>\n10 select counter 2<br \/>\n11 read back command (8254 only, illegal on 8253, see below)<\/div>\n<div class=\"indent\">Bits<br \/>\n54 Read\/Write\/Latch Format Bits<br \/>\n00 latch present counter value<br \/>\n01 read\/write of MSB only<br \/>\n10 read\/write of LSB only<br \/>\n11 read\/write LSB, followed by write of MSB<\/div>\n<div class=\"indent\">Bits<br \/>\n321 Counter Mode Bits<br \/>\n000 mode 0, interrupt on terminal count; countdown, interrupt,<\/p>\n<div class=\"indent\">then wait for a new mode or count; loading a new count in the<br \/>\nmiddle of a count stops the countdown<\/div>\n<p>001 mode 1, programmable one-shot; countdown with optional<\/p>\n<div class=\"indent\">restart; reloading the counter will not affect the countdown<br \/>\nuntil after the following trigger<\/div>\n<p>010 mode 2, rate generator; generate one pulse after &#8216;count&#8217; CLK<\/p>\n<div class=\"indent\">cycles; output remains high until after the new countdown has<br \/>\nbegun; reloading the count mid-period does not take affect<br \/>\nuntil after the period<\/div>\n<p>011 mode 3, square wave rate generator; generate one pulse after<\/p>\n<div class=\"indent\">&#8216;count&#8217; CLK cycles; output remains high until 1\/2 of the next<br \/>\ncountdown; it does this by decrementing by 2 until zero, at<br \/>\nwhich time it lowers the output signal, reloads the counter<br \/>\nand counts down again until interrupting at 0; reloading the<br \/>\ncount mid-period does not take affect until after the period<\/div>\n<p>100 mode 4, software triggered strobe; countdown with output high<\/p>\n<div class=\"indent\">until counter zero; at zero output goes low for one CLK<br \/>\nperiod; countdown is triggered by loading counter; reloading<br \/>\ncounter takes effect on next CLK pulse<\/div>\n<p>101 mode 5, hardware triggered strobe; countdown after triggering<\/p>\n<div class=\"indent\">with output high until counter zero; at zero output goes low<br \/>\nfor one CLK period<\/div>\n<\/div>\n<div class=\"indent\">Read Back Command Format (8254 only)<\/div>\n<div class=\"code\">\n<pre>\t|7|6|5|4|3|2|1|0| Read Back Command (written to Mode Control Reg)\n\t | | | | | | | `--- must be zero\n\t | | | | | | `---- select counter 0\n\t | | | | | `----- select counter 1\n\t | | | | `------ select counter 2\n\t | | | `------- 0 = latch status of selected counters\n\t | | `-------- 0 = latch count of selected counters\n\t `----------- 11 = read back command<\/pre>\n<\/div>\n<div class=\"indent\">Read Back Command Status (8254 only, read from counter register)<\/div>\n<div class=\"code\">\n<pre>\t|7|6|5|4|3|2|1|0|  Read Back Command Status\n\t | | | | | | | `--- 0=16 binary counter, 1=4 decade BCD counter\n\t | | | | `-------- counter mode bits (see Mode Control Reg above)\n\t | | `----------- read\/write\/latch format (see Mode Control Reg)\n\t | `------------ 1=null count (no count set), 0=count available\n\t `------------- state of OUT pin (1=high, 0=low)<\/pre>\n<\/div>\n<ul>\n<li>the 8253 is used on the PC &amp; XT, while the 8254 is used on the AT+<\/li>\n<li>all counters are decrementing and fully independent<\/li>\n<li>the PIT is tied to 3 clock lines all generating 1.19318 MHz.<\/li>\n<li>the value of 1.19318MHz is derived from (4.77\/4 MHz) and has it&#8217;s roots based on NTSC frequencies<\/li>\n<li>counters are 16 bit quantities which are decremented and then tested against zero. Valid range is (0-65535). To get a value<br \/>\nof 65536 clocks you must specify 0 as the default count since<br \/>\n65536 is a 17 bit value.<\/li>\n<li>reading by latching the count doesn&#8217;t disturb the countdown but reading the port directly does; except when using the 8254 Read<br \/>\nBack Command<\/li>\n<li>counter 0 is the time of day interrupt and is generated approximately 18.2 times per sec. The value 18.2 is derived from<br \/>\nthe frequency 1.10318\/65536 (the normal default count).<\/li>\n<li>counter 1 is normally set to 18 (dec.) and signals the 8237 to do a RAM refresh approximately every 15\u00e6s<\/li>\n<li>counter 2 is normally used to generate tones from the speaker but can be used as a regular counter when used in conjunction<br \/>\nwith the 8255<\/li>\n<li>newly loaded counters don&#8217;t take effect until after a an output pulse or input CLK cycle depending on the mode<\/li>\n<li>the 8253 has a max input clock rate of 2.6MHz, the 8254 has max input clock rate of 10MHz<\/li>\n<\/ul>\n<p>Programming considerations:<\/p>\n<p>1. load Mode Control Register<br \/>\n2. let bus settle (jmp $+2)<br \/>\n3. write counter value<br \/>\n4. if counter 0 is modified, an INT 8 handler must be written to<\/p>\n<div class=\"indent\">call the original INT 8 handler every 18.2 seconds. When it<br \/>\ndoes call the original INT 8 handler it must NOT send and EOI<br \/>\nto the 8259 for the timer interrupt, since the original INT 8<br \/>\nhandler will send the EOI also.<\/div>\n<p>Example code:<\/p>\n<div class=\"code\">\n<pre>\tcountdown  equ\t8000h ; approx 36 interrupts per second\n\t   cli\n\t   mov\tal,00110110b  ; bit 7,6 = (00) timer counter 0\n\t\t\t\t  ; bit 5,4 = (11) write LSB then MSB\n\t\t\t\t  ; bit 3-1 = (011) generate square wave\n\t\t\t\t  ; bit 0 = (0) binary counter\n\t   out\t43h,al\t      ; prep PIT, counter 0, square wave&amp;init count\n\t   jmp\t$+2\n\t   mov\tcx,countdown  ; default is 0x0000 (65536) (18.2 per sec)\n\t\t\t\t  ; interrupts when counter decrements to 0\n\t   mov\tal,cl\t      ; send LSB of timer count\n\t   out\t40h,al\n\t   jmp\t$+2\n\t   mov\tal,ch\t      ; send MSB of timer count\n\t   out\t40h,al\n\t   jmp\t$+2\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Original source: http:\/\/heim.ifi.uio.no\/~stanisls\/helppc\/8253.html Spec documentation:&nbsp; 8254 PROGRAMMABLE INTERVAL TIMER Port 40h, 8253 Counter 0 Time of Day Clock (normally mode 3) Port 41h, 8253 Counter 1 RAM Refresh Counter (normally mode 2) Port 42h, 8253 Counter 2 Cassette and Speaker Functions Port 43h, 8253 Mode Control Register, data format: |7|6|5|4|3|2|1|0| Mode Control Register | |&hellip;<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/www.ecsdump.net\/?page_id=338\" title=\"Continue reading &lsquo;8253\/8254 PIT &#8211; Programmable Interval Time&rsquo;\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":683,"menu_order":0,"comment_status":"open","ping_status":"open","template":"page-templates\/full-width.php","meta":{"footnotes":""},"categories":[15,11],"tags":[17,67,30],"wf_page_folders":[69],"class_list":["post-338","page","type-page","status-publish","hentry","category-hardware","category-reference","tag-82538254-pit","tag-hardware","tag-reference"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/pages\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=338"}],"version-history":[{"count":0,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/pages\/338\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=\/wp\/v2\/pages\/683"}],"wp:attachment":[{"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"},{"taxonomy":"wf_page_folders","embeddable":true,"href":"https:\/\/www.ecsdump.net\/index.php?rest_route=%2Fwp%2Fv2%2Fwf_page_folders&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}