0% found this document useful (0 votes)
122 views28 pages

Embedded System Lab Ii

This document contains programs for several embedded system projects using ARM processors and Arduino boards. It includes programs to interface with a 7-segment display and LCD using an ARM processor, control a DC motor using an Arduino and L293D motor controller, detect color using an Arduino color sensor, and monitor oil level using a Raspberry Pi ultrasonic sensor. The oil level monitoring program calculates tank dimensions and uses ultrasonic distance readings to determine the air space and oil level in multiple tanks.

Uploaded by

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

Embedded System Lab Ii

This document contains programs for several embedded system projects using ARM processors and Arduino boards. It includes programs to interface with a 7-segment display and LCD using an ARM processor, control a DC motor using an Arduino and L293D motor controller, detect color using an Arduino color sensor, and monitor oil level using a Raspberry Pi ultrasonic sensor. The oil level monitoring program calculates tank dimensions and uses ultrasonic distance readings to determine the air space and oil level in multiple tanks.

Uploaded by

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

EMBEDDED SYSTEM LAB II

NAME: ASPHIN JOHN J

REG NO: 2019212003

1) 7 SEGMENT DISPLAY USING ARM PROCESSOR(LPC 2138)


PROGRAM:

#include <LPC213x.h>
void delay(int time)
{
int i,j;
for(i=0;i<time;i++)
{
for(j=0;j<i;j++);
}
}
int main()
{
int i, a[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x07,0x7F};
PINSEL0=0x00000000;
IO0DIR=0xFFFFFFFF;
while(1)
{
for(i=0;i<10;i++)
{
IO0SET=a[i];
delay(500);
IO0CLR=a[i];
}
}
return 0;

OUTPUT:
2) LCD INTERFACE USING ARM PROCESSOR(LPC 2138)

PROGRAM:

#include <LPC213x.h>
void initLCD(void);
void LCD_Write(unsigned int c);
void LCD_Cmd(unsigned int LCD_Cmd);
void delay(void);
int main(void)
{
unsigned char ch[]="EST_LAB";
unsigned char ch1[]="2019212003";
unsigned int i,j,k,t;
initLCD();
for(i=0;ch[i]!='\0';i++)
{
LCD_Write(ch[i]);
}
LCD_Cmd(0xc3);
for(j=0;ch1[j]!='\0';j++)
{
LCD_Write(ch1[j]);
}
while(1)
{
for(k=0;k<16;k++)
{
LCD_Cmd(0x1c);
for(t=0;t<30000;t++);
}
}
}

void initLCD(void)
{
IO0DIR = 0x0FFFF00;
delay();
LCD_Cmd(0x38);
LCD_Cmd(0x01);
LCD_Cmd(0x0c);
LCD_Cmd(0x83);
LCD_Cmd(0x06);
}
void LCD_Write(unsigned int c)
{
IO0PIN = (c<<16)|(1<<10);
delay();
}
void LCD_Cmd(unsigned int LCD_Cmd)
{
IO0PIN = (LCD_Cmd<<16)|(0<<10);
delay();
}
void delay(void)
{
int i=0,x=0;
IO0PIN|=(1<<13);
for(i=0; i<15000; i++)
{
x++;
}
IO0PIN&=~(1<<13);
}
OUTPUT:
3) INTERFACE PROGRAM TO CONTROL A DC MOTOR USING ARDUINO
( CONTROLLER USED: L293D)
PROGRAM:

#define button 8
#define pot 0
#define pwm1 9
#define pwm2 10

boolean motor_dir = 0;

int motor_speed;

void setup ()

peripheral_setup();
pinMode(button, INPUT_PULLUP);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
}
void loop()
{
peripheral_loop();
motor_speed = analogRead(pot) / 4;
if(motor_dir)
analogWrite(pwm1, motor_speed);
else
analogWrite(pwm2, motor_speed);
if(!digitalRead(button))
{
while(!digitalRead(button));
motor_dir = !motor_dir;
if(motor_dir)
digitalWrite(pwm2, 0);
else
digitalWrite(pwm1, 0);
}
}
OUTPUT:
4) INTERFACE PROGRAM TO COLOR DETECTOR USING ARDUINO

PROGRAM:

