embedded systems · a control system needs to check the plant status and provide specific commands...

65
Embedded Systems Francesco Ferrante, PhD [email protected] Department of Physics, Engineering, Earth, and Environmental Sciences, and Mechanics Grenoble Image Parole Signal Automatique Université Grenoble Alpes Control Systems Technologies —– Graduate Course Master in Systems, Control, and Information Technologies —– October 14, 2018 Université Grenoble Alpes - 1/55

Upload: others

Post on 04-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Embedded SystemsFrancesco Ferrante, PhD

[email protected]

Department of Physics, Engineering, Earth, and Environmental Sciences, andMechanicsGrenoble Image Parole Signal AutomatiqueUniversité Grenoble Alpes

Control Systems Technologies

—–Graduate Course

Master in Systems, Control, and Information Technologies

—–

October 14, 2018

Université Grenoble Alpes - 1/55

Page 2: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - 2/55

Page 3: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - /55

Page 4: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Embedded SystemsWhat is an Embedded System?

◮ a programmed controlling and operating system;

◮ with a dedicated function within a larger mechanical orelectrical system;

◮ hidden user interface.

It is embedded as part of a complete device often includinghardware and mechanical parts.

Embedded systems control many devices incommon use today. Ninety-eight percent of allmicroprocessors are manufactured componentsof embedded systems. DHCOM Computer On Module

with AM35x Processor,

https://www.dh-electronics.com

Université Grenoble Alpes - 3/55

Page 5: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Applications

◮ Automotive: Automobiles, electric vehicles, and hybrid vehiclesincreasingly use embedded systems. The largest field ofapplication;

◮ Avionics: inertial guidance systems and GPS

◮ Industrial Automation: Various electric motors useelectric/electronic motor controllers;

◮ Communication: from telephone switches for the network tocell phones at the end user;

◮ Consumer Electronics: Consumer electronics include MP3players, mobile phones, video game consoles, digital cameras,GPS receivers, and printers;

◮ Health Applications: Medical equipment uses embeddedsystems for vital signs monitoring, electronic stethoscopes foramplifying sounds, and various medical imaging.

Université Grenoble Alpes - 4/55

Page 6: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Automotive

Modern vehicle’s network architecture. Source: [Leen, Heffernan 2002, IEEE

Computer, 2002.]

Université Grenoble Alpes - 5/55

Page 7: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Embedded Systems

◮ Embedded systems are designed to do some specific task,rather than be a general-purpose computer for multiple tasks.Difficult to define standards.

◮ embedded systems are designed to meet specific requirements.

Typical Functions:

◮ Signal Processing

◮ Communication: with the external environment and within thesystem itself;

◮ Data storage

Université Grenoble Alpes - 6/55

Page 8: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Embedded Systems-Hardware Specifics◮ Communication Interfaces: fundamental in all applications and

have a strong impact on the resulting cost. Some examples:ADC, timers, USB...

◮ User Interfaces: most of the time very basic: buttons, LEDs,graphic or character LCDs;

◮ Consumption: Crucial in battery-powered applications;◮ Mechanical Specs: Weight and occupation.

Source Electronics Engineering Herald

Université Grenoble Alpes - 7/55

Page 9: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - 7/55

Page 10: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Processors in embedded systems

Embedded processors can be broken into two broad categories:

◮ Microprocessors (µP) use separate integrated circuits formemory and peripherals.

◮ Microcontrollers (µC) have on-chip peripherals, thus reducingpower consumption, size and cost.

From a technical point of view:

◮ Both Von Neumann and Harvard architectures are used.

◮ RISC as well as non-RISC processors can be found.

◮ Word lengths vary from 4-bit to 64-bits, although the mosttypical remain 8/16-bit.

Université Grenoble Alpes - 8/55

Page 11: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Von Neumann Architecture

The von Neumann architecture isa computer architecture based ona 1945 description by themathematician and physicist Johnvon Neumann. J. Von Neumann. 1903-1957

