Mechatronics Module 3.13 I/O organisation - PowerPoint PPT Presentation

1 / 55
About This Presentation
Title:

Mechatronics Module 3.13 I/O organisation

Description:

peripheral interface adapters made to be compatible with families of mP's ... A nested DO...LOOP awaits for the user to hit a key on the PC keyboard and loops ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 56
Provided by: vesnabruj
Category:

less

Transcript and Presenter's Notes

Title: Mechatronics Module 3.13 I/O organisation


1
Mechatronics Module 3.13I/O organisation
  • Dr Vesna Brujic-Okretic

2
Peripheral Interface Devices
  • peripheral interface adapters made to be
    compatible with families of mPs
  • most common in 80X86 family is 8255 Programmable
    Peripheral Interface (PPI)
  • it is a parallel device, strictly hence, fast
    data transmission
  • a low-cost IC
  • it has 40 pins in total
  • 24 for I/O
  • 8 for data bus

3
PPI (Intel 8255)
  • Programmable Peripheral Interface - simplified
    block diagram

4
PPI
  • 1 read line
  • 1 write line
  • 2 address lines
  • 1 chip select line
  • 1 pin for 5V
  • 1 pin for 0V
  • 1 clock signal
  • can be used either 1 by 1 wire or more complex
  • not all the wires are always active some spares

5
PPI
  • provides 3 ports A, B, C
  • ports A and B are regular ports (8 bits each)
  • port C has 2 sets of 4-bit wide ports
  • the 24 I/O lines are programmable in 2 groups of
    12, designated as
  • Group A and
  • Group B
  • has 3 modes of operation (0,1 and 2)

6
8255 PPI
  • Group A
  • programs port A and 4 most significant bits of
    port C
  • Group B
  • programs port B and 4 least signif. bits of port
    C
  • ports may be configured as either inputs or
    outputs
  • configuration of ports controlled by control
    register
  • registers and ports configured as memory
    locations in the memory map

7
Memory locations
  • This PC Interface Card plugs into any available 8
    or 16-bit slot (also known as an AT-slot) on your
    PC's motherboard, just like a sound card or disk
    drive controller card does.
  • Your CPU (Central Processing Unit) communicates
    with cards by knowing the card's address.
  • From IBM's Technical Reference Manuals, one can
    learn that the motherboard allows for several
    available addresses for any cards you wish to
    plug into a slot.
  • By physically using jumpers on the card, we can
    assign an address to the card. In software, we
    can tell the CPU what this address is

8
Memory locations
  • locations corresponding to the addresses BA
    (basic address), BA1, BA2, BA3 are registers
    (1 control 3 for the ports) in the PPI chip
    itself
  • their addresses however appear in the memory map
  • when address decoder receives such address
    information it generates a chip select signal
    which activates PPI
  • now, inside the PPI, either Read or Write line is
    activated and the state of the 2 address lines
    tell which of the registers is in question

9
Memory locations
  • As mentioned the Control Port is Base Address
    3.
  • Port A is always at Base Address
  • Port B is Base Address 1
  • Port C is Base Address 2.

10
Setting up ports
11
Modes
  • The 8255 allows for three distinct operating
    modes (Modes 0, 1 and 2) as follows
  • Mode 0
  • Ports A and B operate as either inputs or outputs
    and Port C is divided into two 4-bit groups
    either of which can be operated as inputs or
    outputs 0 - most common sets up ports for
    standard I/O applications
  • Mode 1
  • Same as Mode 0 but Port C is used for handshaking
    and control (strobed - like an impulse mode)
  • Mode 2
  • Port A is bidirectional (both input and output)
    and Port C is used for handshaking. Port B is not
    used.
  • on start-up all ports configured as input to
    protect connected equipment

12
Some examples
13
Interfacing a DC Motor
  • This example will describe how you can interface
    a DC motor to your 8255 PC Interface Card. The
    Turbo C code will demonstrate how you can
    implement pulse-width-modulation (PWM) in
    software and control the motor's speed.
  • Many PC hobbyists are interested in interfacing a
    DC motor to their PCs to build a robot or do
    mechanical work by computer control.
  • Such motor control typically means having the PC
    turn the motor on, off, adjusting speed and
    reversing direction.
  • There are many dedicated chips designed for this
    purpose.
  • Allegro makes one called the UDN2993B which has a
    dual H-bridge driver that can handle continuous
    loads up to 30 V and 0.5A.
  • This chip requires no additional hardware and can
    be quickly interfaced to your 8255 PC Interface
    Card.

