0% found this document useful (0 votes)
28 views

3rd Module Microcontroller and Embedded System

The document discusses various sensors and actuators used in embedded systems including accelerometers, ambient light sensors, LEDs, 7-segment displays, optocouplers, stepper motors, and push buttons. It provides details on how each component works and can be interfaced with an embedded system.

Uploaded by

Madhu Ck
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

3rd Module Microcontroller and Embedded System

The document discusses various sensors and actuators used in embedded systems including accelerometers, ambient light sensors, LEDs, 7-segment displays, optocouplers, stepper motors, and push buttons. It provides details on how each component works and can be interfaced with an embedded system.

Uploaded by

Madhu Ck
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

SENSORS AND ACTUATORS

» An embedded system is in constant interaction with the Real world, and the
controlling/ monitoring functions, executed by the embedded system is
achieved in accordance with the changes happening to the Real world. The
changes in system environment or variables are detected by the sensors
connected to the input port of the embedded system.

» A sensor is a transducer device that converts energy from one form to


another, for any measurement or control purpose.

 Sensor which counts steps for pedometer functionality is an


Accelerometer sensor.

 Sensor used in smart watch devices to measure the high intensity is an


Ambient Light Sensor (ALS).

MCE, CSE, 1
» If the embedded system is designed for any controlling purpose, the system
will produce some changes in the controlling variable to bring the controlled
variable to the desired value. It is achieved through an actuator connected to
the output port of the embedded system.

» Actuator is a form of transducer device (mechanical or electrical) which


converts signals to corresponding physical action (motion). Actuator acts as an
output device.

 Smart watches use Ambient Light Sensor to detect the surrounding light
intensity and uses an electrical/ electronic actuator circuit to adjust the
screen brightness.

MP, CSE, VCET 91


» If the embedded system is designed for monitoring purpose only, then there is
no need for including an actuator in the system.
» For example, take the case of an ECG machine. It is designed to monitor the heart beat
status of a patient and it cannot impose a control over the patient's heart beat and its
order. The sensors used here are the different electrode sets connected to the body of the
patient. The variations are captured and presented to the user (may be a doctor) through
a visual display or some printed chart.

Sensors Actuators
1. Sensor is an input device 1. Actuator is an output device
1. Convert a physical parameter to an 1. Convert an electrical signal to a physical
electrical output output
1. A device that detects events or changes in 1. A component of a machine that is
the environment and send the information responsible for moving and controlling
to another electronic device mechanisms
1. Sensor help to monitor the changes in the 1. Actuator helps to control the environment
environment MCE, CSE or physical changes 2
» The I/O Subsystem:

» The I/O subsystem of the embedded system facilitates the interaction of the
embedded system with the external world. As mentioned earlier the interaction
happens through the sensors and actuators connected to the input and output
ports respectively of the embedded system.

» Light Emitting Diode (LED): LED is an important output device for visual
indication in any embedded system. LED can be used as an indicator for the
status of various signals or situations.

» Typical examples are indicating the presence of power conditions like 'Device
ON', 'Battery Low' or 'Charging of Battery' for a battery operated handheld
embedded devices.

MCE, CSE 3
» Light Emitting Diode is a p-n junction diode and it contains an anode and a
cathode. For proper functioning of the LED, the anode of it should be
connected to +ve terminal of the supply voltage and cathode to the –ve
terminal of supply voltage. A resister is used in series between the power
supply and the LED to limit the current through the LED.

» The ideal LED interfacing circuit is shown in the following Figure.

» LEDs can be interfaced to the port pin of a processor/


controller in two ways.

» Anode is directly connected to the port pin and the port


pin drives the LED.

» Port pin is at logic High (Logic '1').


» Cathode of the LED is connected to the port pin and the anode to the supply
voltage. LED is turned on when the port pin is at logic Low (Logic '0').
MCE, CSE 4
» 7-Segment LED Display: The 7-segment LED display is an output device used
for displaying alpha-numeric characters.

» It contains 8 light-emitting diode (LED) segments arranged in a special form.

» Out of the 8 LED segments, 7 are used for displaying alpha-numeric characters
and 1 is used for representing ‘decimal point'.

» The following Figure explains the arrangement of LED segments in 7-segment


LED display.

» The LED segments are named A to G and


the 'decimal point LED segment is named
as DP.

» For displaying 3, the segments A, B, C, D,


G are lit.

MCE, CSE 5
» The 7-segment LED displays are available in two different configurations,
namely; Common Anode and Common Cathode.

