74
Interfacing to Microprocessors Chapter 12

Chapter 12

Embed Size (px)

DESCRIPTION

chapter 12

Citation preview

Page 1: Chapter 12

Interfacing to MicroprocessorsInterfacing to Microprocessors

Chapter 12Chapter 12

Page 2: Chapter 12

introductionintroduction

• What constitutes a “controller” will vary from application to application.

• It may be no more than an amplifier or a switch. • It may be a complex system that may include

computers and other types of processors such as data acquisition and signal processors.

• Most of the time, it is a microprocessors. • We shall therefore focus the discussion here on

microprocessors.

• What constitutes a “controller” will vary from application to application.

• It may be no more than an amplifier or a switch. • It may be a complex system that may include

computers and other types of processors such as data acquisition and signal processors.

• Most of the time, it is a microprocessors. • We shall therefore focus the discussion here on

microprocessors.

Page 3: Chapter 12

introductionintroduction

• Focus on microprocessors as general purpose, flexible and reconfigurable controllers and the ways sensors and actuator relate to these.

• Microprocessors are often called microcontrollers • What is a microprocessor? What is the different

between a microprocessor and a computer or a microcomputer and how a distinguishing set of features is arrived at are all difficult and subjective issues. What is a microprocessor to one is a full fledged computer to another

• Focus on microprocessors as general purpose, flexible and reconfigurable controllers and the ways sensors and actuator relate to these.

• Microprocessors are often called microcontrollers • What is a microprocessor? What is the different

between a microprocessor and a computer or a microcomputer and how a distinguishing set of features is arrived at are all difficult and subjective issues. What is a microprocessor to one is a full fledged computer to another

Page 4: Chapter 12

The microprocessorThe microprocessor

• A microprocessor is a stand alone, self contained single chip microcomputer.

• It must have as a minimum: – a central processing unit (CPU)– nonvolatile and program memory – input and output capabilities.

• A structure that has these can be programmed in some convenient programming language

• can interact with the outside world through the input/output ports.

• A microprocessor is a stand alone, self contained single chip microcomputer.

• It must have as a minimum: – a central processing unit (CPU)– nonvolatile and program memory – input and output capabilities.

• A structure that has these can be programmed in some convenient programming language

• can interact with the outside world through the input/output ports.

Page 5: Chapter 12

The microprocessorThe microprocessor

• Other important requirements:• must be relatively simple• reasonably small • necessarily limited in most of its features – memory,

processing power and speed, addressing range and, of course in number of I/O devices it can interact with.

• The designer must have access to all features of the microprocessor – bus, memory, registers, all I/O ports,

• In short, Microprocessors are components with flexible features that the engineer can configure and program to perform task or a series of tasks.

• Other important requirements:• must be relatively simple• reasonably small • necessarily limited in most of its features – memory,

processing power and speed, addressing range and, of course in number of I/O devices it can interact with.

• The designer must have access to all features of the microprocessor – bus, memory, registers, all I/O ports,

• In short, Microprocessors are components with flexible features that the engineer can configure and program to perform task or a series of tasks.

Page 6: Chapter 12

The microprocessorThe microprocessor

• Two limits on the tasks microprocessors can perform:

• The limitations of the microprocessor itself• The imagination (or capabilities) of the

designer.

• Two limits on the tasks microprocessors can perform:

• The limitations of the microprocessor itself• The imagination (or capabilities) of the

designer.

Page 7: Chapter 12

The 8 bit microprocessorThe 8 bit microprocessor

• We will narrow down to 8 bit microprocessors – these are the most common in sensor/actuator systems – they are simple and representative of all microprocessor

• 16 and 32 bit microprocessors exist • There are a number of architectures being used. • We will emphasize the Harvard architecture

because of its simplicity, flexibility and popularity.

• We will narrow down to 8 bit microprocessors – these are the most common in sensor/actuator systems – they are simple and representative of all microprocessor

• 16 and 32 bit microprocessors exist • There are a number of architectures being used. • We will emphasize the Harvard architecture

because of its simplicity, flexibility and popularity.

Page 8: Chapter 12

The architectureThe architecture

• There are about two dozen manufacturers of microprocessors

• All based on a few architectures. • We shall only briefly describe here one

architecture – the Harvard architecture• used in many microprocessors• Simple and efficient• The choice in smaller microprocessor• Example: Microchip and Atmel microprocessors

• There are about two dozen manufacturers of microprocessors

• All based on a few architectures. • We shall only briefly describe here one

architecture – the Harvard architecture• used in many microprocessors• Simple and efficient• The choice in smaller microprocessor• Example: Microchip and Atmel microprocessors

