MES Final Assignment (21-45920-3)
MES Final Assignment (21-45920-3)
11/01/2025
Submission Date: Due Date: 11/01/2025
Student Information:
Mahmudul Hasan Sihab A
Student Name: Section:
2 1 4 5 9 2 0 3 EEE
Student ID #: Assigned Date: 12/31/2024 Department:
p q - a b c d e - r
Special Instruction: Questions may be copied from here through copy-paste. Online submission via
TEAMS is allowed.
Assessment Rubrics:
No
Excellent Proficient Good Acceptable Unacceptable Secured
COs-POIs Response
[10] [8-9] [6-7] [4-5] [1-3] Marks
[0]
All the problems are All the problems are All the problems are All the problems are All the problems are not
solved correctly. The solved correctly. The solved correctly. The not solved correctly. solved correctly. The
simulation processes simulation processes are simulation processes are The simulation simulation processes are
are clearly described, clearly described, and not clearly described, processes are not clearly not described, and No
and results are results are generated by and results are described, and results results are generated by responses
CO3 generated by combining all possible generated by combining are generated by combining mostly at all or
P.a.4.C.3 combining all possible input patterns with all possible input combining several wrong input patterns copied
input patterns with appropriate outcomes. patterns with wrong or less no of with inappropriate from
appropriate outcomes. A few necessary appropriate outcomes. input patterns with outcomes. Almost all others
All necessary drawings drawings and A few necessary in/appropriate the necessary drawings
and computations are computations are drawings and outcomes. Some and computations are
shown correctly. missing but no computations are necessary drawings and missing or wrong.
wrong drawing. missing or wrong. computations are
missing or wrong.
Comments Total Marks (10)
1
Final Assignment 1, Fall 2024-25
1. Compute the travel time of the sonar wave as per the following program codes of Arduino if the object is
38.58 cm away from the sonar sensor. Determine the number of LEDs that are turned ON. If we want the
system will display a message for any distance that how many LEDs are turned ON/OFF (for example,
“Two LEDs are turned ON and One LED is turned OFF”) then write the necessary changes that are
required to be included in the following program. Draw the relevant circuit diagram using Proteus and show
its simulation results including the serial monitor’s outputs.
const int trigPin = 8; // define the pin numbers
const int echoPin = 9; // define the pin numbers
void setup() {
Serial.begin(57400); // Starts the serial communication.
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(2, OUTPUT); // Sets pins 2, 3, and 4 as the Output pin
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW); // Clears the
trigPin delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) * 1e-6 * 340 * 100; // Calculating the
distance distanceinches = (distance / 2.54);
// Prints the distance on the Serial Monitor
Serial.print("Distance = ");
Serial.print(distance);
Serial.print(“cm; ”);
Serial.print("Distance = ");
Serial.print(distanceinches);
Serial.println(“inches”);
digitalWrite(4, HIGH); }
delay(300); // Wait for 300 millisecond(s)
}
2. Compute the duty cycle and sketch the waveform obtained at port D of the Arduino. Identify the modes of
operation and compute the operating frequency of that mode based on the following program segment.
Identify the Timer of the Arduino Microcontroller. The system clock frequency is pq MHz. Draw the
relevant circuit diagram using Proteus and show its timing diagram.
DDRD |= (1<<PD5);
pinMode(5, OUTPUT);
OCR0B= (150+a+b); // Load OCR0B for setting its duty cycle
// Configure TCCR0A and TCCR0B registers for the mode and pre-scaler
TCCR0A |= (1 << COM0B1) | (1<<WGM01) | (1<<WGM00);
TCCR0B |= (1<<CS02) | (1<<CS00);
3. Compute the duty cycle and sketch the waveform obtained at port D of the Arduino. Identify the modes of
operation and compute the operating frequency of that mode based on the following program segment.
Identify the Timer of the Arduino Microcontroller. The system clock frequency is rq MHz. Draw the
relevant circuit diagram using Proteus and show its timing diagram.
DDRD |= (1<<PD5);
pinMode(5, OUTPUT);
OCR0A = (200+ a + b + c); // Load a value in the OCR0A register
OCR0B= (100 + d + e); // Load a value in the OCR0B register
// Configure TCCR0A and TCCR0B registers for the mode and pre-scaler
TCCR0A |= (1 << COM0B1) | (1 << COM0A0) | (1<<WGM01) | (1<<WGM00);
TCCR0B |= (1<<WGM02) | (1<<CS01) | (1<<CS00);
4. Find the baud rate for the three operating modes when the oscillator frequency, fOSC = ac MHz (put side-by-
side), and register data is, UBRRn = 010110101110. Calculate the baud error and comment on whether
there will be any communication errors or not. Standard Baud rates are 300, 600, 1200, 2400, 4800,
9600,
14400,19200, 38400, 57600, 115200, 230400, ... bps.
5. For the following program, determine the output and the SPI clock frequency when the oscillator
frequency, fOSC = ar MHz (put side-by-side). Determine the slave state at the end of the program. Draw the
relevant circuit diagram using Proteus and show its simulation results including the serial monitor’s
outputs.
#include <SPI.h>
4
Final Assignment 1, Fall 2024-25
2
Now,
× 106
Travel
×38,58
Time =
34000
b) Number of LEDs Turned ON:
Using the conditions in the program: = 2270 us
distanceThreshold = 100cm
Distance = 38.58cm
We find that:
LED 1: Distance < distanceThreshold
LED 2: distanceThreshold-30 < Distance < distanceThreshold
LED 3: distanceThreshold-50 < Distance < distanceThreshold-30
So, if
38.58 < 100: LED 1 ON
38.58 < 70: LED 2 ON
38.58 < 50: LED 3 ON
void setup() {
Serial.begin(57400);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{ digitalWrite(trigPin,
LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
Serial.print("Distance = ");
Serial.print(distance);
Serial.print(" cm; ");
Serial.print("Distance = ");
Serial.print(distanceinches);
Serial.println(" inches");
5
Final Assignment 1, Fall 2024-25
Serial.print(ledCount);
Serial.print(" LED(s) are turned ON and ");
Serial.print(3 - ledCount); // Remaining LEDs
Serial.println(" LED(s) are turned OFF.");
delay(300);
}
d) Proteus Circuit Diagram and Simulation:
6
Final Assignment 1, Fall 2024-25
× 100
𝑂𝐶𝑅0𝐵
255
Duty Cycle (%)=
Here,
OCR0B = 150+4+5 = 159
× 100
159
Now,
255
Duty Cycle (%) =
= 62.35%
So,
6
21×10
FPWM = 1024 = 80.66 Mhz.
×256
c) Timer identification:
The code configures TCCR0A and TCCR0B, which are the registers for Timer 0 on the Arduino. Timer 0 is
an 8-bit timer.
7
Final Assignment 1, Fall 2024-25
d) Protues Simulation:
a) Duty Cycle:
× 100
Duty
𝑂𝐶𝑅0𝐵
Cycle (%)=
𝑂𝐶𝑅0𝐴+1
Here,
OCR0A = 200+4+5+9 = 218
OCR0B = 100+2+0 = 102
102
Now,
Duty Cycle (%) =
218+1
× 100
= 46.57%
8
Final Assignment 1, Fall 2024-25
b) Modes of Operation:
Fast PWM with TOP = OCR0A
Waveform: PWM signal with 46.57% duty cycle.
c) Operation Frequency:
Here,
Fclk = 21 Mhz
N = 64 (Pre-scalar value)
TOP Value = 218
So,
6
FPWM = 6421×10 = 1493.2 Hz.
×(218+1)
d) Proteus Simulation:
9
Final Assignment 1, Fall 2024-25
6
BaudDouble-Speed = 2 49×10 = 16837.46 b
b) Normal Mode: ×(1454+1)
6
49×10
BaudNormal = 16×(1454+ = 2104.95 b
1)
c) Synchronous Mode:
6
49×10
= 8
BaudSynchronous = 4209.89 b
×(1454+1)
× 100 = −12.31%
16837.46−19200
Error(%) = 1920
0
Normal Mode:
Nearest standard baud rate = 2400bps
× 100 = −12.29%
2104.95−2400
Error(%) = 240
Synchronous Mode: 0
Nearest standard baud rate = 4800bps
× 100 = −12.27%
4209.89−4800
Error(%) = 480
0
For reliable UART communication, the baud error should typically be within ±2% for asynchronous modes and tighter
for synchronous modes.
Observations:
All modes result in a significant baud error (approximately -12%)
This large error exceeds the permissible limit, leading to potential communication errors
10
Final Assignment 1, Fall 2024-25
= 5.375 𝑀ℎ𝑧
Divider = 8
43 𝑀ℎ𝑧
8
FSPI =
c) Slave state:
Active State: The slave is active (listening) when the SS pin is LOW.
Inactive State: The slave becomes inactive (ignoring data) when the SS pin is HIGH.
11