const int s0 = 8;
const int s1 = 9;
const int s2 = 12;
const int s3 = 11;
const int out = 10;
int redLed = 2;
int greenLed = 3;
int blueLed = 4;
int red = 0;
int green = 0;
int blue = 0;

void setup()
{
Serial.begin(9600);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(out, INPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
}

void loop()
{
color();
Serial.print("R Intensity:");
Serial.print(red, DEC);
Serial.print(" G Intensity: ");
Serial.print(green, DEC);
Serial.print(" B Intensity : ");
Serial.print(blue, DEC);

if (red < blue && red < green && red < 20)
{
Serial.println(" - (Red Color)");
digitalWrite(redLed, HIGH); // Turn RED LED ON
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, LOW);
}

else if (blue < red && blue < green)


{
Serial.println(" - (Blue Color)");
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, HIGH);
}

else if (green < red && green < blue)


{
Serial.println(" - (Green Color)");
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(blueLed, LOW);
}
else
{
Serial.println();
}
delay(300);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, LOW);
}

void color()
{
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s3, HIGH);
blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
digitalWrite(s2, HIGH);
green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
}

OUTPUT:

S2 S3 PHOTODIODE TYPE
LOW LOW RED
LOW HIGH BLUE
HIGH LOW WHITE
HIGH HIGH GREEn

5) INTERFACE PROGRAM TO MONITOR THE OIL LEVEL USING


RASPBERRY PI AND PYTHON

PROGRAM:
import time
import math
import RPi.GPIO as GPIO
import signal
import atexit
import tmp102
timeout = 0.020
gpio_pin = 7
num_pings = 40
fudge_factor = 2
tank_width = 68
tank_height = 111.5
tank_length = 151
num_tanks = 2
oil_burn_rate = 1
daily_runtime = 5

def cleanup():
print "Cleaning up GPIO."
GPIO.cleanup()
def termhandler(signum, frame):
print "Terminating script."
global shutdown_flag
shutdown_flag = True
atexit.register(cleanup)
def add(x,y):
return x+y
def init_sensor():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(gpio_pin, GPIO.OUT)
GPIO.output(gpio_pin, 0)
time.sleep(0.000002)
def read_distance():
distances = []
for ping_number in range(1, num_pings):
successful=False
while not successful:
GPIO.setup(gpio_pin, GPIO.OUT)
GPIO.output(gpio_pin, 0)
time.sleep(0.000002)
GPIO.output(gpio_pin, 1)
time.sleep(0.000005)
GPIO.output(gpio_pin, 0)
GPIO.setup(gpio_pin, GPIO.IN)
goodread=True
watchtime=time.time()
starttime=0
endtime=0
while GPIO.input(gpio_pin)==0 and goodread:
starttime=time.time()
if (starttime-watchtime > timeout):
goodread=False
if goodread:
watchtime=time.time()
while GPIO.input(gpio_pin)==1 and goodread:
endtime=time.time()
if (endtime-watchtime > timeout):
goodread=False
else:
continue
if not goodread:
continue
if goodread:
air_temp=tmp102.read()
c_air_m_s=331.5 + (0.6 * air_temp)
duration=endtime-starttime
distance=((duration * c_air_m_s )/2)*100
distances.append(distance)
successful=True
time.sleep(0.05)
distances.sort
onethird=int(len(distances)/3)
twothirds=onethird * 2
mid_distances=distances[onethird:twothirds]
tank_air_space=(reduce(add, mid_distances)) / len(mid_distances)
tank_air_space=round(tank_air_space)
tank_air_space = tank_air_space - fudge_factor
print "Adjusted air space in tank is ", tank_air_space, " cm"
return tank_air_space
def get_fill_height():
air_space = read_distance()
oil_level = tank_height - air_space
print "Oil level calculated as ", oil_level, " cm"
return oil_level
def get_tank_volume():
tank_radius=tank_width/2
tank_square_height=tank_height-tank_width
tank_end_area=math.pi*(tank_radius**2)+(2*tank_radius*tank_square_height)
=tank_end_area*tank_length
return tank_volume
def get_oil_quantity():
oil_level=get_fill_height()
tank_radius=tank_width/2
tank_square_height=tank_height-tank_width
if oil_level < tank_radius:
tank_m=tank_radius-oil_level
theta=2*math.acos(tank_m/tank_radius)
oil_volume=0.5 * tank_radius**2 * (theta - math.sin(theta)) *
tank_length
elif (oil_level > tank_radius) and (oil_level < (tank_radius +
tank_square_height)):
vol_circle=math.pi * (tank_radius**2) * tank_length
height_in_square = oil_level - tank_radius
vol_cube=height_in_square * tank_width * tank_height
oil_volume=(vol_circle/2) + vol_cube
else:
vol_tank=get_tank_volume()
air_space=tank_height-oil_level
tank_m=tank_radius-air_space
air_volume=0.5 * tank_radius**2 * (theta - math.sin(theta)) *
tank_length
oil_volume = vol_tank - air_volume

