2024 May Answers

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Section 3:

Q3. Distingush between synchronous and asynchronous communication protocal give and explain an example of each

Answer:
Synchronous Communication Protocols
Definition: Synchronous communication protocols are those where data transmission occurs at regular, timed intervals, coordinated by a
shared clock signal between the sender and receiver. Both sides need to be synchronized for the data to be properly understood.
Example: I2C (Inter-Integrated Circuit)
Explanation: I2C is a synchronous, multi-master, multi-slave, packet-switched, single-ended, serial communication protocol. It uses two
lines: a serial clock line (SCL) and a serial data line (SDA). The clock signal on the SCL line synchronizes the data transmission on the SDA
line. Here’s how it works:
Start Condition: The master device generates a start condition by pulling the SDA line low while the SCL line is high.
Addressing: The master sends the 7-bit address of the target slave device along with a read/write bit.
Data Transfer: Data is transferred in 8-bit bytes. The clock signal generated by the master synchronizes the sending and receiving of each
byte.
Acknowledge: After each byte, the receiving device sends an acknowledgment bit.
Stop Condition: The master generates a stop condition by releasing the SDA line to high while the SCL line is high.
In I2C, the clock ensures that both the master and slave devices sample data at the same rate, thus maintaining synchronization.
Asynchronous Communication Protocols
Definition: Asynchronous communication protocols transmit data without a shared clock signal. Instead, data is sent in a self-sufficient
manner with start and stop bits to signal the beginning and end of transmission. The receiver uses these bits to synchronize with the
sender.
Example: UART (Universal Asynchronous Receiver/Transmitter)
Explanation: UART is an asynchronous serial communication protocol used widely for communication between microcontrollers and other
devices. Unlike synchronous protocols, UART does not use a shared clock. Here’s how it operates:
Start Bit: Transmission begins with a start bit, which is usually a low voltage level indicating the start of a data packet.
Data Bits: Following the start bit, a predefined number of data bits (typically 7, 8, or 9) are sent. The receiver's internal clock samples the
data bits at a specific rate.
Parity Bit: Optionally, a parity bit can be sent after the data bits for error checking.
Stop Bit: Transmission ends with one or more stop bits, which are high voltage levels signaling the end of the data packet.
The receiver, upon detecting the start bit, begins sampling the incoming bits at the agreed baud rate (speed of transmission), ensuring it
can correctly interpret the data bits without needing a shared clock.
Key Differences
Feature Synchronous Communication Asynchronous Communication
Clock Signal Requires a shared clock signal Does not require a shared clock
Data Synchronization Synchronized with the clock Synchronized with start/stop bits
Data Transfer Rate Generally faster and more reliable Slightly slower due to overhead
Complexity More complex due to clock management Simpler due to self-synchronization
Example I2C UART
In summary, synchronous protocols like I2C rely on a shared clock signal to ensure data is transmitted and received at the correct intervals,
while asynchronous protocols like UART use start and stop bits to align the transmission and reception of data independently.

Section 4:

Q4. with the neat diagrams the disadvantages of multiple semaphores.

Answer:
Disadvantages of Multiple Semaphores Process P1 Process P2
Using multiple semaphores in concurrent programming can | |
introduce complexity and potential issues. Here are some of the v v
main disadvantages, illustrated with neat diagrams for better Lock(S1) Lock(S2)
understanding: | |
1. Deadlock Wait(S2) <-------------> Wait(S1)
Description: Deadlock occurs when two or more threads or In the diagram above, the arrows indicate the waiting
processes wait indefinitely for resources held by each other, dependencies leading to a deadlock.
creating a cycle of dependencies with no resolution.
Example: Consider two processes, P1 and P2, and two 2. Priority Inversion
semaphores, S1 and S2. Description: Priority inversion occurs when a higher-priority task is
 P1 locks S1 and waits for S2. waiting for a resource held by a lower-priority task, and a medium-
 P2 locks S2 and waits for S1. priority task preempts the lower-priority task, effectively