» In common anode configuration, the anodes of the 8 segments are


connected commonly

» In common cathode configuration, the 8 LED segments share a common


cathode line.

MCE, CSE 6
» Optocoupler: Optocoupler is a solid state device to isolate two parts of a
circuit. Optocoupler combines an LED and a photo-transistor in a single
housing (package).

» In electronic circuits, an optocoupler is used for –

» suppressing interference in data communication,

» circuit isolation,

» high voltage separation,

» simultaneous separation and signal intensification, etc.

» Optocouplers can be used in either input circuits or in output circuits.


MCE, CSE 7
» The following Figure illustrates the usage of optocoupler in input circuit and
output circuit of an embedded system with a microcontroller as the system
core.

» Optocoupler is available as ICs from different semiconductor manufacturers.


The MCT2M IC from Fairchild semiconductor is an example for optocoupler
IC.

MCE, CSE 8
» Stepper Motor: A stepper motor is an electro-mechanical device which
generates discrete displacement (motion) in response, to de electrical signals.

» A stepper motor produces discrete rotation in response to the DC voltage


applied to it.

» Stepper motors are widely used in –

» industrial embedded applications,

» consumer electronic products and robotics control systems.

» The paper feed mechanism of a printer/ fax makes use of stepper motors for
its functioning.

MCE, CSE 9
» Based on the coil winding arrangements, a two-phase stepper motor is
classified into two. They are:

» Unipolar: A unipolar stepper motor contains two windings per phase.

» The direction of rotation (clockwise or anticlockwise) of a stepper motor is


controlled by changing the direction of current flow.

» The coils are represented as A, B, C and D.

» Coils A and C carry current in opposite directions for phase 1.

» Similarly, B and D carry current in opposite directions for phase 2.

» Bipolar: A bipolar stepper motor contains single winding per phase.

» For reversing the motor rotation the current flow through the windings is
reversed dynamically.

» It requires complex circuitry for current flow reversal.


MCE, CSE 10
» The stepping of stepper motor can be implemented in different ways by
changing the sequence of activation of the stator windings.

» The different stepping modes supported by stepper motor are explained below:

» Full Step Wave Step Half Step

MCE, CSE 11
» The following Figure shows the stator winding details of Stepper motor:

MCE, CSE 12
» ULN2803 is an octal peripheral driver array available from Texas Instruments
and ST microelectronics for driving a 5V stepper motor.

» Simple driving circuit can also be built using transistors.

» The following circuit diagram illustrates the interfacing of a stepper motor


through a driver circuit connected to the port pins of a microcontroller/
processor.

MCE, CSE 13
» Push Button Switch: Push button switch is an input device. Push button switch
comes in two configurations, namely 'Push to Make' and 'Push to Break'.

» In the 'Push to Make' configuration, the switch is in the open state and it makes
a circuit contact when it is pushed or pressed.

» In the 'Push to Break' configuration, the switch is in the closed state and it
breaks the circuit contact when it is pushed or pressed.

» The push button stays in the 'closed' (for Push to Make type) or 'open' (For
Push to Break type) state.

» Push button is used for generating a momentary pulse. In embedded application


push button is generally used as reset and start switch and pulse generator. The
Push button is normally connected to the port pin of the host processor/
controller.

» Depending on the way in which the push button interfaced to the controller, it
MCE, CSE 14
» Push button is used for generating a momentary pulse.

» In embedded application push button is generally used as reset and start switch
and pulse generator. The Push button is normally connected to the port pin of
the host processor/ controller.

» Depending on the way in which the push button interfaced to the controller, it
can generate either a 'HIGH' pulse or a 'LOW' pulse.

» The following Figure Illustrates how the push button can be used for
generating 'LOW' and 'HIGH' pulses.

MCE, CSE 15
» Keyboard: Keyboard is an input device 'HIGH' Pulse generator for user
interfacing.

» If the number of keys required is very limited, push button switches can be
used and they can be directly interfaced to the port pins for reading.

 However, there may be situations demanding a large number of keys for user
input (e.g. PDA device with alpha-numeric keypad for user data entry).

 In such situations it may not be possible to interface each keys to a port pin
due to the limitation in the number of general purpose port pins available
for the processor/ controller in use and moreover it is wastage of port pins.

 Matrix keyboard is an optimum solution for handling large key requirement.


It greatly reduces the number of interface connections.

MCE, CSE 16
» For example, for interfacing 16 keys, in the direct interfacing technique, 16
port pins are required, whereas in the matrix keyboard only 8 lines are
required.

