0% found this document useful (0 votes)
32 views14 pages

Unit V

Uploaded by

niya enzie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views14 pages

Unit V

Uploaded by

niya enzie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)

Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

UNIT V REAL TIME OPERATING SYSTEM


Introduction to Basic concepts of RTOS:
RTOS is an Operating System that is used in real-time applications to obtain real-time output
without buffer delay. To do multiple tasks without compromising on the synchronization in a short
span of time is achieved by the Real Time Operating System (RTOS).
A real-time operating system (RTOS) is an operating system intended for real-time
applications. Real-time applications usually have very stringent timing requirements. First, a RTOS
must be able to respond to external events quickly, e.g. within a very short time, known as the interrupt
latency. Second, it must complete every requested service within a prescribed time limit, known as the
task deadline.
The General-Purpose Operating System is used in PCs and laptops whereas Real Time
Operating System finds its application in embedded systems. Performance is a prominent factor
required to be considered while selecting RTOS. The main advantage of a Real Time Operating System
is it produces an accurate output within no time. The only disadvantage of RTOS is that the system
only concentrates on a few tasks.
Types of RTOS:
1. Soft Real Time Operating System
In this type of Operating System, the response time of the system is prime but not critical to the
operation of the system. It has a deadline specified but the system can accept a short amount of delay.
Example: Online transaction system, Price quotation system, etc.
2. Hard Real Time Operating System
In Hard Real Time Operating Systems, the deadline and the time duration to execute tasks are specified.
It is necessary for a system to respond within the time line specified else might result in disastrous
consequences. Example: Medical critical care systems, Aircraft systems, etc.
3. Firm Real Time Operating System
In Firm RTOS, the deadline is specified but missing it does not cause a big impact. Example:
Multimedia applications.
In order to meet the stringent timing requirements, real-time OS are usually designed with the
following capabilities.

REC/MCT/MT19402/CF/2022-23 73
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Architecture of RTOS
The core component of an operating system is called Kernel. Micro-Kernel Architecture is
implemented in Real Time Operating System with configurable functionalities. Abstraction Layer is
provided by the Kernel which offers six main types of common services to the Application software.
They are:
 Task Management
 Task Scheduling
 Task Synchronization
 Memory Management
 Time Management
 Interrupt Handling
 Device I/O Management
Task:
Task is a piece of code or program that is separate from another task and can be executed independently
of the other tasks. In embedded systems, the operating system has to deal with a limited number of
tasks depending on the functionality to be implemented in the embedded system. Multiple tasks are not

REC/MCT/MT19402/CF/2022-23 74
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

executed at the same time instead they are executed in pseudo parallel i.e. the tasks execute in turns as
the use the processor.
Task States
In an operation system there are always multiple tasks. At a time only one task can be executed. This
means that there are other tasks which are waiting their turn to be executed.
Depending upon execution or not a task may be classified into the following three states:
1. Running state - Only one task can actually be using the processor at a given time that task is
said to be the “running” task and its state is “running state”. No other task can be in that same
state at the same time
2. Ready state - Tasks that are are not currently using the processor but are ready to run are in
the “ready” state. There may be a queue of tasks in the ready state.
3. Waiting state - Tasks that are neither in running nor ready state but that are waiting for some
event external to themselves to occur before the can go for execution on are in the “waiting”
state.
Threads:
A thread is a path of execution within a process. A process can contain multiple threads. A thread is
also known as lightweight process. The idea is to achieve parallelism by dividing a process into
multiple threads. For example, in a browser, multiple tabs can be different threads. "Multithreading is
a conceptual programming paradigm where a process is divided into a number of sub-processes called
as threads. Each thread is independent and has its own path of execution with enabled inter thread
communication."
"Thread is the path followed while executing a program. Each thread has its own program counter,
stack and register." A thread is a light weight process. It can be virtually represented as:

