Arduino PLL and Frequency Meter

Motivation

The Plant - Phase Locked Loop

Fig.1 - Basic PLL Scheme

PLL Input/Output Signals - Voltage and Current Analogy

Fig.2 - Inner product of signals with distinct frequencies
Fig.3 - Inner product of signals, same frequency, distinct phases

PLL Control Design

PLL Performance

Fig.4 - PLL Phase and Frequency Response - Input Signal Frequency jumps at 0.15s and 0.35s
Fig.5 - PLL Phase and Frequency Response - Input Signal Phase jumps at 0.15s and 0.35s
Fig.6 - PLL Phase and Frequency Response (steady state - continuous time)
Fig.7 - PLL Phase and Frequency Response (steady state - discrete time -sampling rate of 4 kHz)

PLL Test

Fig.8 - Scheme for the PLL Test
Table I - Duration of calculating trigonometric functions
Function Duration in cycles* Duration in µs
Sin(π/2)(AVR Math Lib) 1717 107.3
Cos(π/2)(AVR Math Lib) 1798 112.4
Sin(π/2) [LUT](index calculation and table access) 748 46.8
Cos(π/2) [LUT] (only index offset and table access)** 43 2.7

*The duration in number of cycles was measured using the timer 1 of the Atmega328p running with a clock of 16 MHz. See the way you can measure a time that a given code snippet takes to be executed in RMS Voltage Measurement Using Arduino

**The cosine is calculated using the sine table (200 samples for entire period), considering the normalized angle shifted in 1/4 of the period (50 points). This is calculated using the normalized angle converted to integer in the previous sine calculation, which is faster than to convert the angle from float to integer. Thus, in this case, the cosine value is obtained faster.

Fig.9 - ADC interrupt pulse for real time execution verification

Grid Frequency Meter

Fig.10 - Scheme for the PLL and Grid Frequency Meter

Links

References

[1] Remus Teodorescu, Marco Liserre and Pedro Rodríguez, Grid Converters for Photovoltaic and Wind Power Systems, John Wiley & Sons, Ltd., 2011, ISBN: 978-0-470-05751-3.

[2] Masoud Karimi-Ghartema, Enhanced Phase-Locked Loop Structures for Power and Energy Applications, John Wiley & Sons, 2014, ISBN:‎ 978-1118795026.