Lecture 2 MicrocontrollerLec2

download Lecture 2 MicrocontrollerLec2

of 36

Transcript of Lecture 2 MicrocontrollerLec2

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    1/36

    Lecture 2Microcontroller Introduction

    Shaharyar Mahmood

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    2/36

    Microprocessor and Interfacing 2

    So what exactly is a Microcontroller

    Entire computer system contained within a

    single integrated circuit.

    The goal is to choose the most economicalMC that has the desired parameters and

    features for the application at hand.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    3/36

    Microprocessor and Interfacing 3

    Block Diagram

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    4/36

    Microprocessor and Interfacing 4

    Basic Architecture

    CPU is a complex sequential circuit whoseprimary function is to execute programs that arestored within its Flash EEPROM.

    A program is a series of instructions to perform aspecific task.

    Program is developed on PC and downloadedinto the MC and MC becomes stand-aloneprocessing system.

    Fetch-Decode-Execute cycle. CPU is the maincontrol center for the entire MC. CPU ismanaging program execution andcommunication with different subsystems.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    5/36

    Microprocessor and Interfacing 5

    Software Development Process

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    6/36

    Microprocessor and Interfacing 6

    CPU Architectures

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    7/36

    Microprocessor and Interfacing 7

    RISC versus CISC

    There are two basic types of instruction setarchitectures: Reduced Instruction Set Computer(RISC) and Complex Instruction Set Computer(CISC) Architecture.

    In RISC architecture complex instructions arebuilt up from basic building block instructions.

    RISC-based instruction architectures lendthemselves to systems with less complex CPU

    architectures.A CISC-based architecture has a complement of

    fuller feature, more complex instructions than theRISC-based architecture.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    8/36

    Microprocessor and Interfacing 8

    Little-endian vs Big-endian

    Endianness has to dowith the byte orderingof multibyte scalar

    values. Suppose we have the

    32-bit hexadecimalvalue 12345678 andthat it is stored in a32-bit word in byteaddressable memoryat byte location 184.

    Address Value Address Value

    184 12 184 78

    185 34 185 56

    186 56 186 34

    187 78 187 12

    Big Endian Small Endian

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    9/36

    Microprocessor and Interfacing 9

    Register Set

    Usually all registers associated with a given subsystem are grouped together.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    10/36

    Microprocessor and Interfacing 10

    Register Set

    The register set is the interface between you the userand the different subsystems aboard the microcontroller.

    Each register consists of a collection of flip-flops.

    to set a register called SCI BaudRate to the binary value1010 1110:

    SCI BaudRate = 0xAE;

    Header files contain the personality data for a givenmicrocontroller.

    Specifically, they provide a link between the name of aspecific register used within a program and its locationwithin the microcontroller.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    11/36

    Microprocessor and Interfacing 11

    Bus Structure

    A bus is a collection

    of parallel conductors

    that have a similar

    function. Most MCsare equipped with an

    address bus, a data

    bus, and a control

    bus.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    12/36

    Microprocessor and Interfacing 12

    Address Bus

    The address bus provides a connection between

    the central processing unit and the memory

    subsystem aboard the microcontroller.

    The number of individually addressable memory

    addresses may be determined by evaluating

    (2)address lines =addressable locations. E.g. 16 bits

    = 65536 (64kB). The first address in this

    memory space is (0000)16 while the last addressin this space will be (FFFF)16.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    13/36

    Microprocessor and Interfacing 13

    Data Bus

    Used to route parallel data about different

    subsystems within the MC. E.g. 4, 8, 16 or

    32 bit.The width determines the size of a data

    argument that the MC can process.

    For example, the largest unsigned integer

    that may be stored in a microcontroller

    with an eight-bit data path is 255. (2^n)-1.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    14/36

    Microprocessor and Interfacing 14

    Control Bus

    Microcontrollers are equipped with paths to sendand receive a collection of control signalsdesignated as the control bus.

    These signal lines carry control signals todifferent subsystems throughout themicrocontroller.

    Some control signals are provided on ports toconnect external components.

    Control signals are issued by the CPU inresponse to program instructions to ensure theinstruction is properly executed.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    15/36

    Microprocessor and Interfacing 15

    Memory

    The span of addressable memory usually

    contains several different types of memory

    including Static Random Access Memory

    (SRAM), byte-addressable Electrically

    Erasable Programmable Read Only

    Memory (EEPROM), and bulk

    programmable Flash EEPROM.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    16/36

    Microprocessor and Interfacing 16

    Memory Map

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    17/36

    Microprocessor and Interfacing 17

    RAM

    RAM is volatile. That is, if the microcontrollerloses power, the contents of RAM are lost.

    It can be written to and read from duringprogram execution.

    It is typically used during system development tostore a program. Once development is complete,the completed program is stored in nonvolatilememory such as Flash EEPROM.

    Used to store global variables, support dynamicmemory allocation of variables, and to provide alocation for the stack.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    18/36

    Microprocessor and Interfacing 18

    Byte-addressable EEPROM

    This type of memory is used to

    permanently store and recall variables

    during program execution.

    Used for logging critical data and to store

    useful information during a power failure.

    Applications include electronic lock

    combinations, and automatic garage door

    electronic unlock sequences.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    19/36

    Microprocessor and Interfacing 19

    Flash EEPROM

    Bulk programmable Flash EEPROM isused to store programs.

    Flash EEPROM is typically programmedusing In System Programming (ISP)techniques. That is, a host PC isconnected via a cable to a microcontrollerwhile it is resident within its applicationcircuit. The host PC downloads theprogram to the microcontroller.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    20/36

    Microprocessor and Interfacing 20

    AVR ISP

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    21/36

    Microprocessor and Interfacing 21

    TIME BASE

    The speed at which a microcontroller

    sequences through its actions is controlled

    by an external time base.

    The time base may be provided by an

    external quartz crystal, a programmable

    oscillator, a ceramic resonator, or an

    internal time base.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    22/36

    Microprocessor and Interfacing 22

    Timing Concepts

    Frequency:Signal frequency is the number ofcycles per second completed by a repetitivesignal. It is expressed in units of Hertz (Hz).

    Period:The period is the time increment inseconds required for a repetitive signal tocomplete a single cycle. The period is thereciprocal of the frequency (T= 1/ f).

    Duty cycle:The duty cycle indicates thepercentage of time for which the signal is activein a single period.

    Pulse width modulation (PWM):PWM signals arefrequently used to control motor speed.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    23/36

    Microprocessor and Interfacing 23

    Timing Concepts

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    24/36

    Microprocessor and Interfacing 24

    Timing Subsystem Applications

    Most microcontrollers are equipped with a multichannel timing system. The channels within thetiming system may be configured to:

    Measure parameters of input signals such asperiod and duty cycle.

    Generate precision output pulses or repetitivesignals.

    Count incoming pulses present in an inputsignal.

    Generate PWM signals.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    25/36

    Microprocessor and Interfacing 25

    Port Systems

    Ports provide access toexternal world.

    8-bit ports along with data-direction registers.

    Some ports have alternate

    functions such as alternatefunctions such as analog-to-digital conversion, serialcommunication, and networkinterfacing.

    Some have multiplexedcapability such as expansion

    ports provided to routethe data and address portsoutside the microcontrollermay employ time multiplexedfeatures.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    26/36

    Microprocessor and Interfacing 26

    Communication Systems

    parallel communication techniques are

    used for short distance communication

    within and outside of a microcontroller.

    For a long distance communication, a

    serial communication technique is used to

    send and receive data.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    27/36

    Microprocessor and Interfacing 27

    Serial Communications

    Synchronous and Asynchronouscommunication.

    The asynchronous communication method usesa start and stop bit protocol to synchronize atransmitter and receiver.

    Inexpensive, but the disadvantage is that thedata transmission rates are typically slower thana synchronous serial communication system dueto its overhead (start and stop bits).

    Referred as UART (universal asynchronousreceiver transmitter) or the SCI (serialcommunications interface).

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    28/36

    Microprocessor and Interfacing 28

    Continued

    The synchronous serial communication

    uses a synchronized clock to send and

    receive each bit.

    For a long distance communication, the

    synchronous serial communication

    technique is not recommended.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    29/36

    Microprocessor and Interfacing 29

    Terminology

    Simplex mode: In this mode, the serialcommunication is accomplished by transmittingdata in one direction at a time.

    Duplex mode: In this serial communicationmode, data can be transmitted and receivedfrom both ends of the communication link at thesame time.

    BAUD rate: The rate of bits sent or received. Itdescribes the number of bits communicated persecond.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    30/36

    Microprocessor and Interfacing 30

    Terminology Continued

    ASCII code: The American Standard Code forInformation Interchange code is used incommunication to encode alphabets, numbers,

    punctuation, and control characters using aseven-bit representation. ASCII is a subset ofthe international Unicode standard.

    Bit time: The time required to transmit or receivea single bit.

    Serial line code:A specific encoding mechanismused to transmit and receive information.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    31/36

    Microprocessor and Interfacing 31

    RS-232 Protocol

    The RS-232 standard represents a logic

    high with a 10 VDC level and a logic low

    with a +10 VDC level.

    These chips are equipped to provide

    interfacing for a two way (transmit and

    receive) communication system.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    32/36

    Microprocessor and Interfacing 32

    Interrupt System

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    33/36

    Microprocessor and Interfacing 33

    Speed

    Microcontrollers are available in a wide range ofoperating speeds.

    In general, you should use the lowest

    acceptable speed for a given application. This is because that the power consumption of a

    microcontroller is directly proportional to itsoperational speed. Since many microcontrollerapplications are battery powered, conservingpower and hence extending battery life isessential.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    34/36

    Microprocessor and Interfacing 34

    ANALOG-TO-DIGITAL CONVERTER

    This subsystem converts continuouslyvarying analog signals from the outsideworld into a binary representation suitable

    for use by the microcontroller.These converters commonly have 810-bit

    resolution.

    Therefore, a continuous signal isconverted to a series of digital snapshotsof the analog signal.

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    35/36

    Microprocessor and Interfacing 35

    CHOOSING A MICROCONTROLLER FOR A

    SPECIFIC DESIGN

  • 8/9/2019 Lecture 2 MicrocontrollerLec2

    36/36

    Microprocessor and Interfacing 36

    The End