Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a timer variable that counts up to overflow.
Embedded C
volatile unsigned int timer = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting timer at max value causes immediate overflow.
Using negative values for unsigned timer.
✗ Incorrect
The timer should start counting from 0 to overflow.
2fill in blank
mediumComplete the code to check if the timer has overflowed.
Embedded C
if (timer == [1]) { // Timer overflowed }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 65536 which is out of range for 16-bit.
Checking for zero which is the reset value after overflow.
✗ Incorrect
The timer overflows when it reaches its maximum value 65535 for a 16-bit timer.
3fill in blank
hardFix the error in the overflow check condition.
Embedded C
if (timer [1] 65535) { // Handle overflow }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' causes false positives.
Using '!=' triggers on all values except 65535.
✗ Incorrect
The timer equals 65535 at overflow, so use '==' to check.
4fill in blank
hardFill both blanks to create a dictionary that maps timer values to overflow status.
Embedded C
const char* timer_status = (timer [1] 65535) ? "[2]" : "Running";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' causes wrong status.
Using wrong string for overflow status.
✗ Incorrect
Check if timer equals 65535 to mark overflow status.
5fill in blank
hardFill all three blanks to implement a function that resets the timer on overflow.
Embedded C
void reset_timer_if_overflow(unsigned int* timer) {
if (*timer [1] [2]) {
*timer = [3];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' causes reset at wrong times.
Resetting timer to max value instead of zero.
✗ Incorrect
The function checks if timer equals 65535 and resets it to 0.