0% found this document useful (0 votes)
18 views11 pages

MES Final Assignment (21-45920-3)

Uploaded by

estiakayon
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)
18 views11 pages

MES Final Assignment (21-45920-3)

Uploaded by

estiakayon
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/ 11

Final Assignment 1, Fall 2024-25

American International University – Bangladesh


Faculty of Engineering
Department of Electrical and Electronic Engineering
Final Assignment
Course Name: Microprocessor and Embedded Systems with Lab Course Code: EEE 4103
A
Semester: Fall 2024-2025 Section:
Faculty Name: Md. A noor

Assignment No: 1F (individual submission consisting of 10 marks)

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

long duration; // define variables


float distance, distanceinches, distanceThreshold; // define variables

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”);

distanceThreshold = 100; // set threshold distance to activate

LEDs if (distance > distanceThreshold) {


digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW); }

if (distance < distanceThreshold && distance > distanceThreshold-30)


{ digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW); }

if (distance < distanceThreshold-30 && distance > distanceThreshold-50)


{ digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW); }

if (distance < distanceThreshold-50 && distance > distanceThreshold-70)


{ digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
2
Final Assignment 1, Fall 2024-25

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>

void setup (void) {


Serial.begin(115200);
digitalWrite(SS, HIGH);
SPI.begin ();
SPI.setClockDivider(SPI_CLOCK_DIV8);
}

void loop (void)


{ char c;
digitalWrite(SS, LOW);
// Send test string
for (const char * p = "Hello, Bangladeshi Engineers!\r" ; c = *p; p++)
{ SPI.transfer (c);
Serial.print(c);
}
digitalWrite(SS, HIGH);
delay(2000);
3
Final Assignment 1, Fall 2024-25
}

4
Final Assignment 1, Fall 2024-25

Answer to The Question No 1

a) Travel Time Calculation:


Given,
Distance = 38.58 cm
Speed of sound = 340m/s = 34000cm/s

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

Result: All three LEDs will be ON.


c) Modified code to include message for how many LEDs are turned ON or OFF:
const int trigPin = 8;
const int echoPin = 9;
long duration;
float distance, distanceinches, distanceThreshold;

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);

duration = pulseIn(echoPin, HIGH);


distance = (duration / 2) * 1e-6 * 340 * 100;
distanceinches = (distance / 2.54);

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

int ledCount = 0; // Counter for LEDs ON


distanceThreshold = 100;

if (distance > distanceThreshold)


{ digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
ledCount = 0; // All LEDs OFF
} else if (distance < distanceThreshold && distance > distanceThreshold - 30)
{ digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
ledCount = 1; // 1 LED ON
} else if (distance < distanceThreshold - 30 && distance > distanceThreshold - 50)
{ digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
ledCount = 2; // 2 LEDs ON
} else if (distance < distanceThreshold - 50 && distance > distanceThreshold - 70)
{ digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
ledCount = 3; // 3 LEDs ON
}

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

Answer to the Question No 2


a) Duty Cycle:

× 100
𝑂𝐶𝑅0𝐵

255
Duty Cycle (%)=
Here,
OCR0B = 150+4+5 = 159

× 100
159
Now,

255
Duty Cycle (%) =

= 62.35%

Figure 1: Waveform obtained in Port D


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)

Now, Operation Frequency of that mode based on the program segment:


Here,
Fclk = 21 Mhz
N = 1024 (Pre-scalar value)
256 is the resolution of 8-bit timer.

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:

Answer to the Question No 3

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

Answer to the Question No 4


Here,
fOSC = 49 Mhz
UBBRRn = 010110101110 = 1454

Baud Rate Calculation:

a) Double Speed Mode:

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)

Baud Error Calculation:


 Double Speed Mode:
Nearest standard baud rate = 19200bps

× 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

Answer to the Question No 4


a) Output:
The transmitted string is:
Hello, Bangladeshi Engineers!\r

The serial monitor will display:


Hello, Bangladeshi Engineers!

The carriage return “\r” is typically not visible.


b) SPI Clock Frequency calculation:
Here,
fOSC = 43 Mhz

= 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.

At the end of the program:


 The SS pin is set HIGH after the transmission ends.
 Therefore, the slave will be in an inactive state.
d) Proteus Simulation:

11

You might also like