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 not All the problems are not
solved correctly. The solved correctly. The solved correctly. The solved correctly. The solved correctly. The
simulation processes simulation processes are simulation processes are simulation processes are simulation processes are
are clearly described, clearly described, and not clearly described, not clearly described, not described, and No
and results are results are generated by and results are and results are results are generated by responses
CO3 generated by combining all possible generated by combining generated by combining combining mostly at all or
P.a.4.C.3 combining all possible input patterns with all possible input several wrong or less no wrong input patterns copied
input patterns with appropriate outcomes. patterns with of input patterns with with inappropriate from
appropriate outcomes. A few necessary appropriate outcomes. in/appropriate outcomes. Almost all others
All necessary drawings drawings and A few necessary outcomes. Some the necessary drawings
and computations are computations are drawings and necessary drawings and and computations are
missing but no wrong computations are computations are
shown correctly. missing or wrong.
drawing. missing or wrong. 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>
3
Final Assignment 1, Fall 2024-25
Now,
2 ×38,58
Travel Time = × 106
34000
= 2270 us
b) Number of LEDs Turned ON:
Using the conditions in the program:
• 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");
4
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:
5
Final Assignment 1, Fall 2024-25
𝑂𝐶𝑅0𝐵
Duty Cycle (%)= × 100
255
Here,
OCR0B = 150+4+5 = 159
Now,
159
Duty Cycle (%) = × 100
255
= 62.35%
b) Mode of Operation:
• The mode is configured WGM01 and WGM00 set in TCCR0A indicating Fast PWM Mode (Mode
3)
• The output compare match for Channel B (OBR0B) is set with COM0B1 enabling the PWM output
on pin PD5 (digital pin on Arduino)
So,
21×106
FPWM = 1024 ×256 = 80.66 Mhz.
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.
6
Final Assignment 1, Fall 2024-25
d) Protues Simulation:
a) Duty Cycle:
𝑂𝐶𝑅0𝐵
Duty Cycle (%)= × 100
𝑂𝐶𝑅0𝐴+1
Here,
OCR0A = 200+4+5+9 = 218
OCR0B = 100+2+0 = 102
Now,
102
Duty Cycle (%) =
218+1
× 100
= 46.57%
7
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,
21×106
FPWM = 64 ×(218+1) = 1493.2 Hz.
d) Proteus Simulation:
8
Final Assignment 1, Fall 2024-25
49×106
BaudDouble-Speed = 2 ×(1454+1) = 16837.46 b
b) Normal Mode:
49×106
BaudNormal = 16×(1454+1) = 2104.95 b
c) Synchronous Mode:
49×106
BaudSynchronous = 8 ×(1454+1) = 4209.89 b
16837.46−19200
Error(%) = 19200
× 100 = −12.31%
• Normal Mode:
Nearest standard baud rate = 2400bps
2104.95−2400
Error(%) = 2400
× 100 = −12.29%
• Synchronous Mode:
Nearest standard baud rate = 4800bps
4209.89−4800
Error(%) = 4800
× 100 = −12.27%
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
9
Final Assignment 1, Fall 2024-25
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.
10