Page 9: Chapter 12

The architectureThe architecture

• Main features:• Separate busses for program memory and operand

memory. • Pipelined architecture • Allows fetching data while another operation

executes. • Each cycle consists of fetching the (n+1)th instruction

while executing the nth • Integer arithmetic• Limited instruction set

• Main features:• Separate busses for program memory and operand

memory. • Pipelined architecture • Allows fetching data while another operation

executes. • Each cycle consists of fetching the (n+1)th instruction

while executing the nth • Integer arithmetic• Limited instruction set

Page 10: Chapter 12

The architectureThe architecture

• Bus widths vary depending on manufacturer and on the microprocessor size.

• Example: Figure 12.1, bus architecture for a PIC18F452 from Microchip.

• The instruction is 16bit • Program address is 15bit wide. • Data is 8bits and • Operand address is 12 bits. • These vary from device to device.

• Bus widths vary depending on manufacturer and on the microprocessor size.

• Example: Figure 12.1, bus architecture for a PIC18F452 from Microchip.

• The instruction is 16bit • Program address is 15bit wide. • Data is 8bits and • Operand address is 12 bits. • These vary from device to device.

Page 11: Chapter 12

Bus architectureBus architecture

Page 12: Chapter 12

The architectureThe architecture

• Example, the smallest microprocessors available (PIC10FXX) are 6 pin devices

• Summarized in Table 12.1. • The architecture for this device is shown in

Figure 12.2. • Here the program address bus is only 9 bits

while the instruction buss is 12 bits.

• Example, the smallest microprocessors available (PIC10FXX) are 6 pin devices

• Summarized in Table 12.1. • The architecture for this device is shown in

Figure 12.2. • Here the program address bus is only 9 bits

while the instruction buss is 12 bits.

Page 13: Chapter 12

PIC10FXX microprocessorsPIC10FXX microprocessors

Page 14: Chapter 12

PIC10FXX microprocessorsPIC10FXX microprocessors

Page 15: Chapter 12

The architectureThe architecture

• Example: one of the largest, is the PIC18FXX20

• Has an address bus 21 bits wide. • The processor and its variants are shown in

Table 12.2 • Its architecture in Figure 12.3.

• Example: one of the largest, is the PIC18FXX20

• Has an address bus 21 bits wide. • The processor and its variants are shown in

Table 12.2 • Its architecture in Figure 12.3.

Page 16: Chapter 12
Page 17: Chapter 12
Page 18: Chapter 12

The architectureThe architecture

• Architecture supports:• Direct addressing for the first 8 bits of address space• Indirect addressing (variable pointer addressing) for

all memory space. • Includes a CPU with associated status bits and a set

of special functions registers. • I/O ports, other peripherals (such as comparators,

A/D converters, PWM modules, etc.) • Timers, status indications and much more,

• Architecture supports:• Direct addressing for the first 8 bits of address space• Indirect addressing (variable pointer addressing) for

all memory space. • Includes a CPU with associated status bits and a set

of special functions registers. • I/O ports, other peripherals (such as comparators,

A/D converters, PWM modules, etc.) • Timers, status indications and much more,

Page 19: Chapter 12

The architectureThe architecture

• All modules available to the user. • User writable registers are also provided. • Microprocessors have been designed to respond to

specific needs: common to find modifications that respond to these needs

• Example: various processors from the same family may have a different instruction sets– PIC10FXX has 33 instructions – PIC18FXX20 has 77 instructions– ATmega128 (from Atmel) has 133 instructions.

• All modules available to the user. • User writable registers are also provided. • Microprocessors have been designed to respond to

specific needs: common to find modifications that respond to these needs

• Example: various processors from the same family may have a different instruction sets– PIC10FXX has 33 instructions – PIC18FXX20 has 77 instructions– ATmega128 (from Atmel) has 133 instructions.

Page 20: Chapter 12

The architectureThe architecture

• Memory varies from 256 bytes to over 256 kbytes

• Number of peripherals, ports, etc vary from as few as 4 to over 100

• Physical size: from 6 pin to 100 pins• Various chip configurations (DIP, surface

mount, dies etc.)

• Memory varies from 256 bytes to over 256 kbytes

• Number of peripherals, ports, etc vary from as few as 4 to over 100

• Physical size: from 6 pin to 100 pins• Various chip configurations (DIP, surface

mount, dies etc.)

Page 21: Chapter 12

AddressingAddressing

• 8 bit microprocessors have word length of 8 bits. • Integer data from 0 to 255 may be represented

directly. • To address memory, usually a longer word is