A processing unit that contains:

◮ an arithmetic logic unit (ALU)and processor registers;

◮ a control unit that contains aninstruction register and programcounter;

◮ Memory that stores data andinstructions;

◮ External mass storage;

◮ Input and output mechanisms.

✔ efficiency of design,impl., and operation

✗ data transfers andinstruction fetchescannot occur sim.

Université Grenoble Alpes - 9/55

Page 12: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Harvard Architecture

The term originated from the Harvard Mark Irelay-based computer.

Harvard Mark IComputer

A computer architecture withphysically separated storage andsignal pathways for instructions anddata.

✔ separate data and instructionbusses, allowing transferssimultaneously on bothbusses.

✗ harder to design and develop

✗ free data memory cannot beused for instruction andvice-versa.

Used in Microcontrollers and DSPs.◮ to speed up processing by concurrent instruction and data

access Université Grenoble Alpes - 10/55

Page 13: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Instruction set architectures

◮ An instruction set architecture (ISA) is an abstract model of acomputer. It is also referred to as architecture or computerarchitecture.

◮ An ISA describes the type of data that can be handled, theregisters, and the instructions;

◮ Same ISA can lead to different implementations.

Common classification by architectural complexity:

◮ complex instruction set computer (CISC)

◮ reduced instruction set computer (RISC)

Université Grenoble Alpes - 11/55

Page 14: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

CISC Computers

◮ The term has been actually coined after the development ofthe RISC model.

◮ it is a computer in which single instructions can executeseveral low-level operations (such as a load from memory, anarithmetic operation, and a memory store) or are capable ofmulti-step operations.

The idea is to have computer having low level instructions verysimilar to a high level language: calls, loop control, and complexaddressing modes, data structure and array.

✔ The compact nature of such instruction sets results in smallerprogram sizes and fewer (slow) main memory accesses;

✗ the design of CISC machines is very complex and inefficient interms of circuitry.

Some examples of CISC computers:

◮ System/360, VAX, PDP11, Z80, Motorola 68000, Intel 8080,MT6502, x86

Université Grenoble Alpes - 12/55

Page 15: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

RISC Computers

RISC (Reduced Instruction Set Computing) is a CPU design basedon a simplified instruction set, consisting of:

◮ simple, highly optimized instructions that can be executedwith only a few CPU cycles (ideally only one, even if inpractice it is not always so ).

The advantage of such an approach is to have a low cost in siliconand a great efficiency, but at the cost of a considerable distancefrom the high level languages.

✔ Low cost and efficiency;

✗ high difficulty in low level programming. Need for advancedcompilers.

Some examples of CISC computers:

◮ ARM, ARC, Blackfin, Atmel AVR, MIPS, PA-RISC, SuperH,SPARC.

Embedded systems are in general built upon the RISC paradigm.

Université Grenoble Alpes - 13/55

Page 16: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

RISC Computers

Picmicro mid-range MCU family Instruction Set. Source Microchip R©.

Université Grenoble Alpes - 14/55

Page 17: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - /55

Page 18: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Real-time Systems◮ A control system needs to check the plant status and provide

specific commands when some conditions occur.◮ It is important that such commands are executed in a suitable

time.

One of the key concepts in the division between the variousembedded systems is the so-called "real time".

◮ a real-time system is a system composed of hardware andsoftware able to provide an answer or perform an operationwithin specified time constraints (deadlines).

An algorithm is called:◮ logically correct: if for each input it produces the expected

output;◮ temporally correct: if it produces the output by a given

deadline.

An algorithm is called Real Time if it is logically and temporallycorrect; [J. Stankovic,“Misconceptions of Real-Time Computing”, IEEE Computer,

1988]

Université Grenoble Alpes - 15/55

Page 19: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Real-Time Systems