» The 16 keys are arranged in a 4 column x 4 Row matrix. The following Figure
illustrates the connection o keys in a matrix keyboard.

MCE, CSE 17
» In a matrix keyboard, the keys are arranged in matrix fashion. For detecting a
key press, the keyboard uses the scanning technique, where each row of the
matrix is pulled low and the columns are read. After reading the status of each
columns corresponding to a row, the row is pulled high and the next row is
pulled low and the status of the columns are read.

» This process is repeated until the scanning for all rows are completed. When a
row is pulled low and if a key connected to the row is pressed, reading the
column to which the key is connected will give logic 0. Since keys are
mechanical devices, proper key de-bouncing technique should be applied.

MCE, CSE 18
EMBEDDED FIRMWARE
» Embedded firmware refers to the control algorithm (Program instructions)
and or the configuration settings that an embedded system developer dumps
into the code (Program) memory of the embedded system. It is an un-
avoidable part of an embedded system.

» There are various methods available for developing the embedded firmware.
They are listed below:

1. Write the program in high level languages like Embedded C/ C++ using an
Integrated Development Environment (IDE)

» The IDE will contain a editor, compiler, linker, debugger, simulator, etc.

MCE, CSE 19
» IDEs are different for different family of processors/ controllers.

» For example, Keil microvision3 IDE is used for all family member of 8051
microcontroller, since it contains the generic 8051 compiler C51.

2. Write the program in Assembly language using the instructions supported by


your application's target processor/ controller.

» The instruction set for each family of processor/ controller is different and the
program written in either of the methods given above should be converted into
a processor understandable machine code before loading it into the program
memory.

» The process of converting the program written in either a high level language
or processor/ controller specific Assembly code to machine readable binary
code is called 'HEX File Creation'.

MCE, CSE 20
» The methods used for 'HEX File Creation' is different depending on the
programming techniques used.

» If the program is written in Embedded C/ C++ using an IDE, the cross


compiler included in the IDE converts it into corresponding processor/
controller understandable 'HEX File'.

» If you are following the Assembly language based programming technique,


you can use the utilities supplied by the processor/ controller vendors to
convert the source code into 'HEX File'.

» Also third party tools are available, which may be of free of cost, for this
conversion.

MCE, CSE 21
» For a beginner in the embedded software field, it is strongly recommended to
use the high level language based development technique. The reasons for this
being:

» Writing codes in a high level language is easy, the code written in high level
language is highly portable which means you can use the same code to run
on different processor/ controller with little or less modification. The only
thing you need to do is re-compile the program with the required processor's
IDE, after replacing the include files for that particular processor.

» Also the programs written in high level languages are not developer
dependent. Any skilled programmer can trace out the functionalities of the
program by just having a look at the program. It will be much easier if the
source code contains necessary comments and documentation lines. It is
very easy to debug and the overall system development time will be
reduced to a greater extent. MCE, CSE 22
» The embedded software development process in assembly language is tedious
and time consuming. The developer needs to know about all the instruction sets
of the processor/ controller or at least s/he should carry an instruction set
reference manual with her/ him. A programmer using assembly language
technique writes the program according to his/ her view and taste. Often he/
she may be writing a method or functionality which can be achieved through a
single instruction as an experienced person's point of view, by two or three
instructions in his/ her own style. So the program will be highly dependent on
the developer. It is very difficult for a second person to understand the code
written in Assembly even if it is well documented.

MCE, CSE 23
» The super loop based task execution model for firmware executes the tasks
sequentially in order in which the tasks are listed within the loop. Here every
task is repeated at regular intervals and the task execution is non-real time.

» But, certain applications demand time critical response to tasks/ events and
delay in the response may be catastrophic.
» Examples: Flight control systems, Air bag control, Anti-lock Brake Systems
(ABS) for vehicles, Nuclear monitoring devices, etc.

» In embedded systems, the time critical response for tasks/ events may be
addressed by –
» Assigning priority to tasks and execute the high priority task.

» Dynamically change the priorities of tasks, if required on a need basis.

» The introduction of operating system based firmware execution in embedded


devices can address these needs to a greater extent.
MCE, CSE 24
OPERATING SYSTEM BASICS
» The Operating System (OS) acts as a bridge between the user applications/
tasks and the underlying system resources through a set of system
functionalities and services.

» The primary functions of an operating systems are –

» Make the system convenient to use

» Organize and manage the system resources efficiently and correctly.