needed. • Most microprocessor have a 12 bit (4k) 14 (16k)

or 16 bit (64k) memory address but longer address words are also used.

• 8 bit microprocessors have word length of 8 bits. • Integer data from 0 to 255 may be represented

directly. • To address memory, usually a longer word is

needed. • Most microprocessor have a 12 bit (4k) 14 (16k)

or 16 bit (64k) memory address but longer address words are also used.

Page 22: Chapter 12

SpeedSpeed

• Most microprocessor operate at clock speeds between 1 and 40 MHz.

• Since often the clock is internally divided, the instruction cycle is slower than that

• Typical values are up to about 10 MHz cycle clock or 0.1 s per instruction

• Most microprocessor operate at clock speeds between 1 and 40 MHz.

• Since often the clock is internally divided, the instruction cycle is slower than that

• Typical values are up to about 10 MHz cycle clock or 0.1 s per instruction

Page 23: Chapter 12

Instruction setInstruction set

• Microprocessors have a small instruction set – • sometimes no more than 2-3 dozen simple

instructions. • Varies from a minimum of about 30 to a

maximum of about 150 instructions.• These are selected to cover the common

requirements of programming a device • Allows one to perform almost any task that can be

physically performed within the basic limitations of the device.

• Microprocessors have a small instruction set – • sometimes no more than 2-3 dozen simple

instructions. • Varies from a minimum of about 30 to a

maximum of about 150 instructions.• These are selected to cover the common

requirements of programming a device • Allows one to perform almost any task that can be

physically performed within the basic limitations of the device.

Page 24: Chapter 12

Instruction setInstruction set

• Instructions include: – logical instructions (AND, OR, XOR, etc.)– move and branching instructions (allow one to move data from

and to registers and conditional and unconditional branching)– bit instructions (operations on single bits in an operand)– arithmetic instructions such as add and subtract, – subroutine calls – other instructions that have to do with the performance of the

microprocessor such as reset, sleep and others.

• Some are bit oriented, some are byte (register) oriented, some are literal and control operations

• Instructions include: – logical instructions (AND, OR, XOR, etc.)– move and branching instructions (allow one to move data from

and to registers and conditional and unconditional branching)– bit instructions (operations on single bits in an operand)– arithmetic instructions such as add and subtract, – subroutine calls – other instructions that have to do with the performance of the

microprocessor such as reset, sleep and others.

• Some are bit oriented, some are byte (register) oriented, some are literal and control operations

Page 25: Chapter 12

Input and outputInput and output

• Input and output is defined by the availability of pins on the package.

• Usually limited to less than about 100 pins (6, 8, 14, 18, 20, 28, 32, 40, 44, 64 and 100 pins are common).

• Two pins are used to power to the device • For example, an 18 pin device can have no more

than 14 I/O pins. • Of these, some may be used for other purposes

such as oscillators or communication

• Input and output is defined by the availability of pins on the package.

• Usually limited to less than about 100 pins (6, 8, 14, 18, 20, 28, 32, 40, 44, 64 and 100 pins are common).

• Two pins are used to power to the device • For example, an 18 pin device can have no more

than 14 I/O pins. • Of these, some may be used for other purposes

such as oscillators or communication

Page 26: Chapter 12

Input and outputInput and output

• All microprocessor will have a number of pins available as I/O.

• Example, a 6 pin microprocessor may have as many as 4 I/O, a 64 pin processor can have in excess of 48 I/O pins.

• I/O pins are grouped into ports, each addressable as an 8 bit word (each group has up to 8 I/O pins).

• Different ports may have different properties and may be able to perform different functions.

• All microprocessor will have a number of pins available as I/O.

• Example, a 6 pin microprocessor may have as many as 4 I/O, a 64 pin processor can have in excess of 48 I/O pins.

• I/O pins are grouped into ports, each addressable as an 8 bit word (each group has up to 8 I/O pins).

• Different ports may have different properties and may be able to perform different functions.

Page 27: Chapter 12

Input and outputInput and output

• I/O pins are tri-state enabling an I/O pin to serve as input, output or to be disconnected.

• Most I/O are digital but some may be configured as analog as well.

• I/O pins can supply or sink considerable current – usually in the range of 20-25 mA.

• This is not sufficient to drive many actuators but it can drive low power devices directly or indirectly through switches and amplifiers.

• I/O pins are tri-state enabling an I/O pin to serve as input, output or to be disconnected.

• Most I/O are digital but some may be configured as analog as well.

• I/O pins can supply or sink considerable current – usually in the range of 20-25 mA.

• This is not sufficient to drive many actuators but it can drive low power devices directly or indirectly through switches and amplifiers.