Minicomputers, particularly in the 1970s were builtinto dedicated embedded systems with increasedneed for low-latency priority-driven responses toimportant interactions with incoming data.When the MOS Technology 6502 (Commodore 64and Apple II), and later when the Motorola 68000(Macintosh, Atari ST, and Commodore Amiga)were popular, anybody could use their home com-puter as a real-time system.The possibility to deactivate other interrupts al-lowed for hard-coded loops with defined timing,and the low interrupt latency allowed the imple-mentation of a real-time operating system, givingthe user interface and the disk drives lower prioritythan the real-time thread.

Some History

Université Grenoble Alpes - 16/55

Page 20: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Real-Time Systems

In common language: real time=fast. That is misleading!Some thoughts

High-performance computing does not mean real-time.◮ Real-time system are usually optimized with respect to given

robustness specifications.

◮ Logical correctness depends on implementation aspects.◮ Temporal correctness depends on many HW and SW aspects:

BIOS, OS, bus management, IRQ handling...

Average performance says nothing about correctness◮ logical and temporal correctness need to be met in all cases

and not in average.

“A statistician drowned while crossing a stream that was,

on average, 6 inches deep.”

A real-time system needs to be predictable.◮ real-time systems need the design of specific HW and SW

architectures.Université Grenoble Alpes - 17/55

Page 21: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Properties of Real-time Systems◮ Strict timing constraints

◮ Responsiveness (deadlines), periodicity (sampling rate)◮ Time constraints MUST be verified

◮ Application-specific design◮ Embedded systems◮ Well-known operating environment

◮ High reliability◮ Thoroughly-tested components◮ Fault tolerant

Some examples of application:◮ Control Systems

◮ Manufacturing◮ Automotive: Example Anti-lock Braking System (ABS). The

systems needs to be almost instantaneous.◮ Transaction systems

◮ E-commerce, Wireless phones.◮ Multimedia

◮ Computer games, streaming services.

Université Grenoble Alpes - 18/55

Page 22: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Design of a Real-Time System

Specification

Implementation

Specificationis met?

Verification

Yes

No

END

Université Grenoble Alpes - 19/55

Page 23: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - 19/55

Page 24: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Specification

◮ Reliability

◮ Sampling rate

◮ Response time

−→

−→

−→

◮ Replication

◮ Periodicity

◮ Deadline

Examples of constraints:

◮ Timing constraints◮ A task must complete its execution within given time frames

(example: task periodicity or deadline)

◮ Exclusion constraints◮ A task must execute a code region without being interrupted

(example: a task needs exclusive access to a shared resource)

◮ Precedence constraints◮ A task must complete its execution before another task can

start (example: a data exchange must take place between thetasks).

Université Grenoble Alpes - 20/55

Page 25: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Specification1

Where do timing constraints come from?◮ Laws of physics

◮ Bodies in motion: arm movements in a robotic system◮ Inertia of the eye: minimal frame rate in movies

◮ Control Theory◮ Prescribed sampling time

◮ Component limitations◮ Sensors and actuators: minimal time inbetween operations

How critical are the constraints?Hard Constraints

◮ If the system fails to fulfill a timing constraint, thecomputational results is useless.

Noncritical: system can still function with reducedperformance (diagnostics)Critical: system cannot continue to function (Flight controlsystems)Safety critical: can cause serious damage or catastrophicevents (Braking systems (ABS); defense system)

1Source: Prof. Jan Jonsson. Department of Computer Science andEngineering, Chalmers University of Technology. Real-Time Systems

Université Grenoble Alpes - 21/55

Page 26: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Specification

How critical are the constraints?

Soft Constraints◮ Single failures to fulfill a timing constraint is acceptable, but

the usefulness of the computational result is reduced.

Booking systemsE-commerce: stock trading, eBayMultimedia: video-on-demand, computer games, VirtualReality

Statistical guarantees often suffice for these systems!

Université Grenoble Alpes - 22/55

