0
0
Embedded Cprogramming~10 mins

Timer interrupt for periodic tasks 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 enable the timer interrupt.

Embedded C
TIMSK |= (1 << [1]);
Drag options to blanks, or click blank then click option'
ATOV1
BTOIE0
COCIE1A
DOCIE0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the compare match interrupt bit instead of overflow interrupt bit.
Confusing timer numbers in bit names.
2fill in blank
medium

Complete the code to set the timer prescaler to 64.

Embedded C
TCCR0B = (1 << CS01) | [1];
Drag options to blanks, or click blank then click option'
ACS10
BCS02
CCS00
DCS03
Attempts:
3 left
💡 Hint
Common Mistakes
Setting only one bit for prescaler 64.
Using bits for a different prescaler value.
3fill in blank
hard

Fix the error in the interrupt service routine declaration.

Embedded C
ISR([1]) {
    // Toggle LED
    PORTB ^= (1 << PORTB0);
}
Drag options to blanks, or click blank then click option'
ATIMER0_OVF_vect
BTIMER1_COMPA_vect
CADC_vect
DUSART_RX_vect
Attempts:
3 left
💡 Hint
Common Mistakes
Using interrupt vectors for other peripherals.
Mixing Timer1 and Timer0 interrupt vectors.
4fill in blank
hard

Complete the ISR to count timer overflows and toggle LED every 100 overflows.

Embedded C
ISR(TIMER0_OVF_vect) {
    static uint8_t [1] = 0;
    [1]++;
    if([1] >= [2]) {
        PORTB ^= (1 << PORTB0);
        [1] = 0;
    }
}
Drag options to blanks, or click blank then click option'
Acounter
B100
Cticks
D256
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting static (counter resets each ISR).
Using 256 (full overflow) instead of 100.
Not resetting the counter after task.
5fill in blank
hard

Fill all three blanks for ~1s periodic task in ISR (16MHz, prescaler 64: overflow ~1.024ms, so ~976 for 1s).

Embedded C
ISR(TIMER0_OVF_vect) {
    static uint16_t [1] = 0;
    [1]++;
    if([1] >= [2]) {
        PORTB ^= (1 << PORTB0);
        [1] = [3];
    }
}
Drag options to blanks, or click blank then click option'
Aoverflow_count
B976
Ctimer_count
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Wrong variable name or not uint16_t.
Incorrect count (e.g., 1000 or 1024).
Wrong reset value or comparison operator.