Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start the timer.
Embedded C
TIM2->CR1 |= [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using TIM_CR1_UDIS disables the timer update event.
Using TIM_CR1_DIR changes the counting direction.
Using TIM_CR1_OPM sets one pulse mode instead of starting timer.
✗ Incorrect
Setting TIM_CR1_CEN bit starts the timer counter.
2fill in blank
mediumComplete the code to set the prescaler value for the timer.
Embedded C
TIM3->PSC = [1] - 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using delay_time instead of prescaler_value.
Setting counter_value in PSC register.
Confusing timer_frequency with prescaler_value.
✗ Incorrect
The prescaler divides the timer clock frequency by (PSC+1).
3fill in blank
hardFix the error in the code to wait until the timer update event occurs.
Embedded C
while (!(TIM4->SR & [1])) {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using capture/compare flags instead of update flag.
Using undefined or incorrect flag bits.
✗ Incorrect
TIM_SR_UIF is the update interrupt flag indicating timer overflow.
4fill in blank
hardFill both blanks to configure the timer for a 1s delay assuming 16MHz clock.
Embedded C
TIM5->PSC = [1] - 1; TIM5->ARR = [2] - 1;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping prescaler and ARR values.
Using wrong values that don't match clock frequency.
✗ Incorrect
Prescaler divides 16MHz to 1kHz (16000), ARR counts 1000 ticks for 1s delay.
5fill in blank
hardFill all three blanks to create a delay function using TIM6 with prescaler and auto-reload values.
Embedded C
void delay_ms(uint16_t ms) {
TIM6->PSC = [1] - 1;
TIM6->ARR = [2] * ms - 1;
TIM6->EGR = [3];
TIM6->SR = 0;
TIM6->CR1 |= TIM_CR1_CEN;
while (!(TIM6->SR & TIM_SR_UIF)) {}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not generating update event after changing PSC and ARR.
Using wrong multiplier for ARR.
Forgetting to clear status register before starting timer.
✗ Incorrect
Prescaler divides 16MHz to 1kHz (16000), ARR counts ms ticks, EGR_UG generates update event.