Page 27: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Classification of Real-time SystemsIt is useful to define the notion of Quality of Service (QoS) of aservice.

It is the description or measurement of the overall performance of aservice.

QoS

In a Real Time system, one can define two parameters to describethe QoS:

◮ logical correctness ratio

LCR : =#Correct Results

#Tests

◮ temporal correctness ratio

TCR : =#Results Elaborated within the Deadline

#Tests

Université Grenoble Alpes - 23/55

Page 28: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Hard Real Time

A system is called Hard Real Time if and only if it meets both:

◮ the logical correctness constraint

◮ the temporal correctness constraint

Hard Real Time

HardReal Time ⇐⇒ LCR = TCR = 1

A Hard Real Time system needs to be used when even thesporadic violation of the logical and temporal correctnessconstraints can jeopardize the safety of people or objects, i.e.,nuclear plants, chemical plants...

Université Grenoble Alpes - 24/55

Page 29: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Soft Real Time

Whenever Hard Real Time is not needed, one can rely on Soft RealTime.

A system is called Soft Real Time if and only it can:

◮ violate the logical correctness constraint

◮ violate temporal correctness constraint

Soft Real Time

Soft Real Time ⇐⇒ max{LCR, TCR} < 1

Different Soft Real Time systems can be classified according to thevalue of max{LCR, TCR}.

◮ The larger the value of max{LCR, TCR}, the better.

Université Grenoble Alpes - 25/55

Page 30: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - 25/55

Page 31: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

ImplementationCritical choices to be made at design time:

◮ Application software:◮ Programming language

◮ Determines run-time performance and code size◮ Determines productivity, maintainability and reliability◮ Determines degree of timing verification that is possible

◮ Concurrent programming◮ Program is structured as multiple sequential tasks◮ Models the execution of multiple sequential task

simultaneously◮ Determines degree of timing verification that is possible

◮ Hardware architecture:◮ Single or multiprocessor architecture

◮ Determines degree of true parallelism that can be exploited◮ Microprocessor family

◮ RISC processor (pipelines, caches, support for multiprocessors)◮ Microcontroller (no, or very simple, pipelines/caches)◮ Determines cost and run-time performance◮ Determines difficulty in worst-case execution time

Université Grenoble Alpes - 26/55

Page 32: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - 26/55

Page 33: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

VerificationHow do we verify the system?

◮ Ad hoc testing:◮ Run the system for “a while” and let the absence of failures

“prove” the correctness◮ fast method that indicates that “everything seems to work”◮ pathological cases can be overlooked during testing◮ too frequently used as the only method in industrial design

◮ Exhaustive testing◮ Verify all combinations of input data, time and faults

◮ considers all possible cases◮ requires an unreasonable amount of time for testing

◮ Formal analysis of the implementation:◮ Verify logical correctness using proof machine

◮ requires dedicated description language◮ abstraction level very high (often implementation independent)

Université Grenoble Alpes - 27/55

Page 34: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - /55

Page 35: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Microcontrollers

A digital electronic device containing a RISCmicroprocessor along with some dedicated pe-ripherals.

Microcontroller (MCU)

The first microcontroller is the TMS 1000 cre-ated by TI engineers Gary Boone and MichaelCochran in 1971. The TMS 1000 becamecommercially available in 1974. It combinedread-only memory, read/write memory, proces-sor and clock on one chip and was targeted atembedded systems. The TMS 1000 was usedin Texas Instruments’ own Speak & Spell edu-cational toy, and in the electronic game Simon.

Historical aspects

MCUs are largely diffused on the market of embedded systems.

Université Grenoble Alpes - 28/55

Page 36: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

MicrocontrollersMicrocontrollers are in general used to accomplish the following tasks

Requirements Characteristics Benefits

Input and Outputaccess

I/O ports with bitby bit addressing

Interconnection w/devs.

Com. w/ext. pe-ripherals

Serial ports, SPI,I2C, CAN, etc.