MCE, CSE 25
» The following Figure gives an insight into the basic components of an
operating system and their interfaces with rest of the world.

User Applications
Application Programming
Interface (API)
Memory Management

Kernel Services
Process Management

Time Management

File System Management


I/O System Management
Device Driver
Interface
Underlying Hardware

MCE, CSE 26
» The Kernel:

» The kernel is the core of the operating system. It is responsible for managing
the system resources and the communication among the hardware and other
system services.

» Kernel acts as the abstraction layer between system resources and user
applications.

» Kernel contains a set of system libraries and services.

» For a general purpose OS, the kernel contains different services like memory
management, process management, time management, file system
management, I/O system management.

MCE, CSE 26
» Process Management: deals with managing the process/ tasks.

» Process management includes –

» setting up a memory for the process

» loading process code into memory

» allocating system resources

» scheduling and managing the execution of the process

» setting up and managing Process Control Block (PCB)

» inter process communication and synchronization

» process termination/ deletion, etc.

MCE, CSE 27
» Primary Memory Management: refers to a volatile memory (RAM), where
processes are loaded and variables and shared data are stored.

» The Memory Management Unit (MMU) of the kernel is responsible for –

» Keeping a track of which part of the memory area is currently used by


which process

» Allocating and De-allocating memory space on a need basis.

MCE, CSE 28
» File System Management: File is a collection of related information. A file
could be a program (source code or executable), text files, image files, word
documents, audio/ video files, etc.

» A file system management service of kernel is responsible for –

» The creation, deletion and alteration of files

» Creation, deletion, and alteration of directories

» Saving of files in the secondary storage memory

» Providing automatic allocation of file space based on the amount of


free running space available

» Providing flexible naming conversion for the files.

MCE, CSE 29
» I/O System (Device) Management: Kernel is responsible for routing the I/O
requests coming from different user applications to the appropriate I/O
devices of the system.

» In a well structured OS, direct access to I/O devices is not allowed; access to
them is establish through Application Programming Interface (API).

» The kernel maintains list of all the I/O devices of the system.

» „Device Manager‟ of the kernel is responsible for handling all I/O related
operations.

» The Device Manager is responsible for –

» Loading and unloading of device drivers

» Exchanging information and the system specific control signals to and


from the device.

MCE, CSE 30
» Secondary Storage Management: deals with managing the secondary storage
memory devices (if any) connected to the system.

» Secondary memory is used as backup medium for programs and data, as main
memory is volatile.

» In most of the systems secondary storage is kept in disks (hard disks).

» The secondary storage management service of kernel deals with –

» Disk storage allocation

» Disk scheduling

» Free disk space management

MCE, CSE 31
» Protection Systems: Modern operating systems are designed in such way to
support multiple users with different levels of access permissions.

» The protection deals with implementing the security policies to restrict the
access of system resources and particular user by different application or
processes and different user.

» Interrupt Handler: Kernel provides interrupt handler mechanism for all


external/ internal interrupt generated by the system.

MCE, CSE 32
» The important services offered by the kernel of an OS:

» Kernel Space and User Space: The program code corresponding to the
kernel applications/ services are kept in a contiguous area of primary
(working) memory and is protected from the un-authorized access by user
programs/ applications.

 The memory space at which the kernel code is located is known as „Kernel
Space‟. All user applications are loaded to a specific area of primary
memory and this memory area is referred as „User Space‟.

 The partitioning of memory into kernel and user space is purely Operating
System dependent.

 Most of the operating systems keep the kernel application code in main
memory and it is not swapped out into the secondary memory.

MCE, CSE 33
» Monolithic Kernel and Microkernel: Kernel forms the heart of OS. Different
approaches are adopted for building an operating system kernel. Based on the
kernel design, kernels can be classified into „Monolithic‟ and „Micro‟.
» Monolithic Kernel: In monolithic kernel
architecture, all kernel services run in the
kernel space. All kernel modules run
within the same memory space under a
single kernel thread.

» The major drawback of monolithic kernel


is that any error or failure in any one of
the kernel modules leads to the crashing of
the entire kernel application.

 LINUX, SOLARIS, MS-DOS kernels


MCE, CSE 34
» Microkernel: The microkernel design incorporates only essential set of
operating system services into the kernel. The rest of the operating systems
services are implemented in program known as „Servers‟ which runs in user
space. The memory management, timer systems and interrupt handlers are the
essential services, which forms the part of the microkernel.

» The benefits of micro kernel based designs are –

 Robustness: If a problem is encountered in any of the services, which runs


