0% found this document useful (0 votes)
4 views7 pages

MAES Midterm Assignment 2

The document outlines an assignment for the Microprocessor and Embedded Systems course at AIUB, detailing tasks related to timer configurations for pulse generation using an ATMega328P MCU. It includes specific questions about timer counts, register preparations, and programming a vending machine using Arduino. The document also provides marking rubrics and submission details for the assignment.

Uploaded by

shoaib.ahmed0718
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)
4 views7 pages

MAES Midterm Assignment 2

The document outlines an assignment for the Microprocessor and Embedded Systems course at AIUB, detailing tasks related to timer configurations for pulse generation using an ATMega328P MCU. It includes specific questions about timer counts, register preparations, and programming a vending machine using Arduino. The document also provides marking rubrics and submission details for the assignment.

Uploaded by

shoaib.ahmed0718
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/ 7

American International University- Bangladesh (AIUB)

Faculty of Engineering

Course Name: Microprocessor and Embedded Systems Course Code: EEE 4103
Semester: Fall 24-25 Term: Mid
Total Marks: 20 Submission Date: Exam Day
Instructor Name: Md Sajid Hossain Assignment: 02

Course Outcome Mapping with Questions


Obtained
Item COs POIs K P A Marks
Marks
Q1 CO1 P.a.4.C3 K4 P1, P3, P7 5
Q2 CO1 P.a.4.C3 K4 P1, P3, P7 5
Q3 CO1 P.a.4.C3 K4 P1, P3, P7 5
Q3 CO1 P.a.4.C3 K4 P1, P3, P7 5
Total: 20

Student Information:
Student Name: Mir Shoaib Ahmed Student ID: 19-41772-3

Section: C Department: CSE

Submission link is in the notice section of the portal.


Submission Date: 03.12.24 Due Date: Exam Day

Marking Rubrics (to be filled by Faculty):


Excellent Proficient Good Acceptable Unacceptable No Response
[5] [4] [3] [2] [1] [0]
Detailed unique
No
response Response with no Partial problem is Unable to clarify
Response shows Response/(Copie Secured
Problem # explaining the apparent errors solved; response the understanding
understanding of d/identical Marks
concept properly and the answer is indicates part of of the problem and
the problem, but submissions will
and answer is correct, but the problem was method of the
the final answer be graded as 0
correct with all explanation is not not understood problem solving
may not be correct for all parties
works clearly adequate/unique. clearly. was not correct
concerned)
shown.
1

Comments Total marks (20)


1. In an alternate universe, where live forms with supernatural abilities are common, a top secret research lab is
trying to implement a very robust security system against both physical and cyber threats. They have decided
to build their physical defenses with an ATMega328P MCU at the center. As part of the security measures,
the MCU is supposed to generate two pulses of 80µs and 2s. The team of engineers cleverly realized, they
can easily generate these pulses by configuring the timer modules on the MCU. The MCU is running at 16
MHz and there are 3 timer modules (Timer0, Timer1 and Timer2) available of which Timer0 and Timer2 are
8-bit timers and Timer1 is a 16-bit timer. The available prescalers are 8, 64, 256 and 1024. It is apparent
that 2 different timers need to be used for this purpose. Select 2 from the 3 available timers to be used for this
system. Then compute the necessary timer counts to generate the stated pulse signals using the selected
timers. To leave room for future changes, also compute the maximum pulses which can be generated using
the selected timers if the MCU clock frequency remains unchanged at 16 MHz. [5]
Solution:
Clock frequency: 16MHz
Clock Period: (1/16=62.5ns)
Tclock = 62.5ns
For 80 µs: using prescaler 8
Required Delay
Timer Count= −1
Tclock × Prescaler
80 µs
¿ −1
62.5× 8
¿ 160 −1
¿ 159
So 159 Fits within an 8bit timer’s range (0 to 255) so Timer0 which is a 8bit timer can be used.
For 2s:using prescaler 64
Required Delay
Timer Count= −1
Tclock × prescaler
2s
¿ −1
62.5× 64
¿ 500000 −1
¿499999

For 2s:using prescaler 256


Required Delay
Timer Count= −1
Tclock × prescaler
2s
¿ −1
62.5× 256
¿ 125000 −1
¿124999

For 2s:using prescaler 1024


Required Delay
Timer Count= −1
Tclock × prescaler
2s
¿ −1
62.5× 1024
Page 2 of 7
¿ 31250 −1
¿31249
So 31249 Fits within an 16bit timer’s range (65535) so Timer1 which is a 16bit timer can be used.
Maximum Pulse Duration for Timer0(8bit)
Prescaler 8,
Tmax=Timer count × Tclock × Prescaler
Tmax =255×0.0625μs×8=127.5μs.
Prescaler 64,
Tmax=Timer count × Tclock × Prescaler
Tmax =255×0.0625μs×64=1.02ms.
Prescaler 256,
Tmax=Timer count × Tclock × Prescaler
Tmax =255×0.0625μs×256=4.08ms
Prescaler 1024,
Tmax=Timer count × Tclock × Prescaler
Tmax =255×0.0625μs×1024=16.38ms
The maximum possible time for an 8-bit timer is 16.38 ms with a prescaler of 1024.

Maximum Pulse Duration for Timer1(16bit)