Page 28: Chapter 12

Clock and timersClock and timers

• Microprocessor must have a timing mechanism that defines the instruction cycle.

• This is done by an oscillator • Oscillators may be internal or external. • Usually and RC oscillator is used for internal

oscillation • A crystal is the most common way of setting the

frequency externally (this requires either dedicated pins or the use of two I/O pins).

• Microprocessor must have a timing mechanism that defines the instruction cycle.

• This is done by an oscillator • Oscillators may be internal or external. • Usually and RC oscillator is used for internal

oscillation • A crystal is the most common way of setting the

frequency externally (this requires either dedicated pins or the use of two I/O pins).

Page 29: Chapter 12

Clock and timersClock and timers

• The oscillator frequency is usually divided internally to define the basic cycle time.

• Microprocessors have internal timers– under the control of the user – used for various functions requiring counting/timing – At least one counter is available – larger microprocessors can have 4 or more timers– some are 8 bit timers and some 16 bit timers. – a watchdog timer is available for the purpose of resetting

the processor should it be “stuck” in an inoperative mode.

• The oscillator frequency is usually divided internally to define the basic cycle time.

• Microprocessors have internal timers– under the control of the user – used for various functions requiring counting/timing – At least one counter is available – larger microprocessors can have 4 or more timers– some are 8 bit timers and some 16 bit timers. – a watchdog timer is available for the purpose of resetting

the processor should it be “stuck” in an inoperative mode.

Page 30: Chapter 12

Clock and timersClock and timers

• Registers• Used for • Execution of commands • Control over the functions of the microprocessor, • Addressing• Flagging• Status indication

• Registers• Used for • Execution of commands • Control over the functions of the microprocessor, • Addressing• Flagging• Status indication

Page 31: Chapter 12

MemoryMemory

• Modern microprocessors, contain three types of memory:

• program memory, in which the program is loaded,

• data memory (RAM), • EEPROM memory• Note: EEPROM not available on some very

small microprocessors.

• Modern microprocessors, contain three types of memory:

• program memory, in which the program is loaded,

• data memory (RAM), • EEPROM memory• Note: EEPROM not available on some very

small microprocessors.

Page 32: Chapter 12

MemoryMemory

• Program memory is usually the largest• From less than 256 bytes to over 256kBytes. • In most cases, flash memory which means that is

rewritable at will and is nonvolatile (program is retained until rewritten or erased).

• Data memory (RAM) is usually quite small and may be a small fraction of the program memory

• Does not retain data upon removal of power. • EEPROM is nonvolatile rewritable memory used

mostly to write data during execution

• Program memory is usually the largest• From less than 256 bytes to over 256kBytes. • In most cases, flash memory which means that is

rewritable at will and is nonvolatile (program is retained until rewritten or erased).

• Data memory (RAM) is usually quite small and may be a small fraction of the program memory

• Does not retain data upon removal of power. • EEPROM is nonvolatile rewritable memory used

mostly to write data during execution

Page 33: Chapter 12

PowerPower

• Most microprocessor operate from 1.8V to 6V. • Some have a more limited range (2.7-5.5V). • Based on CMOS technology: This means that:

– power consumption is very modest.

– power consumption is frequency dependent.

• The higher the frequency the higher the power consumed

• Most microprocessor operate from 1.8V to 6V. • Some have a more limited range (2.7-5.5V). • Based on CMOS technology: This means that:

– power consumption is very modest.

– power consumption is frequency dependent.

• The higher the frequency the higher the power consumed

Page 34: Chapter 12

PowerPower

• Power is also dependent on • What the processor does • Which modules are functioning at any given time. • The user has considerable control over power

consumption through:– Choice of frequency– Mode of operation – Special functions such as interrupt wakeup and sleep.

• Power is also dependent on • What the processor does • Which modules are functioning at any given time. • The user has considerable control over power

consumption through:– Choice of frequency– Mode of operation – Special functions such as interrupt wakeup and sleep.

Page 35: Chapter 12

Other functionalitiesOther functionalities

• Microprocessor must have certain modules (CPU, memory and I/O)

• They can have many more modules• Add functionality and flexibility• Many microprocessors include

– comparators (for digitization purposes), – A/D converters, – Capture and Compare (CCP) modules, – PWM generators – Communication interfaces.

• Microprocessor must have certain modules (CPU, memory and I/O)

• They can have many more modules• Add functionality and flexibility• Many microprocessors include

– comparators (for digitization purposes), – A/D converters, – Capture and Compare (CCP) modules, – PWM generators – Communication interfaces.

Page 36: Chapter 12

Other functionalitiesOther functionalities

