0
0
Embedded Cprogramming~10 mins

Timer overflow behavior in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A1
B65535
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting timer at max value causes immediate overflow.
Using negative values for unsigned timer.
2fill in blank
medium

Complete 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'
A0
B-1
C65536
D65535
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.
3fill in blank
hard

Fix 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'
A==
B>
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' causes false positives.
Using '!=' triggers on all values except 65535.
4fill in blank
hard

Fill 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'
A==
BOverflow
C!=
DComplete
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' causes wrong status.
Using wrong string for overflow status.
5fill in blank
hard

Fill 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'
A==
B65535
C0
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' causes reset at wrong times.
Resetting timer to max value instead of zero.