Clock Frequency Calculator Formula
Understand the math behind the clock frequency calculator. Each variable explained with a worked example.
Formulas Used
Clock Period
period_ns = 1e9 / clock_hzInstructions per Second
mips = clock_hz / cycles_per_instruction / 1e6Timer Tick Frequency
timer_freq = clock_hz / prescalerTimer Tick Period
timer_period_us = prescaler / clock_hz * 1e6Variables
| Variable | Description | Default |
|---|---|---|
clock_freq_mhz | Clock Frequency(MHz) | 16 |
cycles_per_instruction | Cycles per Instruction | 1 |
prescaler | Timer Prescaler | 64 |
clock_hz | Derived value= clock_freq_mhz * 1e6 | calculated |
How It Works
Clock Frequency and Timer Calculations
The clock frequency determines the speed of all operations in a microcontroller.
Formulas
Clock Period = 1 / Frequency
MIPS = Clock Frequency / Cycles per Instruction
Timer Frequency = Clock / Prescaler
Prescalers divide the clock to create slower timer ticks, useful for generating precise time intervals without consuming CPU cycles.
Worked Example
16 MHz clock, 1 CPI (ARM Cortex-M), prescaler of 64.
clock_freq_mhz = 16cycles_per_instruction = 1prescaler = 64
- 01Clock period: 1 / 16e6 = 62.5 ns
- 02MIPS: 16e6 / 1 = 16 MIPS
- 03Timer frequency: 16e6 / 64 = 250,000 Hz
- 04Timer tick: 64 / 16e6 = 4.000 microseconds
Ready to run the numbers?
Open Clock Frequency Calculator