Unformatted text preview:

Using the 8254 Timer-CounterThe 8254 PITDisplaying ‘Time-Of-Day’Where’s the ‘tick’ counter?Getting the ‘tick’ countConverting ‘ticks’ to secondsInput/Output frequenciesThree timer/counter ‘channels’Controlling timer-channel 2Counter decrements when pulsed8254 Command-PortProgramming a PIT channelA ten-millisecond delayCode for the 10ms delayStandard BIOS programmingConsequently…How ‘MUL’ worksHow ‘DIV’ worksImplementing the conversion‘Time-Of-Day’ FormatOur four time-parametersA subtle refinementHow to implement rounding?Avoiding inefficiency…In-class exerciseUsing the 8254 Timer-CounterUnderstanding the role of the system’s 8254 programmable Interval-Timer/CounterThe 8254 PIT•The 8254 Programmable Interval-timer is used by the PC system for (1) generating timer-tick interrupts (rate is 18.2 per sec), (2) performing dynamic memory-refresh (reads ram once every 15 microseconds), and (3) generates ‘beeps’ of PC speaker•When the speaker-function isn’t needed, the 8254 is available for other purposesDisplaying ‘Time-Of-Day’•Algorithm steps:–Get the count of timer-interrupts so far today–Convert these ‘timer-ticks’ into seconds–Breakdown the total number of seconds today into Hours, Minutes, Seconds, and AM/PM–Convert numerical values into digit-strings–Output these results to the video terminalWhere’s the ‘tick’ counter?main memoryInterrupt Vector Table(for real-mode)ROM-BIOS DATA AREAtick_count0040:006C0x000000x004000x00500 Number of timer-tick interrupts so far today (longword at 0x0046C)Getting the ‘tick’ count•The ROM-BIOS interrupt-handler for the timer interrupt stores the tick-count as a 32-bit integer located at address 0x046C (it’s in the ROM-BIOS DATA AREA)•In real-mode, we can get it like this:xor %ax, %ax # address segment zeromov %ax, %fs # using FS registermov %fs:0x046C, %eax # copy tick-count to EAXmov %eax, total_ticks # save in a local variable segment-override prefix (segment used would be %ds)Converting ‘ticks’ to secondstotal_seconds_today = total_ticks_today number of ticks-per-secondThe number of ‘ticks-per-second’ is based upon the way the PC’s timing hardware has been programmedInput/Output frequencies•The input-pulses to each Timer-channel is a long established PC standard, based on the design of the chrystal oscillator chip:1,193,182 pulses-per-second (Hertz)•The frequency of the output-pulses from any Timer-channel is determined by how that channel’s Latch was programmedThree timer/counter ‘channels’Channel 0Channel 1Channel 28254 PIT8284PCLK+5 VCLK0CLK1CLK2GATE0GATE1GATE2OUT0OUT1OUT2Interrupt IRQ0DRAM refreshspeakerPort 0x61, bit #0Port 0x61, bit #1ANDPort 0x61, bit #5Port 0x61, bit #41193182 HzControlling timer-channel 2r/o r/o r/o r/o r/w r/w r/w r/w 7 6 5 4 3 2 1 0 I/O port 0x61 (aka ‘Port_B’) OUT2status OUT1status SPKRcontrolGATE2controlRAMparityerror I/Ochannel error RAM paritychecking enabled I/O channelchecking enabledCounter decrements when pulsedOUTCLKGATELSBSTATUSMSBLSBMSBLATCH REGISTERCOUNT REGISTERTIMER/COUNTER CHANNEL8254 Command-PortChannel-ID 00 = chn 0 01 = chn 1 10 = chn 2Command-ID 00 = Latch 01 = LSB r/w 10 = MSB r/w 11 = LSB-MSB r/wOutput Mode 000 = one-shot level 001 = retriggerable 010 = rate-generator 011 = square-wave 100 = software strobe 101 = hardware strobeCounting Mode 0 = binary 1 = BCD7 6 5 4 3 2 1 0CHANNEL OUTPUT MODECOMMANDbinary/ BCDCommands are sent to the 8254 via io/port 0x43Programming a PIT channel•Step 1: send command to PIT (port 0x43)•Step 2: read or write the channel’s Latch – via port 0x40 for channel 0– via port 0x41 for channel 1– via port 0x42 for channel 2A ten-millisecond delay•In future lessons we will want to create a time-delay of ten-milliseconds (allowing some hardware to finish its initialization)•We can do it using the Timer Channel 2•We program its ‘Latch Register’ with the Timer Input-Pulse Frequency, multiplied by 1/100 (i.e., 1193182 / 100 = 11932)•We specify the ‘one-shot’ counting modeCode for the 10ms delay# enable Timer Channel 2in $0x61, %aland $0x0C, %alor $0x01, %alout %al, $0x61# program Channel 2 for “one-shot” countdownmov $0xB0, %alout %al, $0x43# write Channel 2 Latch-Register (LSB/MSB)mov $11932, %axout %al, $0x42mov %ah, %alout %al, $0x42# delay until OUT2 signal is activated (bit 5) poll: in $0x61, %altest $0x20, %aljz poll# disable Timer Channel 2in $0x61, %aland $0x0C, %alout %al, $0x61Standard BIOS programming•For Channel 0 (the ‘timer-tick’ interrupt) the Latch is programmed during system startup with a value of zero •But the Timer interprets zero as 65,536•So the frequency of the output-pulses from Timer-channel 0 is equal to this quotient: output-frequency = input-frequency / frequency-divisor = 1193182 / 65536 (approximately 18.2)Consequently…•To compute ‘total_seconds’ from ‘total_ticks’:total_seconds = total_ticks / ticks_per_second= total_ticks / (1193182 / 65536)= ( total_ticks * 65536 ) / 1193183 •We can use the x86 CPU’s integer-arithmetic instructions MUL (multiply) and DIV (divide)How ‘MUL’ worksEAXreg (or mem)EDX EAX64-bit product multiplicand (32-bits) multiplier (32-bits)Before executing the MUL instruction…32-bit operandsAfter executing the MUL instruction… product (64-bits) mull reg_or_mem Here’s the instruction…How ‘DIV’ worksEDX EAX64-bit dividendBefore executing the DIV instruction… dividend (64-bits)reg (or mem) divisor (32-bits)32-bit operand divl reg_or_mem Here’s the instruction…EDX EAX32-bit remainderAfter executing the DIV instruction… two results (32-bits)32-bit quotientImplementing the conversion•So use MUL and DIV to convert ‘ticks’ into ‘seconds’, like this:# total_seconds = ( total_ticks * FREQ_DIVISOR ) / PULSES_PER_SECmov total_ticks, %eaxmov $FREQ_DIVISOR, %ecxmul %ecxmov $PULSES_PER_SEC, %ecxdiv %ecxmov %eax, total_seconds# Now integer-quotient is in EAX, and integer-remainder is in EDX‘Time-Of-Day’ FormatHH:MM:SS am/pm hoursminutes seconds morning or afternoonSo we need to compute four numerical values from the ‘total_seconds’ integerOur four time-parametersWe use these arithmetical ideas:–total_minutes = ( total_seconds / 60 ); ss = ( total_seconds % 60 );–total_hours = (total_minutes /


View Full Document

USF CS 630 - Using the 8254 Timer-Counter

Documents in this Course
Load more
Download Using the 8254 Timer-Counter
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Using the 8254 Timer-Counter and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Using the 8254 Timer-Counter 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?