return oil_volume
def cc_to_gallons(cubic_cm):
return cubic_cm * 0.000264172052358
init_sensor()
signal.signal(signal.SIGTERM, termhandler)
signal.signal(signal.SIGINT, termhandler)
oil_remaining_cc_1tank=get_oil_quantity()
oil_remaining_cc=oil_remaining_cc_1tank * num_tanks
oil_capacity_1tank=get_tank_volume()
oil_capacity=oil_capacity_1tank * num_tanks

oil_remaining_gal=cc_to_gallons(oil_remaining_cc)oil_capacity_gal=cc_to_gallons(oil_capacity)
orp=(oil_remaining_cc / oil_capacity) * 100
print "%.1f of %.1f gallons remaining ( %3d%% )" % (oil_remaining_gal,
oil_capacity_gal, orp)
hours_left=oil_remaining_gal / oil_burn_rate
print "%d hours of runtime remaining at %.2f gal/hr" % (hours_left, oil_burn_rate)
days_left=hours_left / daily_runtime
print "%d days of operation at %.2f hours per day average" % (days_left,
daily_runtime)

OUTPUT:

Adjusted air space in tank is 69.0 cm


Oil level calculated as 42.5 cm
178.9 of 525.7 gallons remaining ( 34% )
6) INTERFACE PROGRAM FOR CLIENT SERVER BASED IOT USING
RASPBERRY PI

PROGRAM:
 SERVER SIDE CODE:

import socket
import numpy as np
import encodings
HOST = ‘192.168.56.160’
PORT = 65432
def random_data():
x1 = np.random.randint(0, 55, None)
y1 = np.random.randint(0, 45, None)
my_sensor = "{},{}".format(x1,y1)
return my_sensor
def my_server():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
print("Server Started waiting for client to connect ")
s.bind((HOST, PORT))
s.listen(5)
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024).decode('utf-8')
if str(data) == "Data":
print("Ok Sending data ")
my_data = random_data()
x_encoded_data = my_data.encode('utf-8')
conn.sendall(x_encoded_data)
elif str(data) == "Quit":
print("shutting down server ")
break
if not data:
break
else:
pass
if __name__ == '__main__':
while 1:
my_server()
 CLIENT SIDE CODE:

import socket
import threading
import time
HOST = '192.168.56.1'
PORT = 65432
def process_data_from_server(x):
x1, y1 = x.split(",")
return x1,y1
def my_client():
threading.Timer(11, my_client).start()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
my = input("Enter command ")
my_inp = my.encode('utf-8')
s.sendall(my_inp)
data = s.recv(1024).decode('utf-8')
x_temperature,y_humidity = process_data_from_server(data)
print("Temperature {}".format(x_temperature))
print("Humidity {}".format(y_humidity))
s.close()
time.sleep(5)

if __name__ == "__main__":
while 1:
my_client()
OUTPUT:
Enter command
Temperature: 26.2000deg Celsius
Humidity: 27.3999%
7) PWM CONTROL USING ARDUINO

PROGRAM:

int pwm = 12;


int pot = A0;
int t1 = 0;
int t2 = 0;
void setup ()
{
pinMode(pwm, OUTPUT); //
pinMode(pot, INPUT);
}
void loop()
{
t2= analogRead(pot);
t1= 1000-t2;
digitalWrite(pwm, HIGH);
delayMicroseconds(t1);
digitalWrite(pwm, LOW);
delayMicroseconds(t2);
}
OUTPUT:
8) DETAIL ABOUT THE HYBRID AUTOMATED VEHICLES CONTROL