Both processes are now stuck in a waiting state, causing a "inverting" the priorities.
deadlock. Example: Consider three tasks, T1 (high priority), T2 (medium
Diagram: priority), and T3 (low priority), and one semaphore S.
a) T3 locks S. Thread T1 Thread T2 Thread T3
b) T1 preempts T3 but must wait for S. | | |
c) T2 preempts T3 and runs to completion. Lock(S1) Wait(S1) Wait(S1)
d) T3 finally releases S, and T1 can proceed | | |
Diagram | Context Context
Task T1 (High) Task T2 (Medium) Task T3 (Low) | Switch Switch
| | | Unlock(S1) Lock(S1) Lock(S1)
| | | | | |
Wait(S) | Lock(S) v v v
| | | Runs Runs Runs
Preempt(T3) | | In this diagram, the frequent context switches and contention for
| | | the semaphore S1 are highlighted.
v | | Summary
Runs | | Using multiple semaphores can help manage complex
| | | synchronization requirements, but they come with significant
<------------------- Preempts ----------------> disadvantages such as deadlocks, priority inversion, increased
| debugging complexity, and resource contention. These issues can
v degrade system performance and reliability. Proper design and
Runs careful management of semaphore usage are essential to mitigate
| these disadvantages.
v
Releases(S) Section 2:
|
v
Q2. Mention the four necessary conditions for occurrence
Resumes(T1)
3.Complexity in Debugging
of a deadlock. for the resources allocation graph given
Description: Multiple semaphores increase the complexity of below, will a deadlock occur? if no provide the safe state. if
the program, making it difficult to understand, maintain, and deadlock will occur mention the reason for the sam.
debug. Identifying the cause of synchronization issues or
deadlocks becomes challenging.
Example: Consider a system with multiple semaphores (S1, S2,
S3) protecting various critical sections.
a) Incorrect order of acquiring semaphores.
b) Missing releases of semaphores.
c) Difficult-to-track interdependencies between
semaphores.
Diagram:

Process P1 Process P2 Process P3


| | |
Lock(S1) Lock(S2) Lock(S3)
| | |
Lock(S2) <-----------> Lock(S1) Lock(S1)
| | |
Lock(S3) Lock(S3) <--------> Lock(S2)

In the diagram, the inter dependencies and the locking order are
complex and difficult to track. Answer:Four Necessary Conditions for Deadlock
4.Resource Contention For a deadlock to occur in a system, the following four necessary
Description: When multiple semaphores are used extensively, it conditions must all be present simultaneously:
can lead to high contention for those semaphores, reducing
system performance due to the overhead of managing the locks. Mutual Exclusion: At least one resource must be held in a non-
Example: Consider a scenario where multiple threads frequently shareable mode. Only one process can use the resource at any
lock and unlock multiple semaphores. given time.
High overhead in acquiring and releasing semaphores. Hold and Wait: A process must be holding at least one resource
Increased context switching due to waiting threads. and waiting to acquire additional resources that are currently
being held by other processes.
No Preemption: Resources cannot be forcibly taken away from a
process holding them. They must be released voluntarily by the
process holding them.
Circular Wait: A set of processes must exist such that each process
is waiting for a resource held by the next process in the set,
forming a circular chain.
Analyzing the Resource Allocation Graph
The given resource allocation graph includes:
Diagram: Processes: T1, T2, T3, T4
Resources: R1, R2, R3
Graph Representation:  The inputs are direction (up/down) and a PWM input which
R1 is allocated to T1. control the speed at which the lift moves. The duty cycle can
T1 is waiting for R2. vary from 20% to 50%.
R2 is allocated to T2.  The frequency of the PWM signal is 20 Hz.
T2 is waiting for R1.  For detecting whether the lift has reached a floor, the system
R3 is allocated to T3. has a set of three sensors-
T3 is waiting for R3. two 'coarse' sensors and a 'fine' sensor. All the sensors are contact
R3 is allocated to T4. switches (e) when the fif reaches the point where the sensors are
T4 is waiting for R2. placed the contact switch gets pushed in. Output of contact
Checking for Deadlock switches are low when closed and high otherwise. The sensor
 Mutual Exclusion: Yes, resources R1, R2, and R3 are held by arrangement is represented in the fig below
processes, indicating non-shareable resources. Wall along PA Which lift moves
 Hold and Wait: Yes, processes hold resources and wait for Coarse Sensor 1
others. Fine Sensor
 No Preemption: Yes, resources are not forcibly taken away. Coarse Sensor 2
 Circular Wait: Yes, we can observe the following cycle:  On the ground floor-only Coarse Sensort and Fine Sensor will
 T1 -> R2 -> T2 -> R1 -> T1 be available. On the 2nd floor only Coarse Sensor 2 and the
 T3 -> R3 -> T4 -> R2 -> T3 Fine Sensor will be available.