as a server can be reconfigured and restarted without the restarting the
entire OS. Here chances of corruption of kernel services are ideally zero.

 Configurability: Any services, which runs as a server application can be


changed without the need to restart the whole system. This makes the
system dynamically configurable.

MCE, CSE 35
TYPES OF OPERATING SYSTEMS
» Depending on the type of kernel and kernel services, purpose and type of
computing system, Operating Systems are classified into different types.

» General Purpose Operating System (GPOS):

» The operating systems, which are deployed in general computing systems, are
referred as GPOS. The GPOSs are often quite non-deterministic in behavior.

» Windows 10/8.x/XP/MS-DOS, etc., are examples of GPIOs.

MCE, CSE 36
» Real Time Operating System (RTOS):

» Real Time implies deterministic in timing behavior.

» RTOS services consumes only known and expected amounts of time


regardless the number of services.

» RTOS implements policies and rules concerning time-critical allocation of a


system‟s resources.

» RTOS decides which applications should run in which order and how much
time needs to be allocated for each application.

 Windows Embedded Compact, QNX, VxWorks MicroC/OS-II, etc., are


examples of RTOSs.

MCE, CSE 37
» The Real-Time kernel: The kernel of a Real-Time OS is referred as Real-
Time kernel.

» The Real-Time kernel is highly specialized and it contains only the minimal
set of services required for running user applications/ tasks.

» The basic functions of a Real-Time kernel are listed below:


» Task/ Process management

» Task/ Process scheduling

» Task/ Process synchronization

» Error/ Exception handling

» Memory management

» Interrupt handling

» Time management.

MCE, CSE 38
» Task/ Process Management: Deals with setting up the memory space for the
tasks, loading the task‟s code into the memory space, allocating system
resources and setting up a Task Control Block (TCB) for the task and
task/process termination/deletion.

 A Task Control Block (TCB) is used for holding the information


corresponding to a task. TCB usually contains the following set of
information:

 Task ID: Task Identification Number

 Task State: The current state of the task. (E.g. State = „Ready‟ for a
task which is ready to execute)

 Task Type: Task type. Indicates what is the type for this task. The task
can be a hard real time or soft real time or background task.

MCE, CSE 39
 Task Priority: Task priority (E.g. Task priority = 1 for task with
priority = 1)

 Task Context Pointer: Context pointer. Pointer for context saving

 Task Memory Pointers: Pointers to the code memory, data memory


and stack memory for the task

 Task System Resource Pointers: Pointers to system resources


(semaphores, mutex, etc.) used by the task

 Task Pointers: Pointers to other TCBs (TCBs for preceding, next and
waiting tasks)

 Other Parameters: Other relevant task parameters.

» The parameters and implementation of the TCB is kernel dependent. The


TCB parameters vary across different kernels based on the task management
implementation.
MCE, CSE 40
» Task/ Process Scheduling: Deals with sharing the CPU among various tasks/
processes. A kernel application called „Scheduler‟ handles the task
scheduling. Scheduler is an algorithm implementation, which performs the
efficient and optimal scheduling of tasks to provide a deterministic behavior.

» Task/ Process Synchronization: Deals with synchronizing the concurrent


access of a resource, which is shared across multiple tasks and the
communication between various tasks.

MCE, CSE 41
» Error/ Exception Handling: Deals with registering and handling the errors
occurred/ exceptions rose during the execution of tasks.

 Insufficient memory, timeouts, deadlocks, deadline missing, bus error,


divide by zero, unknown instruction execution etc, are examples of
errors/exceptions.

 Errors/ Exceptions can happen at the kernel level services or at task level.

o Deadlock is an example for kernel level exception, whereas timeout is


an example for a task level exception.

MCE, CSE 42
» Errors/ Exceptions can happen at the kernel level services or at task level.

o Deadlock is an example for kernel level exception, whereas timeout is


an example for a task level exception.

 Deadlock is a situation where a set of processes are blocked


because each process is holding a resource and waiting for another
resource acquired by some other process.

 Timeouts and retry are two two techniques used together. The
tasks retries an event/ message certain number of times; if no
response is received after exhausting the limit, the feature might be
aborted.

 The OS kernel gives the information about the error in the form of a
system call (API).

MCE, CSE 43
» Memory Management: The memory management function of an RTOS
kernel is slightly different compared to the General Purpose Operating
Systems.

 In general, the memory allocation time increases depending on the size of


the block of memory need to be allocated and the state of the allocated
memory block. RTOS achieves predictable timing and deterministic
behavior, by compromising the effectiveness of memory allocation.

 RTOS generally uses „block‟ based memory allocation technique, instead