14
Interfacing an DC Motor
  • The UDN2993B is interfaced to the motor (see
    Figure 16).
  • It only requires an ENABLE and PHASE signals.
  • ENABLE must be a pulse-width-modulated (PWM)
    signal.
  • PWM is a very common, highly efficient method for
    controlling motor speed.
  • To understand PWM think how you ride your
    bicycle. There are times when you pedal
    (on-time), and times when you coast (off-time).
  • When coasting you are using your momentum and are
    not physically exerting energy.

15
Interfacing an DC Motor
  • When you feel (modulation) you are going too slow
    you pedal (pulse) again for some time(width) and
    then coast again. This pedal-coast-pedal cycle is
    called PWM.
  • The amount of time you pedal is called the
    on-time.
  • The amount of time you coast is called the
    off-time.
  • The total time is the sum of on-time and
    off-time.
  • PWM signals are described by a duty cycle (D.C.)
    percentage.
  • The duty cycle is the ratio of the on-time and
    total time.
  • For example, a 100 D.C. means that the motor is
    receiving energy (you are pedalling) all the
    time. A 50 D.C. means that the motor receives
    energy (pedalling) only half the time (coasting
    half the time).
  • Typically motor speed controllers are designed in
    hardware with timer circuitry 12 . However, you
    can program a PWM signal in software. This is
    much more economical and efficient.
  • You do not need any external circuitry, and can
    quickly reprogram a new duty cycle. The Program
    Listings will show how to do this later.

16
  • Construction
  • The schematic shows that the UDN2993B requires
    only two digital lines to control a single motor.
  • You can add another motor using pins 9-15 and
    another two digital lines.
  • The toy motor in Figure 16 requires a voltage
    supply of 5V. This supply voltage is connected
    to pin 1.
  • No external heat sinks are required.
  • The UDN2993B can handle much stronger motors with
    supply voltages up to 30 V and 0.5 A.
  • If you require even higher voltages and currents,
    Allegro makes the UDN2998 which can handle 50 V
    and 3A.

17
Program description
  • The program begins by asking the user to input
    the base address of the card. Then Ports A, B, C
    and the control word addresses are assigned. The
    three ports are configured with outputs roles.
  • DutyCycle sets the initial duty cycle to be 0, so
    that the motor is initially at rest.
  • Phase is set to 0 and Enable is set to 1, so that
    the motor is ready to run.
  • A nested DO...LOOP awaits for the user to hit a
    key on the PC keyboard and loops through the PWM
    subroutine.
  • The key menu describes how to control the speed
    of the motor. Once a key press has been detected
    (using the INKEY ) the program enters the
    SELECT...CASE code.
  • If an f key (faster) is hit the duty cycle is
    increased by 5.
  • If an s key (slower) is hit the duty cycle is
    decreased by 5.

18
Program description
  • Since the maximum duty cycle is 100, an
    IF...THEN is used as a threshold. A similar
    threshold is used for the minimum duty cycle of
    0.
  • If an r key (reverse) is hit the PHASE bit is
    complemented from its present state. The motor
    will reverse direction at the present duty cycle.
  • The major subroutine is PWM and calculates the
    OnTime and OffTime values.
  • A divide by 100 is used because duty cycle is in
    percentages.
  • The TotalTime value of the pulse is set for 0.1
    seconds.
  • Port A's A0 (ENABLE) line uses these values to
    enable the motor for OnTime seconds using the
    DelayOnTime function.
  • PWM then disables the motor for OffTime seconds
    using the DelayOffTime function.
  • If the q key (quit) is hit the motor stops and
    the program exits.

19
Nature of the control
  • This circuit and program is an example of
    open-loop control, and does not use any feedback.
  • In our bicycle analogy, if the bicycle has no
    speedometer, there is no way of knowing your
    exact speed. Furthermore, the speed depends on a
    person's pedal rate (on-time and off- time) and
    torque. The rate and torque depend on which gear
    you are in (i.e. the motor's load voltage supply
    and hence supplied current), the road's slope
    (load on the motor) and how properly the tires
    are inflated and how lubricated the gears are
    (e.g. friction of the motor bearings).
  • It is only by trial and error that you can match
    your pedal speed and torque with bicycle speed.
    This trial and error process is called tuning.
  • Similarly, every DC motor needs to be tuned. In
    the following program listing, a TotalTime of 0.1
    seconds was used.
  • For your motor, you may have to tune your motor
    by changing the TotalTime to reflect your motor's
    properties.
  • The Turbo C listing follows, as an illustration.