• One or two comparators are provided on many microprocessors.

• Depending on the microprocessors 8 or 10 bit A/D converters are provided, usually in multiple channels (4 to 16).

• PWM channels (up to 8) are common on some processors.

• Serial interfaces such as UART, SPI, two wire interface (I2C), synchronous serial and USB ports are available

• One or two comparators are provided on many microprocessors.

• Depending on the microprocessors 8 or 10 bit A/D converters are provided, usually in multiple channels (4 to 16).

• PWM channels (up to 8) are common on some processors.

• Serial interfaces such as UART, SPI, two wire interface (I2C), synchronous serial and USB ports are available

Page 37: Chapter 12

Other functionalitiesOther functionalities

• Many microprocessors provide multiple interfaces, all under the user’s control.

• Other functions such as analog amplifiers and even transceivers are sometimes incorporated within the chip.

• The I/O used for these functions are either digital I/O (for communication for example) or analog I/O (for A/D for example)

• Many microprocessors provide multiple interfaces, all under the user’s control.

• Other functions such as analog amplifiers and even transceivers are sometimes incorporated within the chip.

• The I/O used for these functions are either digital I/O (for communication for example) or analog I/O (for A/D for example)

Page 38: Chapter 12

Programs and programmabilityPrograms and programmability• A microprocessor is only useful if it can be

programmed. • Programming languages and compilers have been

designed specifically for microprocessors. • The basic method of programming

microprocessors is through the Assembly programming language

• Can be, and very often is done through use of higher level languages with C leading.

• A microprocessor is only useful if it can be programmed.

• Programming languages and compilers have been designed specifically for microprocessors.

• The basic method of programming microprocessors is through the Assembly programming language

• Can be, and very often is done through use of higher level languages with C leading.

Page 39: Chapter 12

Programs and programmabilityPrograms and programmability• These are specific compilers, adapted for a class of

microprocessors. • They are based on a standard C compiled (such as

ANSI C) and modified to produce executables that can be loaded onto the microprocessor.

• Most microprocessors can be programmed in circuit allowing changes to be made, or the processors to be programmed or reprogrammed after the circuit has been built.

• These are specific compilers, adapted for a class of microprocessors.

• They are based on a standard C compiled (such as ANSI C) and modified to produce executables that can be loaded onto the microprocessor.

• Most microprocessors can be programmed in circuit allowing changes to be made, or the processors to be programmed or reprogrammed after the circuit has been built.

Page 40: Chapter 12

Programs and programmabilityPrograms and programmability• Instruction sets for microprocessors are small and

based on the assembly language nomenclature. • Microprocessors have been designed for integer

operations. • Programming for control, especially sequential

control is simple and logical. • Floating point operations and, are either not

practical or difficult and tedious. • They also tend to require considerable time and

should only be attempted if absolutely necessary.

• Instruction sets for microprocessors are small and based on the assembly language nomenclature.

• Microprocessors have been designed for integer operations.

• Programming for control, especially sequential control is simple and logical.

• Floating point operations and, are either not practical or difficult and tedious.

• They also tend to require considerable time and should only be attempted if absolutely necessary.

Page 41: Chapter 12

Programs and programmabilityPrograms and programmability• There are both integer and floating point

libraries freely available.

• Floating point operations are only practical on the larger microprocessors because they require much memory.

• There are both integer and floating point libraries freely available.

• Floating point operations are only practical on the larger microprocessors because they require much memory.

Page 42: Chapter 12

Examples of microprocessorsExamples of microprocessors

• PIC10FXXX (low level, 6 pin),

• PIC16F62X (midrange, 18 pin),

• PIC18FXX20 (high level, 64 or 80 pin),

• Atmega128 (high level, 64 pin).

• A comparison of these typical processors will reveal most of the properties and capabilities of microprocessors.

• PIC10FXXX (low level, 6 pin),

• PIC16F62X (midrange, 18 pin),

• PIC18FXX20 (high level, 64 or 80 pin),

• Atmega128 (high level, 64 pin).

• A comparison of these typical processors will reveal most of the properties and capabilities of microprocessors.

Page 43: Chapter 12

Interfacing IssuesInterfacing Issues

• Three basic modes:– 1. Continuous dedicated monitoring of the

sensor by the microprocessor– 2. Polling the sensor– 3. Interrupt mode

• Three basic modes:– 1. Continuous dedicated monitoring of the

sensor by the microprocessor– 2. Polling the sensor– 3. Interrupt mode

Page 44: Chapter 12

Continuous modeContinuous mode

• Microprocessor is dedicated for use with the sensor