of the usual dynamic memory allocation techniques used by the GPOS.
RTOS kernel uses blocks of fixed size of dynamic memory and the block
is allocated for a task on a need basis. The blocks are stored in a „Free
buffer Queue‟.

MCE, CSE 44
 Most of the RTOS kernels allow tasks to access any of the memory blocks
without any memory protection to achieve predictable timing and avoid
the timing overheads.

 Some commercial RTOS kernels allow memory protection as optional and


the kernel enters a fail-safe mode when an illegal memory access occurs.

» The memory management function a block of fixed memory is always


allocated for tasks on need basis and it is taken as a unit. Hence, there will not
be any memory fragmentation issues.

MCE, CSE 45
» Interrupt Handling: Deals with the handling of various interrupts. Interrupts
inform the processor that an external device or an associated task requires
immediate attention of the CPU.

 Interrupts can be either Synchronous or Asynchronous.

 Interrupts which occurs in sync with the currently executing task is


known as Synchronous interrupts. Usually the software interrupts fall
under the Synchronous Interrupt category.

 Divide by zero, memory segmentation error etc are examples of


Synchronous interrupts.

 For synchronous interrupts, the interrupt handler runs in the same


context of the interrupting task.

 Interrupts which occurs at any point of execution of any task, and are
not in sync with the currently executing task are Asynchronous
MCE, CSE 46
 Interrupts which occurs at any point of execution of any task, and are
not in sync with the currently executing task are Asynchronous
interrupts.

 Timer overflow interrupts, serial data reception/ transmission


interrupts etc., are examples for asynchronous interrupts.

 For asynchronous interrupts, the interrupt handler is usually written as


separate task (depends on OS Kernel implementation) and it runs in a
different context. Hence, a context switch happens while handling the
asynchronous interrupts.

» Priority levels can be assigned to the interrupts and each interrupts can be
enabled or disabled individually. Most of the RTOS kernel implements
„Nested Interrupts‟ architecture.

MCE, CSE 47
» Time Management: Accurate time management is essential for providing
precise time reference for all applications. The time reference to kernel is
provided by a high-resolution Real Time Clock (RTC) hardware chip
(hardware timer).

 The hardware timer is programmed to interrupt the processor/ controller at


a fixed rate. This timer interrupt is referred as „Timer tick‟. The „Timer
tick‟ is taken as the timing reference by the kernel.

 The „Timer tick‟ interval may vary depending on the hardware timer.

 Usually, the „Timer tick‟ varies in the microseconds range.

 The time parameters for tasks are expressed as the multiples of the „Timer
tick‟.

MCE, CSE 48
 The System time is updated based on the „Timer tick‟.

 If the System time register is 32 bits wide and the „Timer tick‟ interval is 1
microsecond, the System time register will reset in;

232 * 10–6 / (24 * 60 * 60) = ~ 0.0497 Days = 1.19 Hours

 If the „Timer tick‟ interval is 1 millisecond, the System time register will
reset in

232 * 10–3 / (24 * 60 * 60) = 49.7 Days = ~ 50 Days

 The „Timer tick‟ interrupt is handled by the „Timer Interrupt‟ handler of


kernel.

MCE, CSE 49
» The „Timer tick‟ interrupt can be utilized for implementing the following
actions:

 Save the current context (Context of the currently executing task)

 Increment the System time register by one. Generate timing error and
reset the System time register if the timer tick count is greater than the
maximum range available for System time register.

 Update the timers implemented in kernel (Increment or decrement the


timer registers for each timer depending on the count direction setting
for each register. Increment registers with count direction setting =
„count up‟ and decrement registers with count direction setting =
„count down‟)

 Activate the periodic tasks, which are in the idle state

MCE, CSE 50
 Invoke the scheduler and schedule the tasks again based on the
scheduling algorithm

 Delete all the terminated tasks and their associated data structures
(TCBs)

 Load the context for the first task in the ready queue. Due to the re-
scheduling, the ready task might be changed to a new one from the
task, which was pre-empted by the „Timer Interrupt‟ task.

MCE, CSE 51
» Hard Real-Time: A Real Time Operating Systems which strictly adheres to
the timing constraints for a task is referred as hard real-time systems.

» A Hard Real Time system must meet the deadlines for a task without any
slippage. Missing any deadline may produce catastrophic results for Hard
Real Time Systems, including permanent data lose and irrecoverable damages
to the system/users.

 Hard real-time systems emphasize on the principle „A late answer is a