The cycles demonstrate a circular wait condition.  When the lift starts at the ground floor it starts at a low speed
Conclusion: Deadlock gradually accelerating to the maximum speed. It should
Deadlock Will Occur: The given graph has circular wait conditions operate at maximum speed when it reaches Coarse Sensor
indicating a deadlock. 2", As the lift moves up if it has to stop at floor 1, when
Reason: The circular wait involving processes T1, T2, T3, and T4 Coarse Sensor 2 is detected at that floor the lift starts moving
around resources R1, R2, and R3 satisfies all four conditions for at a low speed until it can stop when it reaches Fine sensor.
deadlock. Each process in the cycle is holding a resource and When The 2ndfloor has only the down button.
waiting for another resource held by the next process in the cycle,  Whether the elevator stops at the floor or not depends on
creating a scenario where none of the processes can proceed. the direction in which the lift moves. For eg. if the lift is
Safe State moving in upward direction and the person on say the 1 floor
Since the system is already in a deadlock state, we cannot provide presses the down buttore the lift will not stop in the current
a safe state. The current allocation and requests of the resources journey. When the lift reaches the 2nd floor and starts
and processes form a cycle, leading to a deadlock. To resolve the moving down then the lift will stop at the 1st floor.
deadlock, one or more processes would need to be terminated or o At every floor there is a 7-segement display that indicates the
rolled back, or resources would need to be forcibly preempted, floor in which the lift is right now. The display can be any value
breaking the circular wait condition. from 0-2.0' indicates the ground floor.
o Inside the lift-buttons are available for floor selection.
Section 1: o The floor towards which the lift is moving is also displayed within
the lift.
To Doors to the lift open and close automatically.
A system for elevator control has to be designed. The elevator is o When the lift reaches any floor where it has to stop it opens
similar to the one in the institute building with a few minor automatically, and it clases after an interval of 2 minutes or when a
modifications, button within the lift called "Door Close" is pressed. Lift does not
System Requirements move until the door is closed.
 The elevator operates along 3 floors. o System runs from a standard power inlet.
 When not in use the elevator is always on the ground floor System Specifications
 The elevator can be called by pressing a button available on o An Electro-magnetic system is used for open and close of the
each floor. door. You just need to provide the on/off control.
 Ground floor has an up button o A heavy duty servo motor is used for lift movement. You only
 The 1 floor has two buttons - One button is up and the other have to provide the input to the driver circuit.
is down.
 The 2nd floor has only the down button. o The frequency of the PWM signal is 20 Hz.
 Whether the elevator stops at the floor or not depends on  The inputs are direction (up/down) and a PWM input which
the direction in which the lift moves. For eg. if the lift is control the speed at which the lift moves. The duty cycle can
moving in upward direction and the person on say the 1st vary from 20% to 50%
floor presses the down button: the lift will not stop in the o For detecting whether the lift has reached a floor, the system has
current journey. When the lift reaches the 2nd floor and a set of three sensors - two 'coarse sensors and a 'fine' sensor. All
starts moving down then the lift will stop at the 1st floor. the sensors are contact switches (Le) when the lift reaches the
 At every floor there is a 7-segement display that indicates the point where the sensors are placed, the contact switch gets
floor in which the lift is right now. The display can be any pushed in. Output of contact switches are low when closed and
value from 0-20 indicates the ground floor. high otherwise. The sensor arrangement is represented in the fig
 Inside the lift buttons are available for floor selection. below
System Specifications
 An Electro-magnetic system is used for open and close of the floor only Coarse Sensor 2 and the Fine Sensor will be available
door. You just need to provide the on/off control
 A heavy duty servo motor is used for lift movement. You only o When the lift starts at the ground floor it starts at a low speed
have to provide the input t the driver circuit. gradually accelerating to the maximum speed. It should operate at
maximum speed when it reaches 'Coarse Sensor 2 As the lift
moves up if it has to stop at floor 1, when Coarse Sensor 2 is
detected at that floor the lift starts moving at a low speed until it
can stop when it reaches Fine sensor. Wher it starts again it moves
at low speeds and reaches the maximum possible speed when it
Preaches the fine sensor. The same is done in the reverse direction
with the appropriate sensors.
o Speed at which the lift moves is proportional to the duty cycle.
For acceleration, duty cycle has to be gradually increased from 20
% to 50%. And for deceleration the duty cycle reduced from 50 %
to 20%. The increase is in steps of 10.9%)
o A crystal oscillator of 19.6608 MHz is available. This can be ined
by the system.
o A 7447 chip (BCD to seven segment converter) is used for driving
the 7-segment displays o. 7447 takes a 4-bit BCD value and
converts into the corresponding 7-sgement equivalent.

