Unit V
Unit V
REC/MCT/MT19402/CF/2022-23 73
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering
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
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
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
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
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
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.
REC/MCT/MT19402/CF/2022-23 79
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering
REC/MCT/MT19402/CF/2022-23 80
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering
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
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
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
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
REC/MCT/MT19402/CF/2022-23 85
RAJALAKSHMI ENGINEERING COLLEGE (Autonomous)
Department of Mechatronics Engineering
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