wrong answer‟.

 For example, Air bag control systems and Anti-lock Brake Systems
(ABS) of vehicles are typical examples of Hard Real Time Systems.

 Most of the Hard Real Time Systems are automatic.

MCE, CSE 52
» Soft Real-Time: Real Time Operating Systems that does not guarantee
meeting deadlines, but, offer the best effort to meet the deadline are referred
as soft real-time systems.

» Missing deadlines for tasks are acceptable if the frequency of deadline


missing is within the compliance limit of the Quality of Service (QoS).

 Soft real-time system emphasizes on the principle „A late answer is an


acceptable answer, but it could have done bit faster‟.

 Automatic Teller Machine (ATM) is a typical example of Soft Real Time


System. If the ATM takes a few seconds more than the ideal operation
time, nothing fatal happens.

MCE, CSE 53
INTEGRATION OF
HARDWARE AND FIRMWARE
» Integration of hardware and firmware deals with the embedding of firmware
into the target hardware board. It is the process of 'Embedding Intelligence' to
the product.

» The embedded processors/ controllers used in the target board may or may not
have built in code memory. For non-operating system based embedded
products, if the processor/ controller contain internal memory and the total size
of the firmware is fitting into the code memory area, the code memory is
downloaded into the target controller/ processor.

MCE, CSE 54
» If the processor/ controller does not support built in code memory or the size
of the firmware is exceeding the memory size supported by the target
processor/ controller, an external dedicated EPROM/ FLASH memory chip is
used for holding the firmware. This chip is interfaced to the processor/
controller.

» A variety of techniques are used for embedding the firmware into the target
board. The commonly used firmware embedding techniques for a non-OS
based embedded system are explained below. The non-OS based embedded
systems store the firmware either in the on-chip processor/ controller memory
or off-chip memory (FLASHI/ NVRAM, etc.).

MCE, CSE 55
» Out-of-Circuit Programming:

» Out-of-circuit programming is performed outside the target board. The


processor or memory chip into which the firmware needs to be embedded is
taken out of the target board and it is programmed with the help of a
programming device.

» The programming device is a dedicated unit which contains the necessary


hardware circuit to generate the programming signals. Most of the
programming devices available in the market are capable of programming
different family of devices.

» The programming device will be under the control of a utility program


running on a PC. Usually the programming device is interfaced to the PC
through RS-232C/USB/Parallel Port Interface.

MCE, CSE 56
» The commands to control the programmer are sent from the utility program to
the programmer through the interface (see the following Figure).

»The sequence of operations for embedding the firmware with a programmer is


listed below:
1. Connect the programming device to the specified port of PC (USB/COM
port/Parallel port)
MCE, CSE 57
2. Power up the device (Most of the programmers incorporate LED to indicate
Device power up. Ensure that the power indication LED is ON)

3. Execute the programming utility on the PC and ensure proper connectivity is


established between PC and programmer. In case of error turn off device
power and try connecting it again

4. Unlock the ZIF socket by turning the lock pin

5. Insert the device to be programmed into the open socket as per the insert
diagram shown on the programmer

6. Lock the ZIF socket

7. Select the device name from the list of supported devices

8. Load the hex file which is to be embedded into the device

9. Program the device by 'Program' option of utility program

MCE, CSE 58
10. Wait till the completion of programming operation (Till busy LED of
programmer is off)

11. Ensure that programming is success by checking the status LED on the
programmer (Usually 'Green' for success and 'Red' for error condition) or by
noticing the feedback from the utility program

12. Unlock the ZIF socket and d take the device out of programmer.

» The major drawback of out-of-circuit programming is the high development


time. Whenever the firmware is changed, the chip should be taken out of the
development board for re-programming. This is tedious and prone to chip
damages due to frequent insertion and removal.

» The out-of-system programming technique is used for firmware integration


for low end embedded products which runs without an operating system.
MCE, CSE 59
» In System Programming (ISP):

» With ISP, programming is done 'within the system', meaning the firmware is
embedded into the target device without removing it from the target board. It
is the most flexible and easy way of firmware embedding. The only pre-
requisite is that the target device must have an ISP support. Apart from the
target board, PC, ISP cable and ISP utility, no other additional hardware is
required for ISP.

» The target board can be interfaced to the utility program running on PC


through Serial Port/ Parallel Port/ USB. The communication between the
target device and ISP will be in a serial format. The serial protocols used for
ISP may be 'Joint Test Act Group (JTAG)' or 'Serial Peripheral Interface
(SPI)' or any other proprietary protocol.