(a) Draw UML Use Case diagram for above system. [5M]
(b) Draw a block diagram for this system indicating the connection
of the external
PA sensors/components to the microcontroller. [SM]
(c) Prepare a function description of the system. (Can be provided
as step by step textual description or as a flow chart). [SM]
(d) What are the on-chip peripherals that you will use to
implement the design (Timers. interrupts. GPIO etc). Initialize all
the required on-chip peripherals of the micro-controller for (b) Block Diagram
implementing the functionality. Give appropriate justifications for Here's a textual description of the block diagram indicating
selection of particular peripherals. [10M] connections:
[ 25 Marks ] Components:
1. Microcontroller
Answer: a) Inputs:
(a) UML Use Case Diagram i. Floor call buttons (3 inputs)
The UML Use Case diagram outlines the interactions between the ii. Floor selection buttons inside the elevator (3
actors (users and external systems) and the system. Here's a inputs)
textual representation: iii. Door open/close button (1 input)
Actors: iv. Coarse and Fine sensors (6 inputs: 2 coarse and 1
1. User (Person on any floor) fine per floor)
2. Elevator System (Microcontroller and associated b) Outputs:
components) i. 7-segment display control signals (3 sets of 4-bit
Use Cases: outputs for BCD to 7-segment decoders)
1. Call Elevator ii. Motor driver PWM signals (direction and speed
a) User presses the call button on any floor. control)
2. Select Floor iii. Door control signals (open/close control)
a) User inside the elevator presses a button to select a c) Connections:
desired floor. i. Call Buttons (Ground, 1st, 2nd Floor) ->
3. Move Elevator Microcontroller Input Pins
a) The elevator moves between floors based on the ii. Floor Selection Buttons (Inside Elevator) ->
selected floor and direction. Microcontroller Input Pins
4. Display Floor iii. Door Open/Close Button -> Microcontroller Input
a) The current floor is displayed on a 7-segment display on Pin
each floor and inside the elevator. iv. Coarse and Fine Sensors (Ground, 1st, 2nd Floor) ->
5. Open/Close Door Microcontroller Input Pins
a) The elevator doors open and close automatically or v. Microcontroller Outputs (7-segment BCD) -> 7447
when a button is pressed. BCD to 7-Segment Decoder -> 7-Segment Displays
6. Speed Control vi. Microcontroller Outputs (PWM) -> Motor Driver
a) The system controls the speed of the elevator using Circuit -> Elevator Motor
PWM signals. vii. Microcontroller Outputs (Door Control) ->
Electromagnetic Door Control
 Ground Floor Coarse Sensor 1 (PC0)
 Ground Floor Fine Sensor (PC1)
 1st Floor Coarse Sensor 2 (PC2)
 1st Floor Fine Sensor (PC3)
 2nd Floor Coarse Sensor 1 (PC4)
 2nd Floor Fine Sensor (PC5)
GPIO Outputs:
 7-Segment Display (Common Cathode):
 Ground Floor Display (PD0 - PD3)
 1st Floor Display (PD4 - PD7)
 2nd Floor Display (PE0 - PE3)
 Motor Driver:
 Direction Control (PF0)
 PWM Signal (PF1)

(c) Function Description  Door Control:


