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

Embedded Systems Exam Questions 2021

Uploaded by

ishmaelnjihia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views11 pages

Embedded Systems Exam Questions 2021

Uploaded by

ishmaelnjihia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIVERSITY EXAMINATIONS: 2020/2021

EXAMINATION FOR BACHELORS DEGREE IN APPLIED


COMPUTING/SOFTWARE DEVELOPMENT
BAC 3203/ BSD 3205: EMBEDDED SYSTEMS
INSTRUCTIONS: Question ONE IS COMPULSORY, choose TWO OTHER questions

QUESTION ONE (20 MARKS) COMPULSORY


a) Consider the following embedded system with a dial that can set A3..A0 to binary 0 to 9,and a
7-segment display (Wikipedia: 7-Segment Display) connected to B6..B0 as shown: Below is a
(partial) RIM C program that appropriately sets the display for the given dial
position:

#include “RIMS.h”
void main()
{
while (1) {
switch( A )
{
case 0 : B = 0x77; break; // 0111 0111 (0)
case 1 : B = 0x24; break; // 0010 0100 (1)
case 2 : B = 0x5D; break; // 0101 1101 (2)
//…
case 9 : B = 0x6F; break; // 0110 1111 (9)
default: B = 0x5B; break; // 0101 1011 (E for Error)
}
}
}
i) What B_ outputs should be set to 1 for case 3? List in ascending order separated
by spaces, e.g., B0 B2 … [5 marks]

The binary value for 3 is 0011. To display a 3 on a 7-segment display, the following B
outputs should be set to 1:

● B0 (Least Significant Bit)


● B4

In ascending order, this is B0 B4.

Here's how we arrived at the answer B0 B4 for displaying a 3 on the 7-segment display:

1. Binary representation of 3: The dial setting represents the number in binary. In


this case, 3 in binary is 0011.
2. 7-Segment Display Segments: A 7-segment display uses seven individual LED
segments (labeled a-g) to form different digits. Each segment needs to be turned
on or off to display specific numbers.
Mapping Digits to Segments: There's a specific pattern for which segments need to
be lit to display each digit (0-9). Here's a common mapping (though it might vary slightly
depending on the specific display):
| Digit | Segments lit |

|---|---|

| 0 | a, b, c, d, e, f |

| 1 | b, c |

| 2 | a, b, d, e, g |

| 3 | a, b, c, d, g |
| 4 | b, c, f, g |

| 5 | a, f, g, c, d |

| 6 | a, c, d, e, f, g |

| 7 | a, b, c |

| 8 | a, b, c, d, e, f, g |

3. | 9 | a, b, c, f, g |
4. Matching Binary with Segments: We look at the binary representation of 3
(0011) and compare it to the segment mapping. In this case:
○ The least significant bit (LSB) - B0 - corresponds to segment g. Since the
LSB is 1, segment g needs to be lit.
○ The third bit (counting from left) - B4 - corresponds to segment a. Since
the third bit is 1, segment a needs to be lit.
5. Output Selection: Therefore, to display a 3, we need to set B0 (segment g) and
B4 (segment a) to 1 in the output port B.

By following these steps and referencing the segment mapping, you can determine
which B outputs need to be set for any digit between 0 and 9.

ii) To what should B be set for case 3? B = ____; Use uppercase letters for the hex
literal. [5 marks]

● B0 and B4 need to be set to 1 for displaying a 3.


● In the given system, each B output corresponds to a single bit (B0 - LSB,
B6 - MSB).

To set specific bits to 1 in a hex value, we can use the concept of OR operation.

Steps to solve:
1. Identify bits to set: B0 and B4.
2. Set corresponding bits in a hex value:
○ We can start with a zero (0x00) as all bits are initially off.
○ To set B0 to 1, we perform a bitwise OR with 0x01 (which has only
LSB as 1).
○ Similarly, to set B4 to 1, we perform another OR with 0x10 (which has
only the 4th bit from the right as 1).

Solution:

B = 0x00 (initialize to 0)

B = B | 0x01 (set B0 to 1)

B = B | 0x10 (set B4 to 1)

Final Answer:

B = 0x11 (This value has only B0 and B4 set to 1).

b) State and explain the results of the following bitwise operation. [10 marks]
i) 00001111