REC/MCT/MT19402/CF/2022-23 75
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Multi-processing
Multiprocessing is the ability of an operating system which is used to execute more than one process
simultaneously on a multiprocessor machine. In this, a computer uses more than one CPU at a time.
Two or more processors present in the same computer, sharing all the resources like the system bus,
memory, and other I/O is called a Multiprocessing System.
The diagram given below depicts the multiprocessing −Multi-processing system’s working:

 With the help of multiprocessing, many processes can be executed simultaneously. Say processes
P1, P2, P3 and P4 are waiting for execution. Now in a single processor system, firstly one process
will execute, then the other, then the other and so on.
 But with multiprocessing, each process can be assigned to a different processor for its execution.
If its a dual-core processor (2 processors), two processes can be executed simultaneously and thus
will be two times faster, similarly a quad core processor will be four times as fast as a single
processor.
Advantages
The advantages of multi-processing are as follows −
 As the workload is distributed evenly between the different processors it becomes more
accurate and the reliability increases.
 This is one of the examples of true parallel processing that means, more than one process
executing at the same time.
 By increasing the number of processors, more work can be completed in less time which
leads to increasing the throughput.
 Cost saving

REC/MCT/MT19402/CF/2022-23 76
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Multitasking:
A multitasking environment allows applications to be constructed as a set of independent tasks, each
with a separate thread of execution and its own set of system resources. The inter-task communication
facilities allow the set asks to synchronize and coordinate their activity. Multitasking provides the
fundamental mechanism for an application to control and react to multiple, discrete real-world events
and is therefore essential for many real time applications.
It is the ability of an operating system which executes more than one program on a single processor
machine. More than one task or program can store or reside into the main memory at one point of time.
In this concept the CPU executes some part of one program, and then continues with another part of
the program, and so on. Because of this process, the CPU will never go into the idle state unless there
is no process ready to execute at the time of Context Switching.

Advantages:
The advantages of multiprogramming are as follows −
 Very high CPU utilization.
 Less waiting time for the processes.
 Multi-programming decreases total read time that is needed to execute a job.
 Allows multiple Users
 Increased Resources Utilization
 Increased Throughput
 Improved Memory Utilization
Semaphores:
Semaphores are integer variables that are used to solve the critical section problem by using two atomic
operations, wait and signal that are used for process synchronization.
Types of Semaphores:
There are two main types of semaphores i.e. counting semaphores and binary semaphores.

REC/MCT/MT19402/CF/2022-23 77
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Counting Semaphores:
These are integer value semaphores and have an unrestricted value domain. These semaphores are used
to coordinate the resource access, where the semaphore count is the number of available resources. If
the resources are added, semaphore count automatically incremented and if the resources are removed,
the count is decremented.
Binary Semaphores:
The binary semaphores are like counting semaphores but their value is restricted to 0 and 1. The wait
operation only works when the semaphore is 1 and the signal operation succeeds when semaphore is
0. It is sometimes easier to implement binary semaphores than counting semaphores.
Advantages of Semaphores:
1. Semaphores allow only one process into the critical section. They follow the mutual exclusion
principle strictly and are much more efficient than some other methods of synchronization.
2. There is no resource wastage because of busy waiting in semaphores as processor time is not
wasted unnecessarily to check if a condition is fulfilled to allow a process to access the
critical section.
3. Semaphores are implemented in the machine independent code of the microkernel. So they
are machine independent.
Disadvantages of Semaphores:
1. Semaphores are complicated so the wait and signal operations must be implemented in the
correct order to prevent deadlocks.
2. Semaphores are impractical for last scale use as their use leads to loss of modularity. This
happens because the wait and signal operations prevent the creation of a structured layout for
the system.
3. Semaphores may lead to a priority inversion where low priority processes may access the
critical section first and high priority processes later.
Priority Inversion and Priority Inheritance:
Priority Inversion is a problem while Priority Inheritance is a solution. Priority Inversion means that
the priority of tasks gets inverted and Priority Inheritance means that the priority of tasks gets inherited.
Both of these phenomena happen in priority scheduling. Basically, in Priority Inversion, the higher
priority task (H) ends up waiting for the middle priority task (M) when H is sharing a critical section
with the lower priority task (L) and L is already in the critical section. Effectively, H waiting for M