Step-by-Step Description:  Door Open/Close Control (PF2)
1. Idle State:
a) Elevator is at the ground floor. Initialization Code (Example in C for an AVR Microcontrollers):
b) Doors are closed. void init_gpio() {
2. Call Elevator: // Configure button and sensor pins as input
a) User presses the call button on any floor. DDRB &= ~(1<<PB0) & ~(1<<PB1) & ~(1<<PB2) & ~(1<<PB3) &
b) Microcontrollers records the floor request and ~(1<<PB4) & ~(1<<PB5) & ~(1<<PB6) & ~(1<<PB7);
determines the direction of travel. DDRC &= ~(1<<PC0) & ~(1<<PC1) & ~(1<<PC2) & ~(1<<PC3) &
3. Move Elevator: ~(1<<PC4) & ~(1<<PC5);
a) Microcontrollers initiates the movement.
b) Elevator starts at low speed (20% duty cycle). // Enable internal pull-up resistors for inputs
c) Gradually accelerates to 50% duty cycle using PWM. PORTB |= (1<<PB0) | (1<<PB1) | (1<<PB2) | (1<<PB3) | (1<<PB4)
d) Slows down as it approaches the target floor using | (1<<PB5) | (1<<PB6) | (1<<PB7);
sensor inputs. PORTC |= (1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3) | (1<<PC4)
4. Display Floor: | (1<<PC5);
a) Continuously update the 7-segment displays with the
current floor number. // Configure display and motor control pins as output
5. Open/Close Door: DDRD |= (1<<PD0) | (1<<PD1) | (1<<PD2) | (1<<PD3) | (1<<PD4)
a) Upon reaching the target floor, the door opens | (1<<PD5) | (1<<PD6) | (1<<PD7);
automatically. DDRE |= (1<<PE0) | (1<<PE1) | (1<<PE2) | (1<<PE3);
b) Door closes after 2 minutes or when the "Door Close" DDRF |= (1<<PF0) | (1<<PF1) | (1<<PF2);
button is pressed. }
c) Elevator does not move until the door is confirmed 2. Timer Configuration for PWM
closed. Purpose:
6. Floor Selection:  Generate PWM signals to control the speed of the
i. Inside the elevator, user presses a button to select elevator motor.
a floor.  Set the frequency to 20 Hz and vary the duty cycle
ii. Microcontrollers records the selection and plans between 20% and 50%.
the movement accordingly.
void init_timer_pwm() {
(d) Detailed On-Chip Peripherals and Initialization // Configure Timer1 for PWM mode (Assuming a 16-bit timer,
1. General Purpose Input/Output (GPIO) Configuration e.g., on an AVR)
GPIO Inputs: TCCR1A = (1<<WGM11) | (1<<COM1A1); // Fast PWM mode,
non-inverting
 Call Buttons: TCCR1B = (1<<WGM13) | (1<<WGM12) | (1<<CS11); // Fast
 Ground Floor Call Button (PB0) PWM mode with ICR1 as top, prescaler = 8
 1st Floor Up Call Button (PB1)
 1st Floor Down Call Button (PB2) ICR1 = 1000000 / 20; // Set top value for 20Hz frequency (with
 2nd Floor Call Button (PB3) prescaler = 8)
 Floor Selection Buttons (Inside Elevator): OCR1A = (ICR1 * 20) / 100; // Initial duty cycle at 20%
 Ground Floor Button (PB4)
 1st Floor Button (PB5) // Enable output on the corresponding pin (e.g., OC1A)
 2nd Floor Button (PB6) DDRB |= (1<<PB1); // Assuming PB1 is OC1A
}
 Door Control Button: 3. Interrupt Configuration
 Door Close Button (PB7) Purpose:
 Handle button presses and sensor activations efficiently.
 Sensors:
 Ensure timely response to user inputs and sensor responding promptly to user inputs and accurately controlling the
readings. elevator movement and door operations. The configuration aligns
with the system requirements, ensuring smooth, safe, and reliable
void init_interrupts() { elevator functionality.
// Enable external interrupts on button and sensor pins
EIMSK = (1<<INT0) | (1<<INT1) | (1<<INT2) | (1<<INT3) |
(1<<INT4) | (1<<INT5); // Enable interrupts for INT0 to INT5
EICRA = (1<<ISC01) | (1<<ISC11) | (1<<ISC21) | (1<<ISC31) |
(1<<ISC41) | (1<<ISC51); // Trigger on falling edge

sei(); // Enable global interrupts


}

// Interrupt Service Routines (Example for INT0)


ISR(INT0_vect) {
// Handle ground floor call button press
handle_ground_floor_call();
}
4. ADC Configuration (if analog sensors are used)
Purpose:
Read analog sensor values to determine precise elevator
positioning.
Initialization Code:
void init_adc() {
// Configure ADC
ADMUX = (1<<REFS0); // AVcc with external capacitor at AREF
pin
ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) |
(1<<ADPS0); // Enable ADC, prescaler = 128

// Enable ADC interrupt (if needed)


ADCSRA |= (1<<ADIE);

sei(); // Enable global interrupts


}

// ADC Interrupt Service Routine


ISR(ADC_vect) {
uint16_t sensor_value = ADC;
// Process sensor value
}

Justification for Peripheral Selection:

GPIO:
Essential for interfacing with the various input and output devices
such as buttons, sensors, and displays.
Timers for PWM:
Necessary for generating precise PWM signals to control the
elevator motor speed. The 20 Hz frequency ensures smooth
operation.
Interrupts:
Efficiently handle asynchronous events, ensuring quick response to
button presses and sensor activations without busy-waiting.
ADC:
If sensors provide analog output, ADC is crucial for converting
these signals into digital values for processing.

Conclusion:
The selection and initialization of on-chip peripherals such as GPIO,
Timers, Interrupts, and ADC (if needed) are critical for
implementing the elevator control system. The detailed
initialization ensures that the system operates efficiently,

You might also like