Extension via ext. pe-ripherals

Motor and Act.Control

Timers, Counters,PWM

Easy programming

Logic and Se-quences

Jumps, logic in-structions

Easy programming oflogic and seq. routines

Reaction to exter-nal events

IRQs priority han-dling

Possibility to go RealTime!

Data Acquisition ADC converters Easy to use as a replace-ment of older technolo-gies

Université Grenoble Alpes - 29/55

Page 37: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Microcontrollers

◮ As opposed to dedicated controllers, microcontrollers:◮ can execute complex tasks;◮ can communicate with other devices;◮ can be reprogrammed;◮ have advanced energy saving features.

Adopted in a very large family of applications.

Université Grenoble Alpes - 30/55

Page 38: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - 30/55

Page 39: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Characteristics

PIC18F8XX2 Logic Layout. Source: Microchip R©

Université Grenoble Alpes - 31/55

Page 40: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Characteristics

PIC18F8XX2 Physical Layout. Source: Microchip R©

Université Grenoble Alpes - 32/55

Page 41: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Characteristics

PIC18F8XX2 Instruction Set. Source: Microchip R©

Université Grenoble Alpes - 33/55

Page 42: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - 33/55

Page 43: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

PeripheralsIn general a microcontroller comes with:

◮ ADC converters

◮ PWM outputs

◮ Timers

◮ GPIO (General Purpose Input Output)

◮ Communication ports: USART, I2S, SPI, I2C, USB

Advanced models come equipped with more complex interfaces as:WiFi, ZigBee, Ethernet, Touch Screen, and LCD.

Université Grenoble Alpes - 34/55

Page 44: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

ADC

PIC18F8XX2 ADC. Source: Microchip R©

Université Grenoble Alpes - 35/55

Page 45: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Reset

The program flow can be controlled by acting on the programcounter.2

Any µC is equipped with specific tools to reset the programcounter.

◮ Power-on reset (POR). Present in all µCs and it is called anytime the system is powered on;

◮ External reset (RESET). Present in all µCs and can beactivated manually (reset button);

◮ Watchdog. The system polls this PIN periodically and if it isnot suitably set, a reset is enforced;

◮ Clock monitor reset. The system checks the clock status andenforces a reset if the clock does not run properly.

2The program counter is a register in a computer processor that containsthe address (location) of the instruction being executed at the current time. Aseach instruction gets fetched, the program counter increases its stored value by1.

Université Grenoble Alpes - 36/55

Page 46: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Counters and Timers

◮ Counter◮ It converts the number of input cycles to a binary value using

an array of triggers.

◮ Timer◮ It is a counter interconnected to the system clock. Timers

operate independently of software execution, acting in thebackground without slowing down the code at all.

◮ in general, timers have a prescale register, which divides theclock so that the counter increments at a slower rate.

Timers are used for generating accuracy actions, for example,creating specific time delays between two operations.

◮ Definition of schedulers: Real-time implementation!

Université Grenoble Alpes - 37/55

Page 47: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Interrupts

◮ Program flow can be controlled via interrupts. Those enable tochange the program counter when some events occur.

◮ Processor first saves program counter and/or other registers ofCPU and then loads a vector address into the program counter.

◮ Vector address provides either the Interrupt Service Routine(ISR) address to the processor for the interrupt source or giveninterrupt type.

◮ Different events can have different priorities.

Example of events:

◮ Timer/Counter overflow

◮ PWM Counter overflow

◮ Reset

◮ Software interrupt

◮ External events

Université Grenoble Alpes - 38/55

Page 48: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Interrupts

ATmega328 Interrupt Vector Table. Source Microchip R©

Université Grenoble Alpes - 39/55

Page 49: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

I/O Ports

◮ I/O ports allow the µC to communicate with externalsperipherals.

PIC18F8XX2 ADC. Source: Microchip R©

Université Grenoble Alpes - 40/55

Page 50: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Serial Communication

