Docsity

The Interval Timer-System Programming-Lecture Notes, Study notes of System Programming

Toggle sidebar
bg1
Lecture # 9
The interval timer
-Synchronous Devices require a
timing signal.
Clock
generated
Interval
Timer
Microprocessor
Interval Timer
Clk
Clk
PCLK =1.19318 MHz
PCLK (for peripheral
Synchronous Devices)
Clk Ch0 to IRQ0
CH1 TO DRAM controller
Ch2 to PC Speaker
The interval timer is used to divide an input frequency. The input frequency used by the
interval timer is the PCLK signal generated by the clock generator. The interval timer has
three different each with an individual output and memory for storing the divisor value.
docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download The Interval Timer-System Programming-Lecture Notes and more Study notes System Programming in PDF only on Docsity!

Lecture # 9

The interval timer

  • Synchronous Devices require a timing signal.

Clock generated

Interval Timer

Microprocessor

Interval Timer

Clk

Clk

PCLK =1.19318 MHz

PCLK (for peripheral Synchronous Devices)

Clk

Ch0 to IRQ CH1 TO DRAM controller Ch2 to PC Speaker

The interval timer is used to divide an input frequency. The input frequency used by the

interval timer is the PCLK signal generated by the clock generator. The interval timer has

three different each with an individual output and memory for storing the divisor value.

Dividing Clock signal

Counter Registers:

  • Counter registers can be used to divide frequency.

count

A counter register can be used to divide the clock signal. As shown in the slide above the

but 0 of the clock register is used to divide the clock frequency by 2 subsequently bit 1 is

used to divide it by 4 and so on.

The Division mechanism

0000 0000

0000 0001

0000 0010

0000 0011

0000 0100

0000 0101

0000 0110

0000 0111

Command registers withn the programmable interval timer

Interval Timer Programming:

Command Registers

  • 8-bit Command port
  • Need to be programmed before

loading the divisor value for a

channel.

  • 3 channels, each requires a 16-

bit divisor value to generate the

output frequency.

Command register and the channels need to be programmed for the interval timer to

generate a wanted frequency.

Command Register

Binary = 0

BCD = 1

Mode 0 ~ 5

Ch: 00=

01=Low Byte

10=High Byte

11=Low Byte followed

by High Byte

Command register is an 8 bit register which should be programmed as described in the

slide above before loading the divisor value. It signifies the channel to be programmed,

size of divisor value, the mode in which the channel is to be operated and also whether

the counter is to be used a binary or BCD counter.

Mode Description

Divisor = 4 Mode = 3

Divisor = 4 Mode = 2

Divisor = 4 Mode = 1

Divisor = 4 Mode = 0

The interval timer can operate in six modes. Each mode has a different square wave

pattern according to need of the application. Some modes might be suitable to control a

motor and some might be suitable to control the speaker.

The interval timer has 3 channels each channel is 16 bit wide. The port 43H is an 8 bit

port used as the command register. Ports 40h, 41H and 42H are associated with the

channels o, 1 and 2 respectively. Channels are 16 bit wide whereas the ports are 8 bit

wide. A 16 bit value can be loaded serially through the ports into the register.

Steps for programming the interval timer

Programming Concepts for Interval

Timer:

  • Load the Command byte into

command register required to

program the specific channel.

  • The divisor word is then

Serially loaded byte by byte.

The port 61H

Connect

to interval

timer = 1

Turn ON Speaker = 1 Turn OFF Speaker=

Rest of the bits are used by othe r devices and should not be changed.

61H Port

the port 61h is used to control the speaker only the least significant 2 bits are important.

Bit 0 is used to connect the interval timer to the speaker and the bit #1 is used to turn the

speaker on off. Rest of the bits are used by other devices.

Example

Example:

//Program loads divisor value of 0x21FF

//Turns ON the speaker and connects it to Interval

Timer

#include<BIOS.H>

#include<DOS.H>

void main()

outportb (0x43,0xB4);

outportb (0x42,0xFF);

outportb (0x42,0x21);

outportb (0x61,inportb(0x61) | 3);

getch();

outportb (0x61,inportb(0x61) & 0xFC);

The above programs the interval timer and then turns it on. A value of 0xb4 is loaded into

the command register 0x43. This value signifies that the channel 2 is to programmed,

both the bytes of divisor value are to loaded, the interval timer is to be programmed in

mode 2 and is to be used as a binary counter.

Then the divisor value say 0x21ffH, is loaded serially. First 0xFF low byte and then the

high byte 0x21 is loaded. Both the least significant bits of 0x61 port are set to turn on the

speaker and connect it to the interval timer.

On a key press the speaker is again disconnected and turned off.