MCE, CSE 60
» In System Programming with SPI Protocol: Devices with SPI (Serial
Peripheral Interface) ISP (In System Programming) support contains a built-
in SPI interface and the on-chip EEPROM or FLASH memory. The primary
I/O lines involved in SPI-In System Programming are listed below:
» MOSI – Master Out Slave In

» MISO – Master In Slave Out

» SCK – System Clock

» RST – Reset of Target Device

» GND – Ground of Target Device

» PC acts as the master and target device acts as the slave in ISP. The program data is
sent to the MOSI pin of target device and the device acknowledgement is originated
from the MISO pin of the device. SCK pin acts as the clock for data transfer. A utility
program can be developed on the PC side to generate the above signal lines.

MCE, CSE 61
» Standard SPI-ISP utilities are feely available on the internet and, there is no
need for going for writing own program. For ISP operations, the target device
needs to be powered up in a pre-defined sequence.

» The power up sequence for In System Programming for Atmel's AT89S


series microcontroller family is listed below:

1. Apply supply voltage between VCC and GND pins of target chip

2. Set RST pin to "HIGH" state

3. If a crystal is not connected across pins XTAL 1 and XTAL2, apply a 3


MHz to 24 MHz clock to XTALl pin and wait for at least 10 milliseconds

4. Enable serial programming by sending the Programming Enable serial


instruction to pin MOSI/ Pl.5. The frequency of the shift clock supplied at
pin SCK/ P1.7 needs to be less than the CPU clock at XTALl divided by 40

MCE, CSE 62
5. The Code or Data array is programmed one byte at a time by supplying the
address and data together with the appropriate Write instruction. The
selected memory location is first erased before the new data is written. The
write cycle is self-timed and typically takes less than 2.5 ms at 5V

6. Any memory location can be verified by using the Read instruction, which
returns the content at the selected address at serial output MISO/ Pl.6

7. After successfully programming the device, set RST pin low or turn off the
chip power supply and turn it ON to commence the normal operation.

MCE, CSE 63
» The key player behind ISP is a factory programmed memory (ROM) called
'Boot ROM‟. The Boot ROM normally resides at the top end of code memory
space and it varies in the order of a few Kilo Bytes (For a controller with 64K
code memory space and lK Boot ROM, the Boot ROM resides at memory
location FC00H to FFFFH).

» It contains a set of Low-level Instruction APIs and these APIs allow the
processor/ controller to perform the FLASH memory programming, erasing
and Reading operations.

» The contents of the Boot ROM are provided by the chip manufacturer and the
same is masked into every device.

MCE, CSE 64
» In Application Programming (IAP):

» In Application Programming is a technique used by the firmware running on


the target device for modifying a selected portion of the code memory.

» It is not a technique for first time embedding of user written firmware. It


modifies the program code memory under the control of the embedded
application.

» Updating calibration data, look-up tables, etc., which are stored in code
memory, are typical examples of IAP.

MCE, CSE 65
» Use of Factory Programmed Chip:

» It is possible to embed the firmware into the target processor/ controller


memory at the time of chip fabrication itself. Such chips are known as
'Factory Programmed Chips'. Once the firmware design is over and the
firmware achieved operational stability, the firmware files can be sent to the
chip fabricator to embed it into the code memory.

» Factory programmed chips are convenient for mass production applications


and it greatly reduces the product development time.

» It is not recommended to use factory programmed chips for development


purpose where the firmware undergoes frequent changes.

» Factory programmed ICs are bit expensive.

MCE, CSE 66
» Firmware Loading for Operating System Based Devices:

» The OS based embedded systems are programmed using the In System


Programming (ISP) technique. OS based embedded systems contain a special
piece of code called 'Boot loader' program which takes control of the OS and
application firmware embedding and copying of the OS image to the RAM of
the system for execution.

» The 'Boot 1oader' for such embedded systems comes as pre-loaded or it can
be loaded to the memory using the various interface supported like JTAG.

» The boot loader contains necessary driver initialization implementation for


initializing the supported interfaces like UART/ I2C, TCP/ IP, etc.

» Boot loader implements menu options for selecting the source for OS image
to load (Typical menu item examples are Load from FLASH ROM, Load
from Network, Load through UART, etc).
MCE, CSE 67
» Once a communication link is established between the host and target
machine, the OS image can be directly downloaded to the FLASH memory of
the target device.

MCE, CSE 68

You might also like