◮ Serial communication follows a simple protocol to ensurecorrect transmission. A serial data consists of:

◮ Data Bits◮ Synchronization Bits (The sync bits are start and stop bits to

indicate the start and end of transmission.)◮ Parity Bits (The parity bit, used for error checking)

◮ The baud rate, transmission speed, is also part of the protocol.It is important that the sender and the receiver should havethe same baud rate. The rates have been standardized to anyof these values:

◮ 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200

µC are equipped with a USART (UniversalSynchronous/Asynchronous Receiver Transmitter) module.

◮ USART is an interface that can be programmed tocommunicate asynchronously or synchronously.Microcontrollers have two pins TXD (transmit) and RXD(receive).

Université Grenoble Alpes - 41/55

Page 51: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Inter Integrated Circuit (I2C)◮ The I2C bus is a very popular and powerful bus used for

communication between a master (or multiple masters) and asingle or multiple slave devices;

◮ The I2C bus was designed by Philips in the early ’80s to alloweasy communication between components on the same circuitboard.

Electrical Characteristics◮ I2C uses an open-drain/open-collector with an input buffer on

the same line, which allows a single data line to be used forbidirectional data flow.

Example I2C Bus. Source: Texas Instrument R©Université Grenoble Alpes - 42/55

Page 52: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

I2C

◮ low-speed mode 10 kbit/s

◮ standard mode 100 kbit/s

◮ Fast mode 400 kbit/s

◮ Fast mode plus (Fm+) 1 Mbit/s

◮ High Speed Mode 3.4 Mbit/s

(Multi) Master-Slave architecture:

◮ Master: Generates the clock and starts the communication

◮ Slave: Receives the clock from the Master and responds whenaddressed by the Master.

The general procedure for a master to access a slave device is thefollowing:

Université Grenoble Alpes - 43/55

Page 53: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

I2C

1. Suppose a master wants to send data to a slave:◮ Master-transmitter sends a START condition and addresses

the slave-receiver◮ Master-transmitter sends data to slave-receiver◮ Master-transmitter terminates the transfer with a STOP

condition

2. If a master wants to receive/read data from a slave:◮ Master-receiver sends a START condition and addresses the

slave-transmitter◮ Master-receiver sends the requested register to read to

slave-transmitter◮ Master-receiver receives data from the slave-transmitter◮ Master-receiver terminates the transfer with a STOP condition

Université Grenoble Alpes - 44/55

Page 54: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

I2C-START and STOP ConditionsI2C communication is initiated by the master sending a STARTcondition and terminated by the master sending a STOP condition.

◮ A high-to-low transition on the SDA line while the SCL is highdefines a START condition.

◮ A low-to-high transition on the SDA line while the SCL is highdefines a STOP condition.

Example of START and STOP Condition. Source: Texas Instrument R©

Université Grenoble Alpes - 45/55

Page 55: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

I2C-Data Validity and Byte Format

◮ One data bit is transferred during each clock pulse of the SCL.

◮ One byte is comprised of eight bits on the SDA line.

◮ A byte may either be a device address, register address, ordata written to or read from a slave.

◮ Data is transferred Most Significant Bit (MSB) first. Anynumber of data bytes can be transferred from the master toslave between the START and STOP conditions.

◮ Data on the SDA line must remain stable during the highphase of the clock period, as changes in the data line when theSCL is high are interpreted as control commands (START orSTOP).

Université Grenoble Alpes - 46/55

Page 56: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

I2C-Data Validity and Byte Format◮ Each byte of data (including the address byte) is followed by

one ACK bit from the receive;◮ The ACK bit allows the receiver to communicate to the

transmitter that the byte was successfully received. To send anACK bit, the receiver shall pull down the SDA line during thelow phase of the ACK/NACK-related clock period;

Example of Single Byte Data Transfer. Source: Texas Instrument R©

Université Grenoble Alpes - 47/55

Page 57: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