Prescaler 8,
Tmax=Timer count × Tclock × Prescaler
Tmax =65535×0.0625μs×8=32.768ms
Prescaler 64,
Tmax=Timer count × Tclock × Prescaler
Tmax =65535×0.0625μs×64=262.14ms.
Prescaler 256,
Tmax=Timer count × Tclock × Prescaler
Tmax =65535×0.0625μs×256=127.51.048s.
Prescaler 1024,
Tmax=Timer count × Tclock × Prescaler
Tmax =65535×0.0625μs×1024=4.194s.
The maximum possible time for a 16-bit timer is 4.194 s with a prescaler of 1024.

2. To meet the conditions specified in Q1, at least 1 of the 8-bit timers needs to be used. Prepare the necessary
registers associated with an 8-bit timer to achieve the time count computed in Q1. Consider the timer to be
running in normal mode. [5]

Page 3 of 7
[Hint: TCCRxA and TCCRxB have to be initialized. The useful bits of TCCRxA are bit 0 and bit 1 which
represent WGMx0 and WGMx1 respectively. Bits 0 to 3 are the useful bits from TCCRxB. Bits 3 represent
WGMx2. Bits 0 to 2 represent the clock select functions CSx0, CSx1, CSx2 respectively. Consider WGM = 0
for normal mode of operation. The bits not mentioned here can be ignored/considered as 0]
CSx2 CSx1 CSx0 Prescaler
0 1 0 8
0 1 1 64
1 0 0 256
1 1 1 1024
Solution:
8bit timer so Timer0 TCCR0A TCCR0B

3. A vending machine at a university campus will offer three different options for cold drinks. This machine
will be able to dispense a maximum of 3 drinks at once. The machine will have a total of three buttons
(button 1 for 1 drink, button 2 for 2 drinks, and button 3 for 3 drinks) to select the number of drinks to be
dispensed. After this initial selection, the vending machine will wait for 3s and then display the options for
available drinks. The consumer can use the 3 buttons (button 1 for A drink, button 2 for B drink, and button 3
for C drink) to select their desired drink(s). If only 1 drink is to be dispensed, the consumer will press the
relevant button and the vending machine will dispense the chosen drink after a 3 s wait. If more than 1 drink
is to be dispensed, the relevant buttons need to be pressed one after another and the machine will dispense the
drinks one at a time with a 3 s gap between the consecutive drinks. This vending machine is to be built
around an Arduino Uno platform. Now, prepare a program to execute the mentioned tasks if the Arduino
Uno system is operating at 16 MHz. [For this program, digital I/O pins D0 to D9 can be used whose pin
numbers are 0 to 9 correspondingly.] [5]
Page 4 of 7
Solution:
#define BTN_DRINKS_1 0 // Button for 1 drink
#define BTN_DRINKS_2 1 // Button for 2 drinks
#define BTN_DRINKS_3 2 // Button for 3 drinks

#define BTN_A 3 // Button for drink A


#define BTN_B 4 // Button for drink B
#define BTN_C 5 // Button for drink C

void setup() {
// Configure buttons as inputs
pinMode(BTN_DRINKS_1, INPUT_PULLUP);
pinMode(BTN_DRINKS_2, INPUT_PULLUP);
pinMode(BTN_DRINKS_3, INPUT_PULLUP);
pinMode(BTN_A, INPUT_PULLUP);
pinMode(BTN_B, INPUT_PULLUP);
pinMode(BTN_C, INPUT_PULLUP);

Serial.begin(9600); // Initialize serial communication (optional for debugging)


}

void loop() {
// Step 1: Wait for selection of the number of drinks
int drinksToDispense = selectDrinks();

if (drinksToDispense > 0) {
Serial.print("Number of drinks selected: ");
Serial.println(drinksToDispense);

// Wait for 3 seconds before showing drink options


delay(3000);

// Step 2: Select drink(s) and dispense


dispenseDrinks(drinksToDispense);
}
}

int selectDrinks() {
// Check buttons for number of drinks selection
if (digitalRead(BTN_DRINKS_1) == LOW) {
return 1;
} else if (digitalRead(BTN_DRINKS_2) == LOW) {
return 2;
} else if (digitalRead(BTN_DRINKS_3) == LOW) {
return 3;
}
return 0; // No selection made
}

Page 5 of 7
void dispenseDrinks(int count) {
for (int i = 0; i < count; i++) {
int drinkSelected = selectDrink();

// Dispense the selected drink


if (drinkSelected == 1) {
Serial.println("Dispensing drink A");
delay(3000); // Dispense delay (3 seconds)
} else if (drinkSelected == 2) {
Serial.println("Dispensing drink B");
delay(3000); // Dispense delay (3 seconds)
} else if (drinkSelected == 3) {
Serial.println("Dispensing drink C");
delay(3000); // Dispense delay (3 seconds)
} else {
Serial.println("No drink selected, skipping...");
}
}
}

int selectDrink() {
// Wait for a valid drink selection
while (true) {
if (digitalRead(BTN_A) == LOW) {
return 1; // Drink A selected
} else if (digitalRead(BTN_B) == LOW) {
return 2; // Drink B selected
} else if (digitalRead(BTN_C) == LOW) {
return 3; // Drink C selected
}
}
}

4. Prepare a flowchart for the program in Q3 to show the flow of logic. [5]
Solution:

Page 6 of 7
Page 7 of 7

You might also like