Using the 8254 Timer-Counter Understanding the role of the system’s 8254 programmable Interval-Timer/Counter.

Slides:



Advertisements
Similar presentations
1 Homework Reading –Intel 8254 Programmable Interval Timer (PIT) Data Sheet Machine Projects –Continue on MP3 Labs –Continue in labs with your assigned.
Advertisements

Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54 Timer 2 Port (A,B), No Bidirectional.
Programmable Interval Timer
Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati.
8253/54 Timer Section /54 Timer Description and Initialization
Using the 8254 Timer-Counter Understanding the role of the system’s 8254 programmable Interval-Timer/Counter.
1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
Multiprocessor Initialization
Department of Computer Science and Software Engineering
Using the 8254 Timer-Counter
Outline  Examine some of the H/W supplied with a typical PC and consider the software required to control it.  Introduce Commkit, a software tool that.
Multiprocessor Initialization
Railway Foundation Electronic, Electrical and Processor Engineering.
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Chapter 19 Fundamental PLC Programming
Lecture – 5 Assembly Language Programming
The 8051 Microcontroller architecture
Lecture 9. - Synchronous Devices require a timing signal. Clock generated Interval Timer Microprocessor Interval Timer Clk PCLK = MHz PCLK (for.
Revised: Aug 1, ECE 263 Embedded System Design Lesson 1 68HC12 Overview.
8254 Programmable Interval Timer
ENEE 440 Chapter Timer 8254 Register Select The 8254 timer is actually 3 timers in one. It is an upgraded version of the 8253 timer which was.
Engineering 4862 Microprocessors Lecture 27 Cheng Li EN-4012
Dec Hex Bin 13 D ORG ; THIRTEEN 8253/54 Timer.
8253 TIMER. Engr 4862 Microprocessors 8253 / 8254 Timer A.k.a. PIT (programmable Interval Timer), used to bring down the frequency to the desired level.
PIT: Programmable Interval Timer
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Machine Instruction Characteristics
8254 SOFTWARE PROGRAMMABLE TIMER/COUNTER
The 8253 Programmable Interval Timer
PIT Programming Examples Working with the modes of PIT.
Timers.
Advanced Microprocessor1 I/O Interface Programmable Interval Timer: 8254 Three independent 16-bit programmable counters (timers). Each capable in counting.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
ECE291 Computer Engineering II Lecture 12 Josh Potts University of Illinois at Urbana- Champaign.
Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register.
8051 Micro controller. Architecture of 8051 Features of 8051.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
University of Tehran 1 Microprocessor System Design Timers Omid Fatemi
Arithmetic Flags and Instructions
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Computer Organization CSC 405 (VSC) Very Simple Computer.
Computer Architecture Lecture 32 Fasih ur Rehman.
8254 Timer.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Overview von Neumann Architecture Computer component Computer function
Arithmetic and Logic Instructions
Chapter 3 : Top Level View of Computer Functions Basic CPU function, Interconnection, Instruction Format and Interrupt.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
ECE291 Computer Engineering II Lecture 16 Josh Potts University of Illinois at Urbana- Champaign.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
8086 – I/O Interfacing - I/O mapped I/O
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
BITS Pilani Pilani Campus Pawan Sharma ES C263 Microprocessor Programming and Interfacing.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Basic Computer Organization and Design
Lecture – 5 Assembly Language Programming
Data Transfers, Addressing, and Arithmetic
8253 / 8254 Timer A.k.a. PIT (programmable Interval Timer), used to bring down the frequency to the desired level Three counters inside 8253/8254. Each.
Homework Reading Machine Projects Labs
8086 Microprocessor.
Programmable Interval Timer
Programmable Interval Timer
X86’s instruction sets.
Introduction to Assembly Language
8254 Timer and Counter (8254 IC).
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
Chapter 5: Arithmetic and Logic Instructions
Presentation transcript:

Using the 8254 Timer-Counter Understanding the role of the system’s 8254 programmable Interval-Timer/Counter

The 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 purposes

Displaying ‘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 terminal

Where’s the ‘tick’ counter? main memory Interrupt Vector Table (for real-mode) ROM-BIOS DATA AREA tick_count 0040:006C 0x x x00500 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 zero mov%ax, %fs# using FS register mov%fs:0x046C, %eax# copy tick-count to EAX mov%eax, total_ticks# save in a local variable segment-override prefix (segment used would be %ds)

Converting ‘ticks’ to seconds total_seconds_today = total_ticks_today number of ticks-per-second The number of ‘ticks-per-second’ is based upon the way the PC’s timing hardware has been programmed

Input/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 programmed

Three timer/counter ‘channels’ Channel 0 Channel 1 Channel PIT 8284 PCLK +5 V CLK0 CLK1 CLK2 GATE0 GATE1 GATE2 OUT0 OUT1 OUT2 Interrupt IRQ0 DRAM refresh speaker Port 0x61, bit #0 Port 0x61, bit #1 AND Port 0x61, bit #5 Port 0x61, bit # Hz

Controlling timer-channel 2 r/o r/w I/O port 0x61 (aka ‘Port_B’) OUT2 status OUT1 status SPKR control GATE2 control RAM parity error I/O channel error RAM parity checking enabled I/O channel checking enabled

Counter decrements when pulsed OUT CLK GATE LSB STATUS MSB LSBMSB LATCH REGISTER COUNT REGISTER TIMER/COUNTER CHANNEL

8254 Command-Port Channel-ID 00 = chn 0 01 = chn 1 10 = chn 2 Command-ID 00 = Latch 01 = LSB r/w 10 = MSB r/w 11 = LSB-MSB r/w Output Mode 000 = one-shot level 001 = retriggerable 010 = rate-generator 011 = square-wave 100 = software strobe 101 = hardware strobe Counting Mode 0 = binary 1 = BCD CHANNELOUTPUT MODECOMMAND binary / BCD Commands are sent to the 8254 via io/port 0x43

Programming 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 2

A 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., / 100 = 11932) We specify the ‘one-shot’ counting mode