I2C- ACK and NACK

◮ When the SDA line remains high during theACK/NACK-related clock period, this is interpreted as aNACK.

Example NACK Waveform. Source: Texas Instrument R©

There are several conditions that lead to the generation of a NACK.Check Texas Instrument R© for more details!

Université Grenoble Alpes - 48/55

Page 58: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

PWM Modulation

Motor Controlled via a“H-bridge”

Closed switches Voltage across mo-tor

S1, S4 positive

S2, S3 negative

S1, S3 zero (braking)

S2, S4 zero (braking)

none or one open circuit

The settings not covered in the table (S1 and S2 closed, or S3 andS4 closed, or any set of three or four switches closed) lead to ashort circuit and must be avoided!

The diodes prevent from voltage spikes (flyback.)

Université Grenoble Alpes - 49/55

Page 59: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

PWM ModulationH-bridge of the L293D

L293x Quadruple Half-H Drivers. Source: Texas Instrument R©

Université Grenoble Alpes - 50/55

Page 60: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

PWM Modulation◮ Pulse Width Modulation (PWM) uses digital signals to control

power applications◮ The idea consists of modulating the power transferred to the

load by acting on the duty cycle.

Consider a rectangular pulse wave f with period T and duty cycleD = TON

T. Then, the average value of f reads

f =1

T

∫T

0

f(s)ds = fmaxD + (1−D)fmin

From this, the average value of the signal is directly dependent onthe duty cycle D.

Université Grenoble Alpes - 51/55

Page 61: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

PWM Modulation

Intersective PWM. Source Mathworks R©.

The simplest way to generate a PWM signal is the intersectivemethod.

◮ When the value of the reference signal (red) is larger than themodulation waveform (blue), the PWM signal (blue-bottom) isin the high state, otherwise it is in the low state.

The switching frequency needs to be large enough to keep theripple limited.

Université Grenoble Alpes - 52/55

Page 62: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

PWM Modulation

In the case of the H-Bridge, four signals are in needed in principle.However, to avoid short circuit, the only option is as follows:

◮ S1 = S4

◮ S2 = S3

◮ S2 = S1

Hence, only one PWM signal is needed! The value of S1 can beused to determine the sign of the voltage.

◮ An alternative clever idea consists of using the PWM signal tocontrol the enable pin and set the bridge inputs to select thesign of the voltage.

Université Grenoble Alpes - 53/55

Page 63: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Outline

1. Embedded Systems

◮ Processors in embedded systemsComputer Architectures Basics

2. Real-time Systems

◮ SpecificationClassification of Real-time Systems

◮ Implementation

◮ Verification

3. Microcontrollers

◮ Characteristics

◮ Peripherals

4. Arduino

Université Grenoble Alpes - /55

Page 64: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Arduino

◮ Arduino is an open-source hardware and software company,project and user community that designs and manufacturessingle-board microcontrollers and microcontroller kits forbuilding digital devices and interactive objects that can senseand control objects in the physical and digital world.

◮ 2001: Olivetti and Telecom Italia creates the Interaction Design

Institute of Ivrea;

◮ 2005: Massimo Banzi creates Arduino as an electronicprototyping tool

◮ today: Arduino has become a worldwide success and it isnowadays a very powerful tool.

Some History

Université Grenoble Alpes - 54/55

Page 65: Embedded Systems · A control system needs to check the plant status and provide specific commands when some conditions occur. It is important that such commands are executed in

Arduino

Why has Arduino become so popular?◮ Software and hardware is open◮ Architecture KISS (Keep It Simple, Stupid!)◮ easy to program, nasty things are hidden, i.e., objects,

pointers, etc...◮ a lot of library developed by communities and manufacturers

What’s wrong with it?◮ Standards are very weak and not all the HW available on the

market is of high quality

Feel free to go and search. There is a world to be discovered outthere! Arduino.

Université Grenoble Alpes - 55/55