Jan 18 / Wadix Technologies

CORDIC Explained: Deterministic Math for Real-Time Embedded Systems

CORDIC Explained: Deterministic Math for Real-Time Embedded Systems


1. Introduction

Many embedded applications rely on mathematical operations such as sine, cosine, vector magnitude, and phase calculation. These operations are common in motor control, signal processing, and sensor-based systems. On microcontrollers without a floating-point unit, implementing such functions in software can consume significant CPU time and introduce unpredictable execution latency.

To address this problem, some microcontrollers integrate a dedicated hardware accelerator known as CORDIC (Coordinate Rotation DIgital Computer). CORDIC allows complex mathematical functions to be computed using only simple arithmetic operations, making it efficient, deterministic, and well suited for real-time embedded systems.

Rather than replacing software math entirely, CORDIC provides a hardware-assisted alternative for specific classes of computations where performance and timing predictability are critical


2.What Is CORDIC?

CORDIC (Coordinate Rotation Digital Computer) is an algorithm designed to compute trigonometric and related mathematical functions using only additions, subtractions, and bit shifts. Unlike traditional math algorithms, CORDIC avoids multiplications and divisions, which makes it especially suitable for hardware implementation in microcontrollers.

At its core, CORDIC works by rotating a vector in small, predefined angular steps. Each iteration applies a simple shift-and-add operation that gradually moves the vector closer to a desired angle or value. After a fixed number of iterations, the final vector components represent the result of the requested function, such as sine and cosine, or vector magnitude and phase.

From a firmware perspective, CORDIC behaves like a specialized math coprocessor. The software provides the input values and selects the desired operation, while the hardware performs the iterative calculations internally. Because the number of iterations is fixed and known in advance, the execution time is determinis                                                Figure 1– CORDIC Concept


3. How CORDIC Works and Why It Is Fast

CORDIC is based on performing a rotation in a two-dimensional coordinate system using a sequence of small, predefined rotation steps. Instead of rotating a vector by an arbitrary angle in a single operation, CORDIC approximates the desired rotation by applying multiple micro-rotations.

At each iteration, the algorithm decides whether to rotate the vector clockwise or counter-clockwise based on the remaining angle error. The rotation angles are chosen so that their tangents are powers of two, allowing multiplications to be replaced by simple bit shifts.

Because the sequence of rotation angles is fixed, the number of iterations required to reach a given precision is known in advance. This makes CORDIC execution time fully deterministic, unlike software implementations that rely on loops, lookup tables, or polynomial approximations with data-dependent behavior.

From a performance perspective, CORDIC is fast because it avoids complex arithmetic units such as multipliers and dividers. Shift-and-add operations are compact, low-latency, and energy efficient in hardware. When implemented as a dedicated peripheral, CORDIC can compute results in a small and predictable number of clock cycles while the CPU continues executing other tasks.                Figure 2 – Why CORDIC Is Fast


4. Use Case of the CORDIC Peripheral

A common requirement in embedded systems is to determine the angle of a 2D vector given its X and Y components. Typical examples include motor control (α/β coordinates), joystick position, and sensor vector processing.

Computing atan2(y, x) in software can be expensive, especially on microcontrollers without a floating-point unit. When a CORDIC peripheral is available, this operation can be performed efficiently in hardware with deterministic latency



/* CORDIC handle */

CORDIC_HandleTypeDef hcordic;

void CORDIC_Init(void)

{

hcordic.Instance = CORDIC;

HAL_CORDIC_Init(&hcordic);

}

int32_t input[2] = { x, y };

int32_t angle = 0;

CORDIC_ConfigTypeDef cfg = {0};

/** Configure CORDIC for phase (atan2) computation */

cfg.Function = CORDIC_FUNCTION_PHASE;

cfg.Precision = CORDIC_PRECISION_6CYCLES; /* Balance between speed and accuracy */

cfg.Scale = CORDIC_SCALE_0;

cfg.NbWrite = CORDIC_NBWRITE_2; /* X and Y inputs */

cfg.NbRead = CORDIC_NBREAD_1; /* Angle output */

cfg.InSize = CORDIC_INSIZE_32BITS;

cfg.OutSize = CORDIC_OUTSIZE_32BITS;

HAL_CORDIC_Configure(&hcordic, &cfg);

/** Write input vector to CORDIC */

HAL_CORDIC_WriteData(&hcordic, input, 2, HAL_MAX_DELAY);

/** Read computed angle */

HAL_CORDIC_ReadData(&hcordic, &angle, 1, HAL_MAX_DELAY);

return angle; }


This example shows how CORDIC replaces costly trigonometric calculations with a short, deterministic hardware operation. The CPU performs no math, and execution timing is fully predictable.               Figure 3 – Peripheral Data Flow


5.CORDIC Is Not About Speed, It’s About Control and Determinism:

CORDIC is often described as a faster way to compute trigonometric functions, but speed is not its most important advantage. In embedded systems, predictability matters more than raw performance.

Software math functions can introduce variable execution time depending on inputs, compiler optimizations, or library implementations. This variability complicates scheduling, increases jitter in control loops, and makes worst-case execution time difficult to reason about.

CORDIC shifts mathematical computation from software into a fixed-latency hardware operation. The number of iterations is known, the execution time is deterministic, and the CPU is no longer responsible for managing numerical complexity. From the firmware’s perspective, math becomes a bounded peripheral transaction rather than an unpredictable code path.

This level of control simplifies real-time design. Timing budgets become reliable, control loops more stable, and system behavior easier to analyze. CORDIC’s real value is not that it computes math faster, but that it allows engineers to design systems with confidence in when those computations complete.


6. Conclusion

CORDIC enables embedded systems to perform complex mathematical operations efficiently and with deterministic timing. By offloading these computations to dedicated hardware, the CPU remains free for application logic, making CORDIC a practical and reliable choice for real-time embedded applications

Created with