20
Turbo C program listing
  • FILE PWM.C
  • DESC Control speed and direction of a DC motor
    using PWM
  • /
  • includeltstdio.hgt
  • includeltstdlib.hgt
  • includeltdos.hgt / outportb, inportb defined here
    /
  • includeltconio.hgt / formatted text functions
    defined here /
  • void pwm(int, int, int, int)
  • void main(void)
  • int BASEADDR
  • int PORTA, PORTB, PORTC
  • int CNTRL
  • int DutyCycle
  • int SpeedOption
  • int Enable, Phase / Enable on A.0, Phase on A.1
    /

21
Turbo C program listing
  • clrscr() / clear screen /
  • window(5,5,75,30) / set up text window /
  • gotoxy(1,1) cprintf("Enter Base Address
    (decimal) e.g. 608 gt\n")
  • gotoxy(42,1) scanf("d", BASEADDR)
  • PORTA BASEADDR
  • PORTB BASEADDR 1
  • PORTC BASEADDR 2
  • CNTRL BASEADDR3
  • outportb(CNTRL, 128) / configure all ports for
    output /
  • outportb(PORTA, 0) / motor should be off /
  • gotoxy(1,3) cprintf("Speed Options")
  • gotoxy(1,4) cprintf("(f)aster")
  • gotoxy(1,5) cprintf("(s)lower")
  • gotoxy(1,6) cprintf("(r)everse direction")
  • gotoxy(1,7) cprintf("(q)uit")
  • gotoxy(1,9) cprintf("Selection gt ")

22
Turbo C program listing
  • DutyCycle 0 / start off at zero velocity /
  • Enable 1
  • Phase 0
  • do
  • while (!kbhit())
  • pwm(PORTA, DutyCycle, Enable, Phase)
  • / end of while /
  • SpeedOption getch()
  • switch(SpeedOption)
  • case 102 / 102 ASCII is f /
  • / increase speed by 5 DC /
  • DutyCycle DutyCycle 5
  • if(DutyCycle gt 100)
  • DutyCycle 100
  • gotoxy(1,20) cprintf("Can't go faster")
  • delay(200)
  • gotoxy(1,20) cprintf(" ")

23
Turbo C program listing
  • gotoxy(1,13) cprintf("Going faster...\n")
  • Enable 1
  • pwm(PORTA, DutyCycle, Enable, Phase)
  • break
  • case 115 / 115 ASCII is s /
  • / decrease speed by 5 DC /
  • DutyCycle DutyCycle - 5
  • if(DutyCycle lt 0)
  • DutyCycle 0
  • gotoxy(1,20) cprintf("Can't go slower")
  • delay(200)
  • gotoxy(1,20) cprintf(" ")
  • gotoxy(1,13) cprintf("Going slower...\n")
  • Enable 1
  • pwm(PORTA, DutyCycle, Enable, Phase)
  • break

24
Turbo C program listing
  • case 114 / 114 ASCII is r /
  • / reverse direction at present DC /
  • Enable 1
  • if(Phase 0)
  • Phase 2
  • else if(Phase 2)
  • Phase 0
  • pwm(PORTA, DutyCycle, Enable, Phase)
  • gotoxy(1,13) cprintf("Reversing.....\n")
  • break
  • case 113 / 113 ASCII is q /
  • gotoxy(1,22) cprintf("Quitting")
  • outportb(PORTA, 0)
  • outportb(PORTB, 0)
  • outportb(PORTC, 0)
  • exit(0)
  • break

25
Turbo C program listing
  • void pwm(int PORTA, int DutyCycle, int Enable,
    int Phase)
  • int OnTime, OffTime, TotalTime
  • TotalTime 100 / 100 msec /
  • OnTime (int)(TotalTime DutyCycle / 100)
  • OffTime (int)(TotalTime - OnTime)
  • outportb(PORTA, EnablePhase)
  • delay(OnTime)
  • Enable 0
  • outportb(PORTA, EnablePhase)
  • delay(OffTime)
  • gotoxy(1,10) cprintf("Duty Cycle is 3d",
    DutyCycle)
  • return

26
Interfacing transistors
27
Interfacing transistors
  • Relays and transistors will be interfaced to your
    8255 PC Interface Card in this example.
  • The circuits will show how you can turn on and
    off home appliances such as desk lamps or heavy
    duty motors.
  • Your computer can be programmed to turn on and
    off home appliances such as desk lamps and TVs.
    Perhaps you want to design a home security system
    or automate your home using your PC as a command
    console.
  • The 82C55 chip can only sink or source about 10
    mA, thus you cannot directly perform on/off
    control on large current devices from its ports.
  • In such cases you can build the relay and
    transistor circuits as in this example.

28
Interfacing transistors
  • These circuits can control both DC and AC loads.
    The heart of these circuits is the widely
    available 74LS374 octal latch and requires 10
    digital I/O lines.
  • With a single 74LS374 you can simultaneously
    control eight devices. Adding another octal
    latch, you can control another eight devices.

29
An example
30
  • Construction
  • The 74LS374 is a tristate device with an Output
    Enable (OE) on pin 1 and a Clock (CLK) on pin 11.
    The outputs 1Q-8Q are in a high impedance state
    which will not source or sink current while OE is
    high.
  • Bringing OE low and CLK high latches the inputs
    1D-8D and opens the lines 1Q-8Q. Lines 1D-8D are
    physically wired to the A0-A7 on the Terminal
    Expansion Board. The OE and CLK lines are wired
    to B0 and B1 respectively.
  • When an Q-line (1Q-8Q) is low, the 74LS374 can
    sink 12 mA which is enough current to drive
    relays or transistors.

31
Interfacing transistors
  • A typical toy DC motor requires voltage supply
    from 1.5 to 18 VDC. Depending on the torque on
    the motors spindle, about 1 A of current is
    needed. To turn it ON/OFF you can use a
    transistor.
  • The schematic in Fig. 24 shows a transistor
    connected to the 74LS374 circuit in Fig. 22. The
    TIP31 is an NPN transistor.
  • Transistors are cheaper, last longer and switch
    faster than relays. Transistors can handle higher
    currents if proper heat sinks are used.
  • The TIP31 can handle up to 3 A at 40 VDC.
  • In Fig. 22 a high on 1Q and CLK, and a low on OE
    will enable the TIP31s gate and allow current to
    flow from its collector to its emitter.
  • For example, you can use
  • OUT PORTA, 1 OUT PORTB, 1
  • to turn the motor.
  • Writing a 0 to port A or setting OE back high
    will turn it off.

32
Digital Communication
33
Digital Communication
  • once we have digital data we need to deal with
    the digital communication
  • There are 2 ways of digital communications
  • Parallel
  • all bits transferred at once (fast)
  • Serial
  • bits transferred 1 at a time (slower)

34
Parallel communication
  • All bits transferred simultaneously
  • fast
  • many wires
  • no extra bits
  • certain protocols must be followed, such as
    handshaking, for example

35
Parallel Data Transfer
  • The purpose of a parallel I/O interface is
  • to allow external devices, which can be
    controlled via binary state signals, to be
    interfaced to the mP system
  • For example
  • switches lamps are interfaced by connecting
    each to an individual data line
  • The interface to the outside world is called a
    port
  • in case of a parallel I/O device each port
    consists of
  • 8 digital data lines which may be configured as
    either INPUT or OUTPUT

36
Parallel Data Transfer
  • All bits of 1 byte are transferred simultaneously
  • parallel port may also be used for data transfer
    between 2 mPs
  • To ensure a reliable data transfer - control
    signals are used to indicate
  • new data ready
  • acknowledge new data has been read
  • Operation of these 2 signals between 2 mPs is
    called
  • HANDSHAKING - which is one of the commonly used
    PROTOCOLS

37
Handshaking
  • Fig. Below shows how 2 mP systems can be
    interfaced using parallel ports and handshaking
    lines

38
Handshaking
  • Each has 2 control lines
  • Data Ready
  • Data Acknowledge
  • Port 1 on each mP is configured as Output and
  • Port 2 configured as Input
  • Microprocessor A sends 1 byte of data to B as
    follows
  • A writes data to the register in Port 1 which
    activates its DoutRdy/ control line
  • which is connected to DinRdy/ control input on
    port 2 of B port 2 of B either sends an
    interrupt to its CPU or raises the flag in its
    status register that could be polled by the CPU

39
Handshaking
  • When B recognises data is ready it reads its port
    2 data register and indicates to A that it has
    done it by activating DinAck/ control line
  • similarly, in A the active DinAck/ either causes
    an interrupt or raises the flag in status
    register
  • once CPU of A has seen active acknowl. Signal it
    resets DoutRdy/ signal and makes it ready for the
    new set of data
  • when B sees the ready handshake signal has been
    reset it knows it has seen the acknowledgment and
    resets DinAck/ control line
  • A is ready to transmit more data to B

40
Parallel Communication Standards
  • most popular
  • IEEE-488 - General Purpose Interface Bus
    (GPIB/IeC625)
  • defines mechanical electrical requirements,
    e.g. compatibility with TTL, max transmission
    length (20m), data transfer rates up to 1Mbit/s
  • particularly good for control instrumentation
    systems
  • 24-pin connector 8data lines, 3 handshake lines,
    5 interface management lines, 8 ground return
    lines

41
Serial Data transfer
  • 1 bit transferred at a time with a clock signal
    allowing re-assembling the data at the receiver
  • transferring data between 2 mP systems or
    components within 1 system
  • advantages
  • only 3 wires required in a cable 1 for the data,
    1 for the clock signal, 1 ground
  • serial cabling advantageous over greater
    distances
  • disadvantages
  • unlike parallel port which can be used to
    interface sensors, actuators etc, there are no
    primary sensing/actuation techniques which result
    in the devices that may conveniently interface to
    serial digital port

42
Serial Data transfer
  • it is necessary that each system has a serial
    port and that the way information is transferred
    is the same for all ports
  • Synchronous Data Transfer
  • requires a common clock signal
  • can be achieved with so called SHIFT REGISTERS
  • it is a register whose contents are shifted by 1
    bit position when it receives a clock signal
  • when all bits are shifted, new data can come in
    at the input side
  • output of shift A is connected to input of shift
    B using a common clock signal

43
Serial - synchronous
44
Serial Data transfer
  • data transfer occurs synchronously and depends on
    the clock frequency used
  • shifting occurs on a specific edge of a clock
    signal (e.g. rising)
  • Typical procedure
  • CPU loads data onto shift reg. A (there needs to
    be encoder to transform parallel data into serial
    data)
  • control circuitry within the serial port A
    generates 8 clock signals to shift out the data
    progressively
  • when port B has received 8 clock signals it
    either interrupts its CPU or sets a flag in a
    status register (which can then be polled)

45
Serial data interface
46
Serial Data transfer
  • it may happen that data has not enough time to
    settle if B picks it up on each rising edge of
    the clock
  • to solve this, data may be put on B on a
    different edge of the clock - allowing some extra
    time for data to settle
  • it can be achieved via inverter placed in the
    clock line before it is read by port B
  • as a result, data is sampled half a clock pulse
    later (see Figure 4.5, Notes)

47
Synchronous data transfer
48
Serial Data transfer
  • additional hardware (decoder) transforms data
    from serial to 1 parallel byte again
  • lower speed
  • Asynchronous
  • does not rely on common clock
  • instead, each system has its own clock running at
    the same nominal frequencies
  • small difference in actual frequencies soon leads
    to clocks running out of step - data received
    incorrectly
  • to avoid this, each clock synchronised at the
    beginning of transmission of every byte

49
Asynchronous data transfer
  • Example ASCII Q (1010001)

50
Serial Data transfer
  • Procedure
  • Start bit
  • followed by data bits optional parity bit (to
    chack for errors)
  • stop bit which resets the logic levels - ready to
    accept new start bit
  • the circuitry used to implement asynchronous
    transmission/reception - typically contained in
    one chip called Universal Asynchronous Receiver
    and Transmitter - UART

51
UART
  • Universal Asynchronous Receiver Transmitter

52
UART
  • independent bi-directional device for serial
    communication
  • if the data can be received and transmitted at
    the same time - it is referred to as full duplex
    operation
  • 2 shift registers 1 transmit, 1 receive
  • 2 buffers 1transmit, 1 receive
  • the rate of data transmission depends on baud
    rates (bits per second)
  • nominally the same clock for Tr an Rec.

53
UART
  • start and stop signals
  • data sampled in the middle using signal derived
    from baud clock
  • talks to other devices via handshake line
  • control registers - allow various functions to be
    selected
  • number of bistop bits
  • parity check type etc
  • control over handshake lines

54
Serial Communication Standards
  • most widely used
  • EIA RS232C (Electrical Industries Association
    Recommended Standard)
  • 25-way plug-socket
  • every pin is allocated a signal - meaning
    direction described in the standard
  • standard does not define protocol

55
Universal Serial Bus (USB)
  • introduced for ease-of-use
  • advancement in a plug-and-play direction
  • much faster than a serial port
  • USB 1.1 12 Mbits/s USB 2.0 480 Mbits/s
  • USB port comes a standard with new PCs
Write a Comment
User Comments (0)
About PowerShow.com