10101010

The & operator performs a bitwise AND operation. It compares each bit of the first
operand to the corresponding bit of the second operand. If both bits are 1, the
corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

00001111

& 10101010
----------

00001010

ii) 00001111 | 10101010

The | operator performs a bitwise OR operation. It compares each bit of the first operand to the
corresponding bit of the second operand. If either bit is 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0

iii) 00001111 ^ 10101010

The ^ operator performs a bitwise XOR operation. It compares each bit of the first
operand to the corresponding bit of the second operand. If the bits are not identical, the
corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0..

00001111

^ 10101010

----------

10100101
iv) ~00001111

The ~ operator is a bitwise NOT operation. It inverts the bits of its operand.

~ 00001111

----------

11110000
v) Give a statement that sets B’s bits to the opposite of A’s bits, so if A is
11110000, B will be 00001111. End with ;

B = ~A;

In this statement, ~A performs a bitwise NOT operation on A, which flips all the bits of A.
The result is then assigned to B. So if A is 11110000, B will be 00001111. This statement ends
with a semicolon

QUESTION TW0 (15 MARKS)


A parking lot has eight parking spaces, each with a sensor connected to input A. Write a program
that sets B to the number of occupied spaces, by counting the number of 1s using the GetBit()
function. [15 marks]

#include <stdio.h>

// Function to get the value of a specific bit in a byte

int GetBit(unsigned char byte, int bitPosition) {

return (byte >> bitPosition) & 1;

int main() {

unsigned char inputA = 0b00101110; // Example state of parking spaces


int occupiedSpaces = 0;

// Iterate through each parking space

for (int i = 0; i < 8; i++) {

// Check if the bit representing the parking space is 1 (occupied)

if (GetBit(inputA, i) == 1) {

occupiedSpaces++;

// Set B to the number of occupied spaces

unsigned char outputB = occupiedSpaces;

// Print the number of occupied spaces

printf("Number of occupied spaces: %d\n", outputB);

return 0;

QESTION THREE (15 MARKS)


Given the following timing diagram and the light on/off SM, determine the value of B0 at
the specified times. [15 marks]

i) 0 s [3 marks]- 0
ii) 1 s [3 marks] -1
iii) 2 s [3 marks] -0
iv) 3 s [3 marks] -1
v) 4 s [3 marks] -1
QUESTION FOUR (15 marks)
a) Explain and give an example of an embedded system [5 marks]

A common example of an embedded system is a microwave oven. The digital control panel
of the microwave (which lets you input cooking time, select power level, etc.) is an
embedded system. It is designed to control the microwave’s operations, including turning
the microwave generator on and off, controlling the timer, and managing the display. The
control panel can’t be used for other tasks; it’s specifically designed and embedded into the
microwave to control its operation.

b) Consider the following schematic diagram for a serial communication

Two Arduino boards are used. The Arduino Uno on the left is the sender and the Arduino
Mega on the right is the receiver. We use the Mega to make it easier to display debugging
information on the computer. The Arduinos are connected together using digits 0 and 1
(RX and TX) on the Uno and digitals 16 and 17 (RX2 and TX2) on Mega. The receiver
one needs to be connected to the transmitter on the other and vice versa. The Arduinos
also need to have a common reference between the two, this is done by running a ground
wire. The first step in creating a serial communication system is to package the string to
be communicated. In general a packet is comprised of some start byte, a payload (the data
you wish to send), and a checksum to validate your data. Here, the packet is: [0x53]
+[counter value]+[static value]+ [checksum]. The sender code is shown below that
increments our counter and sends our packet.
Write the Receiver code for the above send information. [10 marks]

#include <SoftwareSerial.h>
SoftwareSerial mySerial(16, 17); // RX, TX

