SME
Embedded Systems · Problem type
CPU time in an interrupt
Use this for “An interrupt fires at 10 kHz and its ISR takes 20 μs. What share of the CPU does it use?”
Diagram
20% of 100 μs is 20 μs.
This is an example. Type your own values to start a new problem.
T (μs)
=
1
÷
r (kHz)
U (%)
=
tISR (μs)
÷
T (μs)
Formulas
T
=
1,000
r
100
=
1,000
10
U
=
100
×
tISR
T
20
=
100
×
20
100
Assumptions
•
Interrupts arrive at a steady rate and each ISR run takes the same time, entry and return included.
•
The CPU load is the ISR time over the time between interrupts, as a percent.
•
The ISR must finish before the next interrupt, so the load stays under 100%.
Step-by-step
WE KNOW
r = 10 kHz, tISR = 20 μs
FIND
time between interrupts (T), CPU load (U)
Step 1 · Find time between interrupts (T)
Use T = 1,000 ÷ r
The time between interrupts is one over the rate; 1000 turns 1/kHz into μs.
T
=
1,000
10
T
=
100
μs
Step 2 · Find CPU load (U)
Use U = 100 × tISR ÷ T
The ISR time over the time between interrupts, as a percent.
U
=
100
×
20
100
U
=
2,000
100
U
=
20%
Check
Put the numbers back in. Both sides should match.
100
=
1,000
10
✓
20
=
100
×
20
100
✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.
Related lessons
Interrupts and timers
Main lesson
PWM frequency and duty cycle
Use this for “A 16 MHz timer with prescaler 8 counts to TOP = 1999 and compares at 500. Find the PWM frequency, duty and average voltage at 5 V.”
Longest timer period
Use this for “How long can a 16-bit timer at 16 MHz run with prescaler 1024 before it overflows?”
What happens on an interrupt
Use this for “A timer matches its compare value. Put in order what the CPU does until the main program resumes.”