• Its output is monitored by the microprocessor continuously

• The microprocessor reads the sensor’s output at a given rate

• Output is then used to act

• Microprocessor is dedicated for use with the sensor

• Its output is monitored by the microprocessor continuously

• The microprocessor reads the sensor’s output at a given rate

• Output is then used to act

Page 45: Chapter 12

Poling modePoling mode

• Sensor operates as if the microprocessor did not exist.

• Its output is monitored by the microprocessor

• The microprocessor reads the sensor’s output at a given rate or intervals - poling

• Output is then used to act

• Sensor operates as if the microprocessor did not exist.

• Its output is monitored by the microprocessor

• The microprocessor reads the sensor’s output at a given rate or intervals - poling

• Output is then used to act

Page 46: Chapter 12

Interrupt modeInterrupt mode

• Microprocessor is in sleep mode

• Outputs of the sensor are not being processed

• Upon a given event, microprocessor wakes up through one of its interrupt options

• The sensor activates the interrupt

• Microprocessor is in sleep mode

• Outputs of the sensor are not being processed

• Upon a given event, microprocessor wakes up through one of its interrupt options

• The sensor activates the interrupt

Page 47: Chapter 12

Notes:Notes:

• Interrupts can be timed• Interrupts can be issued by sources other

than the sensor• The microprocessor may be involved in

other functions, separate from the sensor, such as control of an actuator

• Feedback from actuators may also be used to perform interrupts

• Interrupts can be timed• Interrupts can be issued by sources other

than the sensor• The microprocessor may be involved in

other functions, separate from the sensor, such as control of an actuator

• Feedback from actuators may also be used to perform interrupts

Page 48: Chapter 12

General Interfacing RequirementsGeneral Interfacing Requirements• Microprocessor input interfacing

requirements• Microprocessor output

requirements• Errors introduced by

microprocessors

• Microprocessor input interfacing requirements

• Microprocessor output requirements

• Errors introduced by microprocessors

Page 49: Chapter 12

Input interfacing requirementsInput interfacing requirements• Signal level• Impedance and matching• Response, frequency• Signal conditioning• Signal scaling• Isolation• Loading

• Signal level• Impedance and matching• Response, frequency• Signal conditioning• Signal scaling• Isolation• Loading

Page 50: Chapter 12

Output interfacing requirementsOutput interfacing requirements• Signal levels• Power levels• Isolation

• Signal levels• Power levels• Isolation

Page 51: Chapter 12

Input signal levelsInput signal levels

• Basic level: zero to Vdd

– Must scale signals if necessary• No dual polarity signals

– Must translate/scale as necessary• Direct reading or A/D• Can read voltages only

– AC or DC– Limitations in frequency

• Basic level: zero to Vdd

– Must scale signals if necessary• No dual polarity signals

– Must translate/scale as necessary• Direct reading or A/D• Can read voltages only

– AC or DC– Limitations in frequency

Page 52: Chapter 12

ImpedanceImpedance

P are high input impedance devices– ~ 1 - 10 M– Input current - < 1 A.

• Ideal for direct connection of low impedance sensors (magnetic, thermistors, thermoelectric, etc.)

• High impedance sensors (capacitive, pyroelectric, etc.) must be buffered– Voltage followers– FET amplifiers

P are high input impedance devices– ~ 1 - 10 M– Input current - < 1 A.

• Ideal for direct connection of low impedance sensors (magnetic, thermistors, thermoelectric, etc.)

• High impedance sensors (capacitive, pyroelectric, etc.) must be buffered– Voltage followers– FET amplifiers

Page 53: Chapter 12

Response and frequencyResponse and frequency

• Most sensors are slow devices– Can be interfaced directly– No concern for response and frequency

range

• Some sensors are part of oscillators– Frequencies may be quite high– Need to worry about proper sampling by the

microprocessor

• Most sensors are slow devices– Can be interfaced directly– No concern for response and frequency

range

• Some sensors are part of oscillators– Frequencies may be quite high– Need to worry about proper sampling by the

microprocessor

Page 54: Chapter 12

Response and frequencyResponse and frequency

• Example: 10 mHz P, cycle time of 0.4 s. (most processor divide the clock frequency by a factor - 4 in this case)

• Any operation such as reading an input required n cycles, say n=5

• Effective frequency: 0.5 MHz• Sampling cannot be done at rates

higher than 250 kHz• Any sensor producing a signal above

this frequency will be read erroneously

• Example: 10 mHz P, cycle time of 0.4 s. (most processor divide the clock frequency by a factor - 4 in this case)

• Any operation such as reading an input required n cycles, say n=5