Why hybrid vehicles:


  The number of the cars increases continuously and nearly doubled in the last 10 years.
With increasing number of cars entered in circulation every year, is held and increasing fuel consumption,
increased environmental pollution due to emissions from internal combustion engines (ICE), used to their
propulsion. Reducing oil consumption takes into account the limited availability of petroleum reserves and
reducing emissions that affect the health of population in large urban agglomerations. The car needs a
propulsion source to develop a maximum torque at zero speed. This can not be achieved with the classic
ICE. For ICE power conversion efficiency is weak at low speeds and it has the highest values close to the
rated speed. Pollution reduction can be achieved by using electric vehicles (EV), whose number is still
significant. Any vehicle that has more than one power source can be considered hybrid electric vehicle
(HEV). But this name is used most often for a vehicle using for propulsion a combination of an electric drive
motor and an ICE, which energy source is fossil fuel.
Concept of hybrid electric vehicle with ICE-electric motor aims to overcome the disadvantages
of the pure electric vehicles, whose engines are powered by electric batteries: the limited duration of use
(low autonomy) and time recharging for batteries.
SYSTEM DESIGN
HOW CONTROL STRATEGY HAPPENS;
Speed and battery SOC are used by the ICE-EM switching circuit based on two
experimentally designed thresholds. First threshold is the speed threshold ST which is 40km/h. This speed is
the maximum speed for running the HEV safely in term of current. Going above this speed may cause
battery fuse burning and/or battery damage. Second threshold is the battery threshold BT which is 25% of
full battery level. Under this level using the EM may cause battery damage. The main target of the strategy
is to improve fuel economy. Therefore, in the proposed algorithm, the ICE is switched on in two cases only.
The first case is when the speed is above ST. Going above this speed may cause battery fuse burning and/or
battery damage as mentioned before. The other case is when the battery is almost empty. In this case there is
no choice on using the EM.
Types of hybrid vehicles:
1. full hybrids
2. mild hybrids 
3. plug-in hybrids.
ADVANTAGES IN USING HYBRID VEHICLES:
There are many advantage reasons for using the combination of ICEs and EMs over ICEs
alone: EMs can stop completely during the ICEs idle period. EMs can use much less energy than ICEs in
low speed (less than 50 km/h) where most of vehicles have to operate in cities. While ICE vehicles can
operate better only on the highways with high speed (above 50 km/h) since the ICEs achieve higher level of
power-to weight ratio. Therefore, the main advantage of ICEs is on the higher power that can provide to
vehicles. Then, the combination of ICEs and EMs can maintain the optimal operation in both low speed on
busy roads and high speed on highways. The ICEs can automatically turn on and recharge the batteries for
EMs when they get low.
A distinction of HEVs can be divided into two main types:
1) serial type
2) parallel types.
In the serial type, the ICEs are not mechanically connected to the vehicle powertrain, but they are used only
to run the electrical generator to supply the electrical power to batteries for EMs. The EMs now can use the
electrical energy from their batteries to propel the vehicle. In the parallel type, both ICE and EM power
sources are independently operated; therefore, they can both individually or commonly propel the vehicles.
The most general configuration is that the ICE and EM are connected by an automatically controlled clutch.
For the EM driving in low speeds, the clutch between the ICE and the EM is open and only the EM runs the
vehicle. In high speeds, this clutch is closed and the ICE is started and propelled the vehicle while the EM is
stopped off. At very high speeds or at critical heavy loads, this EM can be automatically activated on to
support the ICE to drive the vehicle. To conclude, serial hybrids are less efficient and are more suitable for
short-distance travel before exhausting their batteries. However parallel hybrids fuel consumption is greater
than serial hybrids; gas/diesel engine has dominating role in parallel hybrids and thus battery pack can have
less capacity.

CONTROL STRATEGIES IN HYBRID VEHICLES:


Initial approaches to switch the transition between EM and ICE power sources were drawn on
heuristic information on the characteristics of ICEs vs EMs.
 Fuzzy logic was used as typical controlled schemes. A set of rules was applied to separate the