void setup() {

// Open serial communications:

[Link](9600);

// Set the data rate for the SoftwareSerial port

[Link](9600);

void loop() { // run over and over

if ([Link]()) {

byte startByte = [Link]();

if (startByte == 0x53) {

byte counterValue = [Link]();

byte staticValue = [Link]();

byte checksum = [Link]();

if (checksum == (counterValue + staticValue)) {

[Link]("Received valid packet with counter value: ");

[Link](counterValue, HEX);

} else {

[Link]("Checksum error in packet");


}

This code uses the SoftwareSerial library to create a new serial port. In the setup() function, it
begins communication on both the built-in serial port (for debugging purposes) and the software
serial port. In the loop() function, it checks if there is any available data on the software serial
port. If data is available and the start byte matches 0x53, it reads the next three bytes as the
counter value, static value, and checksum. It then checks if the checksum matches the sum of the
counter value and static value. If the checksum is correct, it prints the counter value; otherwise, it
prints an error message.

Common questions

Powered by AI

Bitwise operations perform logical operations on binary digits of numbers. AND (&) results in 1 only if both corresponding bits are 1; e.g., 00001111 & 10101010 results in 00001010 . OR (|) results in 1 if either bit is 1; e.g., 00001111 | 10101010 is not performed in the sources. XOR (^) results in 1 if bits are different; e.g., 00001111 ^ 10101010 results in 10100101 . NOT (~) inverts bits; ~00001111 becomes 11110000 .

For displaying the digit '3' on a 7-segment display, B0 and B4 should be set to 1. The binary value for 3 is 0011, which corresponds to segments a, b, c, d, and g being lit. The least significant bit (LSB) - B0 - corresponds to segment g, and the third bit from the left - B4 - corresponds to segment a. Thus, these bits are set to 1 in the output port B .

A checksum in serial communication is crucial for data integrity. It provides a means to verify that the received data matches what was sent, protecting against errors during transmission. In the example, the checksum is calculated as the sum of the counter and static values, ensuring the receiver confirms data accuracy before processing. This mechanism helps identify and handle transmission errors reliably, enhancing communication reliability .

In embedded systems, the bitwise NOT operation is crucial for flipping all bits of a given data, effectively creating its complement (e.g., converting 11110000 to 00001111). This is applicable in scenarios necessitating inversion, such as signal processing (inverting a digital signal) or setting states (e.g., toggling LEDs). It enables efficient data manipulation needed in various control algorithms and state transformations within system hardware .

In an embedded system, to set specific bits of a register's value using a bitwise OR operation, you first initialize the register to 0 (e.g., B = 0x00). Next, to set specific bits to 1, you perform a bitwise OR with the binary representations where only the relevant bits are set to 1. For instance, to set bits B0 and B4, you perform B = B | 0x01 followed by B = B | 0x10, resulting in B = 0x11 .

The receiver code ensures accurate data receipt by sequentially reading data bytes following initial verification of a start byte (0x53), which confirms the packet's beginning. Each subsequent byte is read and interpreted in sequence as counter, static, and checksum values. The checksum provides error detection by verifying that the sum matches expected computations, thus preventing corrupted data processing. This step-wise reading and validation are pivotal in maintaining integrity and correctness in data communication .

A common ground is necessary in a serial communication setup to ensure a common reference for voltages, which prevents miscommunication between devices. In the setup described, the Arduino Uno uses pins 0 and 1 for RX and TX, whereas the Arduino Mega uses pins 16 and 17 for RX2 and TX2. The RX of one should connect to the TX of the other, and vice versa, with the ground wire ensuring common reference .

The GetBit function checks the value of a specific bit in a byte by right-shifting the byte by the bit position and performing a bitwise AND with 1. This identifies whether the bit is set (i.e., equals 1). The loop iterates over all 8 bits representing parking spaces, increments a counter if the bit is set, thereby calculating the number of occupied spaces. This iteration allows accurate counting of '1's across the entire byte .

Ensuring specific sequences in protocol communication is crucial to maintain synchronization, data integrity, and avoid misinterpretation. Proper sequencing like including a start byte (e.g., 0x53) signals the beginning of a packet, while using a checksum helps validate data integrity post-transmission. This approach prevents errors such as data alignment issues, ensuring that devices interpret communication correctly, thereby maintaining system reliability and functionality .

A 7-segment display depicts digits by selectively lighting segments (a-g), each controlled by a bit. Each segment combination corresponds to specific binary values representing digits 0-9. For example, digit 2 might light segments a, b, d, e, and g, represented by the binary value 5D (or 0101 1101). By setting specific bit configurations for each segment, the system encodes a digit using binary coded decimal, ensuring accurate digital-to-visual translation on the display .

You might also like