• Effective frequency: 0.5 MHz• Sampling cannot be done at rates

higher than 250 kHz• Any sensor producing a signal above

this frequency will be read erroneously

Page 55: Chapter 12

Response and frequencyResponse and frequency

• Some solutions:– Divide the sensor’s frequency

• Reduces sensitivity• Must be done externally to the P

– F-V converter• Introduces conversion errors• Must be done externally

– Frequency counter at input• Use output of the counter as input to mP.• Expensive

– Faster microprocessors

• Some solutions:– Divide the sensor’s frequency

• Reduces sensitivity• Must be done externally to the P

– F-V converter• Introduces conversion errors• Must be done externally

– Frequency counter at input• Use output of the counter as input to mP.• Expensive

– Faster microprocessors

Page 56: Chapter 12

Input signal conditioningInput signal conditioning

• Offset– Primarily for dc levels– Can be offset up or down– Usually done to remove the dc level– Sometimes needed to remove negative

polarity.– AC signals may sometimes be coupled

through capacitors to eliminate dc levels

• Offset– Primarily for dc levels– Can be offset up or down– Usually done to remove the dc level– Sometimes needed to remove negative

polarity.– AC signals may sometimes be coupled

through capacitors to eliminate dc levels

Page 57: Chapter 12

OffsetOffset

• Example– Thermistor: 500 at 20ºC– Varies from 100 to 900 for temp. between 0

and 100ºC

• Example– Thermistor: 500 at 20ºC– Varies from 100 to 900 for temp. between 0

and 100ºC

Page 58: Chapter 12

OffsetOffset

• At 500ºC– V = (12/1500)*500 = 4 V

• At 0ºC– V = (12/1400)*400 = 3.428 V

• At 100ºC– V = (12/1900)*900 = 5.684 V

• V varies between 3.428V and 5.684V– 5.684V is above the 5V operating voltage of

the microprocessor

• At 500ºC– V = (12/1500)*500 = 4 V

• At 0ºC– V = (12/1400)*400 = 3.428 V

• At 100ºC– V = (12/1900)*900 = 5.684 V

• V varies between 3.428V and 5.684V– 5.684V is above the 5V operating voltage of

the microprocessor

Page 59: Chapter 12

OffsetOffset

• Some solutions– Remove 3.428V through an inverting amplifier– Reduce the source voltage from 12V to, say

6V. This will change the range from 1.714V to 2.842V

– Increase the resistor from 1000W to, say, 1500 W. This will reduce the output and will vary from 2.526V to 4.5V

• Some solutions– Remove 3.428V through an inverting amplifier– Reduce the source voltage from 12V to, say

6V. This will change the range from 1.714V to 2.842V

– Increase the resistor from 1000W to, say, 1500 W. This will reduce the output and will vary from 2.526V to 4.5V

Page 60: Chapter 12

Offset - other solutionsOffset - other solutions• For ac signals

– Rectification• Only appropriate if signal is unipolar

– Bi-polar signals produce negative signals• Cannot be used with microprocessors

• For ac signals– Rectification

• Only appropriate if signal is unipolar

– Bi-polar signals produce negative signals• Cannot be used with microprocessors

Page 61: Chapter 12

Offset - other solutionsOffset - other solutions• Bridge connection

– Battery must be floating– Output: 0V at 0ºC to 2.3V at 100ºC.– Offset of arbitrary value can be added

• Done by decreasing the value of lower-left resistor • 1V offset with 285.7 resistor

• Bridge connection– Battery must be floating– Output: 0V at 0ºC to 2.3V at 100ºC.– Offset of arbitrary value can be added

• Done by decreasing the value of lower-left resistor • 1V offset with 285.7 resistor

Page 62: Chapter 12

ScalingScaling

• By amplification– Operational amplifiers

• By attenuation– Operational amplifiers– Resistance dividers– Transformers (for ac)

• Amplifiers are preferrable• Dividers introduce errors• Transformers are noisy and big

• By amplification– Operational amplifiers

• By attenuation– Operational amplifiers– Resistance dividers– Transformers (for ac)

• Amplifiers are preferrable• Dividers introduce errors• Transformers are noisy and big

Page 63: Chapter 12

IsolationIsolation

• Two basic methods– Transformers– Optical isolation

• Two basic methods– Transformers– Optical isolation

Page 64: Chapter 12

LoadingLoading

• Microprocessors load the sensor• Not an issue with low impedance sensors• Must be buffered for high impedance

sensors• Solution: voltage followers with FET input

stages• An error due to loading should be taken into

account

• Microprocessors load the sensor• Not an issue with low impedance sensors• Must be buffered for high impedance