requirements between the two power sources. These control plans were introduced in the
early hybrid implementations. The dynamic engagements of the clutch between the ICE and
the EM must be controlled as smooth as possible at the right time of engagement. For the
safety and comfort reasons, the clutch engagement and the torque transmission are not
permitted to cause any unacceptable acceleration or exceeded jerk. Several other control
strategies for smothering the clutches engagement have been attempted including the back
stepping control
 The model predictive control is to achieve faster and smoother clutches engagement
between ICE and EM. In a research, a new predictive model for controlling the speeds of
ICEs and EMs is developed and applied to the engagement of the clutches, which can help to
enhance the driving comfort and reduce the jerk on the parallel HEVs. The main motivation
of using the model predictive control (MPC) scheme in this chapter is the ability of the MPC
to determine the optimization actions online in both linear and nonlinear systems. Model
predictive control involves new mathematic algorithms that calculate an infinite sequence of
input and output variables in order to optimize the future behaviour of the systems. To date,
MPC strategy can be found in many application areas including aerospace, automotive and
petrochemical industries. One of the advantages of MPC is its ability to cope with constraints
from the open-loop optimal control problems. Achieving solution from the general
constrained nonlinear models within an infinite prediction sequence becomes impractical
because the numerical means to solve these problems can be only applied for a finite horizon
length in order to obtain a real-time numerical solution. 
 Robust model predictive control (RMPC) that guarantees stability in the existence of the
model uncertainty using linear matrix inequalities (LMIs) subject to both input and output
saturated constraints . In this RMPC,the controller will soften the output constraints as
penalty terms and add into its objective function. These terms will keep the output violation
at low values until the constrained solution is returned.

9) ROLE OF RTOS IN REAL TIME APPLICATION


RTOS  is an operating system intended to serve real time application that
process data as it comes in, mostly without buffer delay. It offers priority-based scheduling, which
allows you to separate analytical processing from non-critical processing. ... RTOS system occupy
very less memory and consume fewer resources. A real-time embedded system is a computer system
with timing constraints, like a system that responds to external input stimuli or events within a finite
and specified time period. In this case, timing constraints are finish time, start time and response
time.
Embedded systems have a wide variety of applications that vary from consumer
electronics to entertainment devices, weapons to medical instruments, industrial equipment to academic
equipment to aerospace control systems. Embedded systems are also used in many different industries, like
office automation, banking and finance, home appliances, security, telecommunications, personal
automobiles and instrumentations, among others. Here are a few real-world uses of embedded systems
 Weapons defense system :
Their sole job is to protect the naval destroyer by shooting down incoming missiles.
The weapons defense system is made up of three sub-systems: a weapons firing system, a
radar system and a control system. Weapon firing systems and the radar system are
controlled while the control system acts like the command and decision system. The radar
system monitors for potential threats like incoming missiles and measures its coordinates,
whichare then forwarded to the control system. The control system determines the threat
degree possessed by the target as per the information gathered from the radar system. The
command and decision system determines the different target parameters like flight path,
possible point of impact and speed. Based on these parameters, the control system activates
the weapons firing system that fires until the target is completely destroyed. The
communication between the radar and the command and decision system happens in real
time.

 Detecting speeding on highways

This relies on a highway speed checker device that senses speeding on highways and
notifies traffic authorities if it notes a vehicle that violates the defined highway speed limits.

 Street light control


This works by detecting the movement of vehicles on highways and triggering street
lights to turn on before an approaching vehicle reaches them. The street lights then go off
after the vehicle passes in order to conserve energy.

 Vehicle tracking
Vehicle trackers work by determining the exact location of a vehicle with the help of
GPS. They are used to curb theft and possible criminal activities. The GPS modem sends a
message to a specific mobile that stores data. The location information in terms of longitude
and latitude values are displayed using an LCD display. Its microcontroller checks the GPS
modem regularly.

 ABS(Anti-lock braking systems):