REC/MCT/MT19402/CF/2022-23 78
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

results in inverted priority i.e. Priority Inversion. One of the solutions to this problem is Priority
Inheritance. In Priority Inheritance, when L is in the critical section, L inherits the priority of H at the
time when H starts pending for the critical section. By doing so, M doesn’t interrupt L and H doesn’t
wait for M to finish. Please note that inheriting of priority is done temporarily i.e. L goes back to its
old priority when L comes out of the critical section.

Priority Inversion Priority Inheritance

In priority inversion, a higher priority


It is a method that is used to eliminate the
process is pre-empted by a lower priority
problems of Priority inversion.
process.
With the help of this, a process scheduling
It is the inversion of the priorities of the two algorithm increases the priority of a process,
processes to the maximum priority of any other process
waiting for any resource.
It can cause a system to malfunction in our Priority inheritance can lead to poorer worst-
system. case behavior when there are nested locks.
Priority inheritance can be implemented
Priority inversions can lead to the
such that there is no penalty when the locks
implementation of corrective measures.
do not contend,
To deal with the problem of priority
inversion we can have several techniques It is the basic technique at the application
such as Priority ceiling, Random boosting, level for managing priority inversion.
etc.
Queues:
Queue is a structure with a series of data elements with the first element waiting for an operation. Used
when an element is not to be accessed by index with a pointer directly, as in an array, but only through
FIFO (first in first out) mode through a queue-head pointer. An element can be inserted only at the end
(also called tail or back) in series of elements waiting for an operation and deleted from front (queue-
head). There are two pointers, one for deleting after the read operation from the head and other for
inserting at the tail. Both increment after an operation.

REC/MCT/MT19402/CF/2022-23 79
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Washing Machine in Embedded System:


The design uses the PIC18F series microcontroller. All the control functionalities of the system are
built around this. Upgradeability is the unique feature of this system. Control card hardware and
software allows the manufacturer to add or remove the features as per customer requirement and model.
Thus once the whole system is designed it is very economical in large quantity production. Single-
phase motor is considered for the design. Front panel consists of a keypad and LCD display. Keypad
provides automatic and manual wash options to the user. LCD display is convenient to convey machine
information to user. One more design possibility is to use brushless DC motors or three phase induction
motor. These types of motors are very efficient but requires complex control algorithm. To implement
such a complex and real time algorithm dedicated controller and software is required which a master
controller controls. Even though cost is important criteria modern washing machines are designed with
BLDC motors owing to efficiency and energy conservation. But in this assignment single phase
universal motor has been used to design prototype due to its simplicity.
Design Specifications:
This include both hardware and software specifications.
1. The system should provide fully automatic mode, semi-automatic mode and manual
mode. Modes should be selectable by a keypad.
2. Under fully automatic mode user intervention requirement should be zero. Once the
system is started in this mode it should perform its work independently and after the
completion of work it should notify the user about the completion of work. This mode
instantaneously should sense cloth quality and requirement of water, water temperature,
detergent, load, wash cycle time and perform operation accordingly.
3. In semi-automatic mode also user requirement should be nil. But user has to choose any
one of the semi-automatic mode in which washing conditions are predefined. Once the
predefined mode is started the system should perform its job and after completion it
should inform the user.
4. In manual mode continuous intervention of user is required. User has to specify which
operation he wants to do and has to provide related information to the control system. For
example, if user wants to wash only, he has to choose ‘wash’ option in manual mode.
Then the system should ask the user to enter the wash time, amount of water and the load.