Code for the 10ms delay # enable Timer Channel 2 in$0x61, %al and$0x0C, %al or$0x01, %al out%al, $0x61 # program Channel 2 for “one-shot” countdown mov$0xB0, %al out%al, $0x43 # write Channel 2 Latch-Register (LSB/MSB) mov$11932, %ax out%al, $0x42 mov%ah, %al out%al, $0x42 # delay until OUT2 signal is activated (bit 5) poll:in$0x61, %al test$0x20, %al jzpoll # disable Timer Channel 2 in$0x61, %al and$0x0C, %al out%al, $0x61

Standard 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 = / (approximately 18.2)

Consequently… To compute ‘total_seconds’ from ‘total_ticks’: total_seconds = total_ticks / ticks_per_second = total_ticks / ( / 65536) = ( total_ticks * ) / We can use the x86 CPU’s integer-arithmetic instructions MUL (multiply) and DIV (divide)

How ‘MUL’ works EAX reg (or mem) EDXEAX 64-bit product multiplicand (32-bits) multiplier (32-bits) Before executing the MUL instruction… 32-bit operands After executing the MUL instruction… product (64-bits) mull reg_or_mem Here’s the instruction…

How ‘DIV’ works EDXEAX 64-bit dividend Before executing the DIV instruction… dividend (64-bits) reg (or mem) divisor (32-bits) 32-bit operand divl reg_or_mem Here’s the instruction… EDXEAX 32-bit remainder After executing the DIV instruction… two results (32-bits) 32-bit quotient

Implementing the conversion So use MUL and DIV to convert ‘ticks’ into ‘seconds’, like this: # total_seconds = ( total_ticks * FREQ_DIVISOR ) / PULSES_PER_SEC movtotal_ticks, %eax mov$FREQ_DIVISOR, %ecx mul%ecx mov$PULSES_PER_SEC, %ecx div%ecx mov%eax, total_seconds # Now integer-quotient is in EAX, and integer-remainder is in EDX

‘Time-Of-Day’ Format HH:MM:SS am/pm hours minutes seconds morning or afternoon So we need to compute four numerical values from the ‘total_seconds’ integer

Our four time-parameters We use these arithmetical ideas: –total_minutes = ( total_seconds / 60 ); ss = ( total_seconds % 60 ); –total_hours = (total_minutes / 60 ); mm = ( total_minutes % 60 ); –total_halfdays = (total_hours / 12 ); hh = (total_hours % 12 ); –Total_days = ( total_halfdays / 2 ); xm = total_halfdays % 2;

A subtle refinement Our ‘total_seconds’ value was gotten with an integer-division operation, so there’s likely to be some ‘round-off’ error How can we be sure we use the ‘closest’ integer to the actual quotient? We should remember the ‘rounding’ rule! When ‘remainder’ is equal or greater than 1/2 of ‘divisor’, ‘quotient’ gets incremented

How to implement rounding? There is more than one way to do it – i.e., the “amateur’s” way or the “expert’s” way Knowledge of the CPU’s architecture and instruction-set can assist The ‘obvious’ method: if ( 2 * remainder >= divisor ) ++quotient; But this uses a multiply and a conditional jump-instruction (inefficient!)

Avoiding inefficiency… Replace the ‘multiply’ with an ‘addition’ Use ‘subtract’ and ‘add-with-carry’ instead of using ‘compare’ and ‘conditionally-jump’ # Recall: quotient was in EAX, remainder was in EDX, divisor was in ECX add%edx, %edx# doubles the remainder sub%ecx, %edx# computes: 2*quotient – divisor # now carry-flag is clear in case 2*quotient >= divisor cmc# complement the carry-flag bit # now carry-flag is set in case 2*quotient >= divisor adc$0, %eax# add the carry-flag to the quotient # So this achieves the same effect as the ‘rounding rule’, but wit no jump!

In-class exercise Can you enhance our ‘timeoday.s’ demo to make it more dramatic (and later useful) by creating a loop within its ‘main’ routine, so that it continues to read and display the time (until the user presses a key)? HINTS: Use an INT-0x16 keyboard service to ‘peek’ into the keyboard-queue, and omit the ‘\n’ (newline) control-code from the ‘report’ message-string