Almost all modern cars (and motor cycles as well) are equipped with a safety feature
called Anti – lock Braking System or ABS when we apply brakes on a car, the brake pressure
will be applied on all the wheels irrespective of the orientation of the wheel and speed of the car,
causing the wheels to lock. This will result in skidding of the vehicle and loss of traction (there
is separate Traction control system).  ABS (Anti-locking Barking System) plays an important
role in such situations. An ABS system typically comprises of three parts: Sensors, Control Unit
and Hydraulic Valves. Each wheel has its own sensor, which helps in continuously monitoring
the speed of rotation of the wheel. The data from the sensor is constantly monitored by the
Electronic Control Unit (ECU). If the rotational speed of a wheel is less than that of the others,
the wheel is susceptible to locking when brakes are applied. The ECU will then activate the
hydraulic valves according to the rotational speed of the wheel i.e. less hydraulic pressure to the
wheel rotating at slower speed than others. The reduction in hydraulic pressure to the brake will
reduce the braking force on that particular wheel and thus all the wheels will be synchronized.
The other case i.e. if the rotational speed of a wheel is higher than the others, then also ABS
comes in to picture.

 Heart Pacemaker:

A Heart pacemaker. This is a device that is inserted in someone's chest to provide


electrical impulses at regular intervals to help their heart beat. If the device missed a beat, it may
be fatal.

 Defence application systems like RADAR:

The need for secure real-time operating system and embedded computing security software
for use in military embedded system continues to rise due to increasing security concerns
and threats. The IT sector has responded by designing numerous security innovations that are
used to deliver protection at system and component levels. Connected security systems must
integrate numerous capabilities to achieve absolute security, especially in hostile network
environments. This may entail the use of layered security components that are integrated
with capabilities that keep the components updated to ensure continuous service and
application availability while retaining top security capabilities.

 Aerospace and avionics system:-

Aerospace and avionics system have strict requirements for software and
require the utmost security. Some of the most efficient aerospace systems deployed today
utilize embedded virtualization technology that creates advanced partitioning strategies.
Partitioning creates room for integration of several applications with the help of several
operating systems within shared compute platforms. It also triggers support for legacy
applications, facilitates the use of enterprise OS on traditional RTOS platform, offers a basis
for obsolescence management while systems evolve through their life cycle, and decreases
SWaP (size, weight and power) for next-gen system designs through platform sharing.
Support for modern hardware is also important for the Aerospace and avionics sector.

OTHER APPLICATION WHERE RTOS IS IMPORTANT:


Applications with strict deadlines: Some tasks must be completed before the set instant or deadline.
However, the exact instant when the task is performed is not crucial. For instance, a sound card buffer has to
be refilled before it is emptied. The output port’s voltage must reach a certain level before the value is read
by the next peripheral device.

Applications with zero execution time: This is where a task has to be performed at a specific instant that
is minimized. For instance, in a digital control theory, taking measurement, calculating a control action, and
sending it to the peripheral device occurs instantly.

Quality of service: An RTOS can be used when a task must have a fixed service amount per time unit. In
this case, service implies CPU time. However, it can be network bandwidth, disk access bandwidth or
memory pages. This is crucial for applications like network services and video and audio streaming.

Applications that involve competition for resources: In some applications, tasks compete for resources
like network, processors, and memory. This competition is stiffer in real-time operating systems than in
general purpose operating systems. Therefore, a real-time operating system ensures that each task is allotted
the necessary resources promptly.
Applications with worst-case scenarios
If there are numerous tasks that need a service, there will be a time when they will all need the service at
once. Real-time operating systems are used in such applications to ensure that worst-case scenarios are given
priority.

10.a) JAVA PROGRAM TO FIND THE SUM OF TWO MATRIX(3X3)

PROGRAM:

public class MatrixAddition

public static void main(String args[])

int a[][]={{1,3,4},{2,4,3},{3,4,5}};

int b[][]={{1,3,4},{2,4,3},{1,2,4}};

int c[][]=new int[3][3];

System.out.println(“The sum of two matrix is”);

for(int i=0;i<3;i++)

for(int j=0;j<3;j++)

{
c[i][j]=a[i][j]+b[i][j];

System.out.print(c[i][j]+" ");

System.out.println();

OUTPUT:

10.b) JAVA PROGRAM TO CALCULATE A FACTORIAL OF A NUMBER

PROGRAM:
import java.util.Scanner;

public class Factorial

public static void main(String[] args)

int number;

System.out.println("Enter the number: ");

Scanner scanner = new Scanner(System.in);

number = scanner.nextInt();

scanner.close();

long fact = 1;

int i = 1;
while(i<=number)

fact = fact * i;

i++;

System.out.println("Factorial of "+number+" is: "+fact);

OUTPUT:

You might also like