REC/MCT/MT19402/CF/2022-23 80
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

After these data are entered, the user should start the machine. When the specified
operation is completed system should inform the user.
5. When the lid is open system should not work. If door is accidentally opened in between
wash operation, then the system should stop working in minimum possible time (<10s)>
6. The system should provide all basic features of a washing machine like washing, rinsing,
spinning, drying, cold wash, hot wash etc.
7. The system should provide easy options for upgradeability of new features. The hardware
and the software should be compatible to both machines, which have fewer features, or
more features. Removal of any feature should not affect the working of any other features
or overall working of the system.
8. The system should work on single phase AC from 190VAC to 250VAC. The system
should protect itself from power supply voltage variations.
9. In the event of power failure, the washing machine should automatically start its cycle
from the point of interruption when power is resumed.
Hardware Design
Heart of this system is PIC18F452. Most of the peripheral features have been utilized to implement the
design. Controlling the motor is very crucial part of the design. The PWM feature of the microcontroller
controls motor speed. PWM output is fed to driver circuit and then to motor. To rotate the motor in two
different directions ‘forward’ and ‘reverse’ direction control blocks are used. Motor speed sensor is
interfaced to microcontroller. Microcontroller reads the speed of the motor and appropriately controls
the speed of the motor in different phases of washing using PWM output. Door sensor, pressure sensor,
keypad are also interfaced to microcontroller. Serial port in connected to GSM module. EEPROM and
RTC are interfaced to MSSP module of controller. In circuit serial programming facility is provided
for quick and easy programming and debugging.

REC/MCT/MT19402/CF/2022-23 81
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Cruise Control:
Cruise control is a system that takes charge of controlling the throttle from the driver and cruising the
vehicle at preset and constant speed. It may also maintain string stability in case of multiple cars
streaming through highway and in case of VIP convoy. Using an adaptive algorithm, ACC system
maintains constant speed and can be added string stability feature in case of multiple cars streaming on
highway. String stability─ maintaining inter-car distances constant.
Cruise control relieves the driver from that duty and the driver hands over the charge to the ACC When
(1) road conditions are suitable (not wet or icy), or
(2) there are no strong winds or fog), or
(3) car is cruising at high speed and when there is no heavy traffic.
The driver resumes the charge in adverse conditions.

REC/MCT/MT19402/CF/2022-23 82
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Inputs:
 Present alignment of radar (or laser) beam emitter.
 Delay interval in reflected pulse with respect to transmitted pulse from emitter
 Throttle position from a stepper motor position sensor.
 Speed from a speedometer
 Brake status for brake activities from brake switch and pedal
 Port_Align─ for a motor control for steps up clockwise or anticlockwise on a signal from
task_Align, aligns radar or UVHF transmitting device in the lane of the front-end car
 Port_ReadRange─ for measuring front end-car range. Time difference delta T is read on a
signal from task_Signal to port device.
 task_ReadRange to read using the Port device_ReadRange circuit for the computations of
deltaT between the transmission and reception instances. deltaT 1.5 × 105 measures the range
rangeNow ( present range or front-car distance d) of the front-end car.

REC/MCT/MT19402/CF/2022-23 83
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

 task_ReadRange to send message for speedNow (= velocity v) to task_RangeRate and


transmits same to all other streaming behind cars
 Port_Speed ─ to send speed to port control function routine on receiving a signal from
task_Speed
 Port_Brake─ to apply the brakes or emergency brakes on an interrupt signal, which runs
service routine ISR_BrakeControl
Automatic Chocolate Vending Machine:
An ACVM contains a Coin insertion slot and Keypad (on the top of the machine) to insert the coin
according to the possible denomination like 2, 5 rupees. Then after the coin is inserted, the system
directs each coin to the particular port like port 2 and port 5 (coin sorter). It also contains an LCD unit
on the top of the machine to display menus, text entered into the ACVM and pictograms, welcome,
thank and other messages. Graphic interactions are also available on this machine. The displays in the
ACVM also show the current time and date. The delivery slot in the ACVM is used to collect the
chocolate and coins (if refunded). The internet connection port is provided so that the owner can know
the status of the ACVM sales from a remote location. The block diagram of an ACVM is shown in
Figure 1 given below.