sensors• Solution: voltage followers with FET input

stages• An error due to loading should be taken into

account

Page 65: Chapter 12

Output InterfaceOutput Interface

• Most microprocessors:– 1.8 to 6V– 20 to 25 mA per output pin– Can power small loads directly (LEDs, small

relays)– Protection diodes on all outputs

• Most microprocessors:– 1.8 to 6V– 20 to 25 mA per output pin– Can power small loads directly (LEDs, small

relays)– Protection diodes on all outputs

Page 66: Chapter 12

Output InterfaceOutput Interface

• Large loads:– Must add circuitry to boost current, power– MOSFETS are ideal for this purpose– Inductive loads: must add protection against

large spikes– Often necessary to isolate output– Very often necessary to translate voltages for

output

• Large loads:– Must add circuitry to boost current, power– MOSFETS are ideal for this purpose– Inductive loads: must add protection against

large spikes– Often necessary to isolate output– Very often necessary to translate voltages for

output

Page 67: Chapter 12

Output pinsOutput pins

• MOSFETS:– Driven

• MOSFETS:– Driven

Page 68: Chapter 12

Output pins connection of loadsOutput pins connection of loads• Sourcing current• Sinking current• The two are somewhat different:

• Sourcing current• Sinking current• The two are somewhat different:

Page 69: Chapter 12

Errors and resolutionErrors and resolution• Errors introduced by the

microprocessor:– Due to resolution of A/D, D/A– Sampling errors

• These come in addition to any errors in the sensor/actuator

• Errors introduced by the microprocessor:– Due to resolution of A/D, D/A– Sampling errors

• These come in addition to any errors in the sensor/actuator

Page 70: Chapter 12

ResolutionResolution• Digital systems have an inherent

resolution:• LSB - least significant bit

– Any value smaller than the LSB cannot be represented

– This constitutes an error– LSB is inherent in any module as well as

in the CPU itself

• Digital systems have an inherent resolution:

• LSB - least significant bit– Any value smaller than the LSB cannot

be represented– This constitutes an error– LSB is inherent in any module as well as

in the CPU itself

Page 71: Chapter 12

Resolution of modulesResolution of modules• A/D - n bits resolution, meaning:

a 10 bit A/D, digitizing a 5V input has a resolution of:

5V/1024 = 4.88 mV

• The A/D can resolve down to 4.88 mV• Can represent data in increments of 4.88 mV• (a 14 bit A/D resolves down to 0.3 mV)• For a 1V span on a sensor, this is approximately

0.5% error

• A/D - n bits resolution, meaning:a 10 bit A/D, digitizing a 5V input has a resolution of:

5V/1024 = 4.88 mV

• The A/D can resolve down to 4.88 mV• Can represent data in increments of 4.88 mV• (a 14 bit A/D resolves down to 0.3 mV)• For a 1V span on a sensor, this is approximately

0.5% error

Page 72: Chapter 12

Resolution of modulesResolution of modules• PWM (Pulse Width Modulator)• Given a clock frequency fosc, the PWM resolution

is:

• PWM (Pulse Width Modulator)• Given a clock frequency fosc, the PWM resolution

is:

PWM res . =

log ( f osc / fPWM

)

log (2)

Page 73: Chapter 12

CPU errorsCPU errors

• Most microprocessors are 8 bit microprocessors

• Integer arithmetics• Largest value represented: 256• Roundoff errors due to this representation• Special math subroutines have been

developed to minimize these errors (otherwise they would be unacceptably high)

• Most microprocessors are 8 bit microprocessors

• Integer arithmetics• Largest value represented: 256• Roundoff errors due to this representation• Special math subroutines have been

developed to minimize these errors (otherwise they would be unacceptably high)

Page 74: Chapter 12

Sampling errorsSampling errors

• All inputs and outputs on a microprocessor are sampled. That is:– Inputs are only read at intervals– Outputs are only updated at intervals– Intervals depend on the frequency of the clock, operation

to be executed and on the software that executes it– Sampling may not even be constant during operation

because of the need to perform different tasks at different times

– Errors are due to changes in input/output between sampling to which the microprocessor is oblivious

– Errors are not fixed - depend among other things on how well the program is written

• All inputs and outputs on a microprocessor are sampled. That is:– Inputs are only read at intervals– Outputs are only updated at intervals– Intervals depend on the frequency of the clock, operation

to be executed and on the software that executes it– Sampling may not even be constant during operation

because of the need to perform different tasks at different times

– Errors are due to changes in input/output between sampling to which the microprocessor is oblivious

– Errors are not fixed - depend among other things on how well the program is written