Challenge - 5 Problems
Timer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Calculate Timer Frequency with Prescaler
Given a microcontroller clock frequency of 16 MHz and a timer prescaler set to 64, what is the timer's input clock frequency?
Embedded C
unsigned long clock_freq = 16000000; unsigned int prescaler = 64; unsigned long timer_freq = clock_freq / prescaler; printf("%lu\n", timer_freq);
Attempts:
2 left
๐ก Hint
Divide the main clock frequency by the prescaler value.
โ Incorrect
The timer frequency is the main clock frequency divided by the prescaler. 16,000,000 / 64 = 250,000 Hz.
โ Predict Output
intermediate2:00remaining
Timer Overflow Period Calculation
If a timer counts from 0 to 255 (8-bit timer) with a clock frequency of 1 MHz after prescaling, what is the overflow period in microseconds?
Embedded C
unsigned long timer_clock = 1000000; unsigned int max_count = 256; unsigned long overflow_period = max_count * (1000000 / timer_clock); printf("%lu\n", overflow_period);
Attempts:
2 left
๐ก Hint
Overflow period = max count * timer clock period.
โ Incorrect
Timer counts 256 steps at 1 MHz clock, so overflow period = 256 * 1 microsecond = 256 microseconds.
๐ง Debug
advanced2:00remaining
Identify the Error in Prescaler Setting Code
What error will occur when compiling this code snippet that sets a timer prescaler?
Embedded C
unsigned int prescaler = 8; TCCR0B = (1 << CS01) | (1 << CS00);
Attempts:
2 left
๐ก Hint
Check punctuation at the end of statements.
โ Incorrect
The first line is missing a semicolon, causing a syntax error.
โ Predict Output
advanced2:00remaining
Effect of Clock Division on Timer Frequency
If the main clock is 8 MHz and the timer uses a clock division factor of 256, what is the timer frequency?
Embedded C
unsigned long main_clock = 8000000; unsigned int division_factor = 256; unsigned long timer_freq = main_clock / division_factor; printf("%lu\n", timer_freq);
Attempts:
2 left
๐ก Hint
Divide the main clock by the division factor.
โ Incorrect
8,000,000 / 256 = 31,250 Hz timer frequency.
๐ง Conceptual
expert3:00remaining
Understanding Combined Prescaler and Timer Resolution
A 16-bit timer runs with a 20 MHz clock and a prescaler of 128. What is the maximum timer overflow period in milliseconds?
Attempts:
2 left
๐ก Hint
Calculate timer clock frequency, then multiply by max count (65536) and convert to milliseconds.
โ Incorrect
Timer clock = 20,000,000 / 128 = 156,250 Hz. Period = 1/156,250 = 6.4 ยตs. Max count = 65536. Overflow period = 65536 * 6.4 ยตs = 419,430.4 ยตs = 419.43 ms.