CET Embedded Systems & Programming 2 — Questions and Answers
Question 1: What is the primary purpose of a watchdog timer in an embedded system?
- To measure elapsed execution time
- To reset the system if software becomes unresponsive (Correct answer)
- To synchronize two microcontrollers over a bus
- To generate PWM signals for motor control
Correct answer: To reset the system if software becomes unresponsive
A watchdog timer resets the processor if the firmware fails to periodically 'kick' it, recovering from software hangs.
Question 2: In C, what does declaring a variable as `volatile` tell the compiler?
- The variable is stored in flash memory
- The variable must not be optimized away or cached in a register (Correct answer)
- The variable is shared across multiple files
- The variable is read-only at runtime
Correct answer: The variable must not be optimized away or cached in a register
`volatile` instructs the compiler to always read the variable from memory, preventing optimizations that could miss hardware-driven changes.
Question 3: Which type of non-volatile memory allows byte-level electrical erasure and reprogramming?
- ROM
- SRAM
- EEPROM (Correct answer)
- DRAM
Correct answer: EEPROM
EEPROM (Electrically Erasable Programmable Read-Only Memory) retains data without power and supports byte-granular erase/write cycles.
Question 4: What is the role of an Interrupt Service Routine (ISR) in embedded firmware?
- It initializes peripheral clocks at startup
- It executes a predefined response when a hardware or software interrupt fires (Correct answer)
- It manages heap memory allocation
- It configures the system's baud rate
Correct answer: It executes a predefined response when a hardware or software interrupt fires
An ISR is a function that the CPU branches to automatically upon receiving an interrupt, handling the event quickly before returning to the main loop.
Question 5: In C99, which data type is guaranteed to be exactly 8 bits wide on any platform?
- char
- short
- uint8_t (Correct answer)
- byte
Correct answer: uint8_t
`uint8_t`, defined in `<stdint.h>`, is an exact-width type guaranteed by the C99 standard to be 8 bits unsigned.
Question 6: What does the stack pointer register track in a microcontroller?
- The address of the next instruction to execute
- The top of the current call stack in RAM (Correct answer)
- The base address of flash memory
- The current interrupt priority level
Correct answer: The top of the current call stack in RAM
The stack pointer holds the address of the most recently pushed item on the stack, which grows and shrinks as functions are called and return.
Question 7: In embedded C, what is the purpose of using bit-field structs in register definitions?
- To speed up floating-point operations
- To map individual bits or groups of bits within a hardware register to named fields (Correct answer)
- To enable dynamic memory allocation
- To store strings more efficiently
Correct answer: To map individual bits or groups of bits within a hardware register to named fields
Bit-field structs allow firmware to access specific bits within a control register by name, improving readability over manual bit-masking.
What is the primary purpose of a watchdog timer in an embedded system?