Hardware in ACVM:
The heart of an ACVM is a Microcontroller or ASIP (Application Specific Instruction Set Processor).
A RAM is used for storing temporary variables and the stack, and a ROM for application codes, and
the RTOS codes for scheduling the tasks. It also has flash memory for storing user preferences, contact
data, user address, a user date of birth, user identification code and answers to frequently asked
questions (FAQs). Timer and Interrupt controller are also needed to control the process of ACVM. It
has a TCP/IP port (Internet broadband connection) to the ACVM for remote control and for providing
the system status reports to the owner. It also has an ACVM specific hardware and a power supply.
Software:

REC/MCT/MT19402/CF/2022-23 84
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

Software is required to handle the following:


Read input from keypad, display text/graphics, control coins reader, and control delivery port (to
deliver the chocolate). In addition to these, we also need the TCP/IP stack communication for remote
control, and an RTOS (say, MUCOS), to run the ACVM software.
Pick and Place Robot:
A pick and place robot is the one which is used to pick up an object and place it in the desired location.
It can be a cylindrical robot providing movement in horizontal, vertical and rotational axes, a spherical
robot providing two rotational and one linear movement, an articulate robot or a scara robot (fixed
robots with 3 vertical axes rotary arms).
A Rover: It is the main body of the robot consisting of several rigid bodies like a cylinder or a sphere,
joints and links. It is also known as a manipulator.
End Effector: It is the body connected to the last joint of the rover which is used for the purpose of
gripping or handling objects. It can be an analogy to the arm of a human being.
Actuators: They are the drivers of the robot. It actually actuates the robot. It can be any motor like
servo motor, stepper motor or pneumatic or hydraulic cylinders.
Sensors: They are used to sense the internal as well as the external state to make sure the robot functions
smoothly as a whole. Sensors involve touch sensors, IR sensor etc.
Controller: It is used to control the actuators based on the sensor feedback and thus control the motion
of each and every joint and eventually the movement of the end effector.
the basic pick and place robot works as follows:
 The wheels underneath the base help to move the robot to the desired location.
 The rigid body supporting the end effector bends or straightens up to reach the position where
the object is placed.
 The end effector picks up the object with a strong grip and places it at the desired position.
The transmitter part consists of the keypad interfaced to the microcontroller. Any button number in
decimal format is converted to 4-digit binary by the microcontroller and the parallel output at one of
its port is applied to the encoder. The encoder converts this parallel data to serial data and this is fed to
the transmitter, fitted with an antenna to transmit the serial data.
The receiver side consists of a decoder interfaced to the microcontroller. The decoder converts the
received command in serial format to the parallel form and gives this data to the microcontroller. Based

REC/MCT/MT19402/CF/2022-23 85
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering

MT19402 – Microcontrollers and Embedded Systems

on this command the microcontroller sends the appropriate input signals to the motor drivers to drive
the respective motors.
The system consists of two motors for providing motion to the whole robot and two other motors to
provide the arm motion. The end effector or the gripper needs to be controlled to apply proper pressure
on the object to handle it effectively, to give it a soft grip. This is ensured by controlling the arm motors
through proper command. The output from the arm motors is connected to a 10Ohms/2W resistor and
at the time of motor over load or locked condition, a high voltage is developed across the resistor,
which causes a logic high level at the output of the opto-isolator and the interrupt pin of the
microcontroller connected to the opto-isolator output through a PNP transistor gets logic low signal,
which halts all other operations of the gripper.

REC/MCT/MT19402/CF/2022-23 86

You might also like