Professional Documents
Culture Documents
supervised by
Ludwig de Clercq
Vlad Negnevitsky
Abstract
This report describes a discrete-time filter approach to improve the stability of
PID controlled locks with respect to infrequent and comparatively large disturbances
that exceed the usable error signal range. The concept has been implemented with
Verilog on an FPGA and was tested on several systems of varying intrinsic stability.
Further work has been put into the PyQt based configuration interface to allow
completely asynchronous data streaming of input and output channels as well as
configuration updates on a single serial communication channel.
1
Contents
1 Introduction 3
7 Experimental setup 13
7.1 Test procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
8 Results 14
9 Conclusion 15
10 Acknowledgements 16
2
1 Introduction
Proportional-integral-derivative (PID) feedback loop controllers are widely used algo-
rithms to control devices automatically and keep their output stable (locked) at a given
configuration. When configured correctly they provide great performance and stability
with minimal user intervention. However, when it comes to sudden external influences
with unusually high magnitudes, the PID parameters may not provide corrections large
enough to keep the device stable. In many cases this is not a long-term problem, since the
error signal guides the controller back to the desired configuration - but unfortunately
there are setups which provide a usable error signal only within a very narrow region
around the lock point (example in figure 3b). If this region is exceeded, the controller
will no longer provide a correcting output. A common example is the Pound-Drever-Hall
error signal which is widely used to stabilize lasers or cavities.
To tackle this problem a digital filter solution has been developed on top of an existing
PID controller FPGA module to disallow control outputs of uncommon significance. This
report contains a theoretical analysis of the filter, a complete description of the solution
and some experimental results.
Additionally, since the (filtered) PID controller is configurable via a Python/PyQt
based graphical user interface (GUI) over an USB connection, many improvements have
been implemented into the configuration GUI. The most significant change introduces
a live oscilloscope view of the PID input and output channels. This modification re-
quired a complete rewrite of the former single-threaded program. The new solution for
asynchronous, serial communication which integrates nicely with PyQt’s signal/slot sys-
tem and works around Python’s global-interpreter-lock restrictions will be discussed in
section 5.
3
Figure 1: Pound-Drever-Hall error signal generation setup [1]. The incoming laser beam
will be slightly modulated to gain access to the odd-symmetric derivative of the reflected
cavity intensity.
4
(b) Fast modulation at carrier resonance
(a) Slow modulation of Beam frequency frequency
Figure 3: Pound-Drever-Hall error signal with two different beam frequency modulation
speeds [1]
The mathematical derivation and a much more detailed explanation of this topic can
be found in the excellent paper of Eric D. Black [1].
5
be described in greater detail in the following two sections.
It works for all piecewise continuous functions φ(t) which are zero for t < 0 and do not
grow faster than Ceαt for some α ∈ R and C > 0 [2].
Laplace transforms mainly have two very important properties which are frequently
used especially for calculation purposes:
• Complex linearity: L(wφ + vψ) = wLφ + vLψ
• Differentiation in the time domain becomes multiplication by s:
φ0 (t) = sφ̂(s) − φ(0+ )
Having the first property makes it a lot simpler to transform functions with the usage of
readily calculated tables. The second one can then for example be used to solve ordinary
differential equations algebraically.
If it is the case that φ(t) can only be sampled at discrete timesteps T such that φ[n] =
φ(nT ), the corresponding discrete transform Z is called the (unilateral) Z-transform:
∞
X
φ̂(z) = Zφ(z) = φ[n]z −n
n=0
It has the same linearity property as the Laplace transform. Additionally, the shifting
theorem [7] is very important for daily use:
f [n − 1] = z −1 fˆ(z) + f [−1]
Here f [−1] is the initial condition which is usually set to 0.
6
Here h(s) is called the transfer function of a continuous system since it relates the system
input and output in Laplace space.
Transfer functions of discrete or continuous systems can be related to each other
by using the so called bilinear transform (chapter 7.1.2, Oppenheim and Schafer [6]).
It provides the following two substitutions, where z is the parameter in Z-space, s the
parameter in Laplace-space and T the sampling period:
2 z−1 2 + sT
s= · z=
T z+1 2 − sT
This is very useful in digital filter design, since now the algorithm can be immediately
derived from a continuous design transfer function.
From this transfer function h(z) the frequency response for a sinusoidal input signal
with frequency ω can easily be calculated by substituting z = eiωT (see page 28 of [8])
|h(eiωT )|
7
Gain @dBD
0
-5
-10
-15
Hz
0.01 0.1 1 10 100
Figure 5: Frequency dependent amplitude gain of a first-order, time-discrete low-pass
filter with a sampling frequency of 93.75 kHz and α = 2−16 . The cutoff frequency is
2.47 Hz.
that although the PID controller tries to compensate, the cavity jumps far away from
its original lockpoint to an unusable error signal region. As soon as this happens, the
controller will not be able to go back to the original lockpoint since the odd-symmetry
of the slope is gone.
Now, when this procedure is over, the absolute PID output value will be far away
from its original average point. And exactly this is what we will try to detect. In section
8 a real world measured example of such an event can be found.
8
PID output
High-pass filter
extracts short time variations
from the PID output signal
Low-pass filter
configurable, smoothes signal
threshold
some very low frequencies (smaller than approximately 2.5 Hz) that are for example
introduced due to temperature variations.
9
5 Graphical user interface
One aim of the project was to remove the need for an external oscilloscope during
the laser locking process and implement a real time display with the already available
streaming feature on the hardware side.
Since the previous GUI version was basically a single-threaded configuration interface
for the PID controller, streaming data to the GUI required a complete rewrite. The
asynchronous nature of the streaming made it impractical to stay with the single thread
design and forced a fully parallel approach.
10
Main process
GUI thread Queuing thread
Communication process
USB connection
- fetch command from command queue
- FPGA communication
- post result into result queue
Figure 7: Internal thread and process structure of the GUI to allow asynchronous com-
munication and therefore streaming with the FPGA
11
5.3 Implementation of a live oscilloscope view
This feature is intended to replace the single-shot time-series display which existed be-
fore. It basically recorded a specific number of samples with a given rate from a chosen
channel (PID input, PID output, ...) and displayed them in a plot generated with
matplotlib [5].
Unfortunately this library has difficulties with fast plot updates and also Qt inte-
gration is not very elegant. Therefore PyQtGraph [3] was chosen as a powerful and
fast alternative. Its PlotWidget can be used as a QGraphicsView replacement, and
from there the live view is just a connection of the PlotWidget.plot method to the
got stream data signal generated by the queueing thread.
12
Laser Pound-Drever-Hall Doubling cavity
Blackbox
error signal
Python GUI PID output
FPGA
USB connection
Figure 8: Possible real world application of the lockbox. Here it is used to control the
length of an unstable frequency doubling device to track a given laser frequency. The
error signal is generated by using a Pound-Drever-Hall blackbox with the reflected cavity
intensity.
7 Experimental setup
The lab testing setup covers a standard application situation and is displayed in figure 8.
A frequency doubling cavity should precisely track a given laser frequency. Due to small
temperature changes and acoustic disturbances in the laboratory the cavity length has
to be constantly adjusted with the use of a PID controller acting on a Pound-Drever-Hall
error signal. Originally the cavity was controlled without the bandpass filter solution.
This worked sufficiently well in a controlled environment.
But to the used doubling cavity disturbances as someone clapping or, more likely,
accidentally hitting the table had significant effects. In such cases the pure PID controller
was not able to keep the lock at the correct position and probably jumped to a sideband,
even with carefully chosen gain values. This behaviour is even worse than falling out of
lock completely, since the cavity frequency changes without any notice of the user.
13
Figure 9: Disturbance of the cavity with relocking feature disabled.
(approximately 100 g) was dropped on the table from a height of 1 cm and 20 cm away
from the cavity.
8 Results
The following individual plots are recorded from comparable but different events due
to the lack of a multi-channel streaming possibility. The data has been taken solely for
visualization purposes within the given precision in the plots.
Figure 9 shows the error signal (orange) and the eight most significant bits of the PID
output value (green). Starting from left one can see a stable controlled lock. Then, at
about 120 ms the error signal shows the disturbance which results in a huge drift of the
PID output, corresponding to a cavity length change. Finally, the output stabilizes at a
completely different length of the cavity, which is the worst scenario for a user unaware
of the resulting output frequency shift.
In contrast to this figure 10 shows the same procedure, but now with the relocking
feature enabled and TTL expansion set to roughly 400 ms. This time the green plot
14
Figure 10: Disturbance of the cavity with relocking feature enabled.
corresponds to the eight least significant bits of the PID output, while the topmost eight
bits (as shown in the last figure) do not change at all due to the action of the relocking
system. One clearly sees the disturbance which is almost immediately detected and the
PID output is held constant at its last known average value. Then, as the disturbance
goes away after about 200 ms the TTL expander still holds the PID constant for another
400 ms until it releases the controller back to normal operation.
9 Conclusion
The results did clearly show a huge improvement regarding shock resistance of the cavity
lock. In reality, the lock even stabilized after much larger impacts like dropping a
screwdriver from 30cm or running against the table. These situations are not uncommon
when working in a lab, and using a controller which does not require manual interaction
in the case of such events increases productivity a lot. Also the new oscilloscope feature
of the GUI simplifies debugging during the development process on the FPGA as well as
configuration of the relocking feature. This is due to the possibility of having a live view
15
of the filtered PID output used in the out-of-lock detection module, which can then be
used to choose the cutoff frequencies and threshold values.
Still, lots of further improvements could be made: for example the ability to stream
more than one channel simultaneously (at cost of package length) or even automagical
configuration of the whole device to reduce (re-)configuration effort once again. The
implementation of these features is greatly eased by the code structure of the Python
GUI, giving users the flexibility to automate these actions in the future without needing
to modify the FPGA code.
10 Acknowledgements
I would like to express my very great appreciation to my supervisors Professor Dr
Jonathan Home, Mr. Vlad Negnevitsky and Ludwig de Clercq for their outstanding
support, helpful hints and very useful critiques during my work. Additionally I am par-
ticularly grateful for the end-user feedback and assistance given by Mr. Florian Leupold
and Mr. Hsiang-yu Lo during the software testing.
16
A Module documentation and sourcecode
A.1 Low-pass filter
clk Supposed to be a 96 MHz clock. Different clock speeds will alter the cutoff fre-
quency.
data i
Filter input value.
smoothing i
This parameter is meant to be configured with values between 0 and 32767 and
determines the low-pass filter cutoff frequency. Higher values mean faster response.
Further explanations can be found in section 3.3.
data o
Low-pass filtered output value.
module l p f i l t e r (
input clk ,
input signed [ 1 5 : 0 ] data i ,
input signed [ 1 5 : 0 ] smoothing i ,
output reg signed [ 1 5 : 0 ] d a t a o ) ;
// r e a l smoothing i s smoothing ∗2ˆ( −16)
parameter a c c b i t s = 3 1 ;
parameter g a t e d c l o c k b i t s = 1 0 ;
parameter u s e g a t e d c l o c k = 1 ;
wire signed [ 1 5 : 0 ] d a t a o w ;
reg signed [ 1 5 : 0 ] data temp = 0 ;
assign d a t a o w = d a t a r [ a c c b i t s : a c c b i t s − 1 5 ] ;
i n i t i a l begin
d a t a o <= 0 ;
end
// Gated c l o c k t o s l o w down s a m p l i n g r a t e
reg [ g a t e d c l o c k b i t s − 1 : 0 ] g a t e d c l o c k c o u n t e r r = 0 ;
always @( posedge c l k ) begin
if ( use gated clock )
g a t e d c l o c k c o u n t e r r <= g a t e d c l o c k c o u n t e r r + 1 ;
else
17
g a t e d c l o c k c o u n t e r r <= 0 ;
end
endmodule // l p f i l t e r
18
module l p p e a k d e t e c t o r (
input clk ,
i n i t i a l begin
p e a k d e t e c t e d o <= 0 ;
d a t a s l o w l p o <= 0 ;
end
// Make t h e i n p u t an r e g i s t e r f o r o p t i m i z a t i o n p u r p o s e s
reg signed [ 1 5 : 0 ] d a t a i r = 0 ;
reg signed [ 1 5 : 0 ] s m o o t h i n g i r = 0 ;
reg [ 1 5 : 0 ] peak threshold i r = 0;
reg [ 1 5 : 0 ] peak detected ttl i r = 0;
always @( posedge c l k ) begin
d a t a i r <= d a t a i ;
s m o o t h i n g i r <= s m o o t h i n g i ;
p e a k t h r e s h o l d i r <= p e a k t h r e s h o l d i ;
p e a k d e t e c t e d t t l i r <= p e a k d e t e c t e d t t l i ;
end
wire [ 1 5 : 0 ] d a t a i s l o w l p ;
wire [ 1 5 : 0 ] d a t a i l p d i f f ;
// d a t a i l p d i f f i s h i g h −p a s s f i l t e r e d v a l u e
assign d a t a i l p d i f f = d a t a i r − d a t a i s l o w l p ;
wire [ 1 5 : 0 ] d a t a i f i l t e r e d ;
reg [ 1 5 : 0 ] d a t a i f i l t e r e d a b s = 1 6 ’ d0 ;
19
// g e t a b s o l u t e v a l u e o f d a t a i l p d i f f
always @( posedge c l k ) begin
if ( data i filtered [15])
d a t a i f i l t e r e d a b s <= − d a t a i f i l t e r e d ;
e l s e d a t a i f i l t e r e d a b s <= d a t a i f i l t e r e d ;
d a t a i f i l t e r e d o <= d a t a i f i l t e r e d a b s ;
end
// c r e a t e a g a t e d c l o c k t o be used w i t h t h e t t l
// f o r p e a k d e t e c t i o n s i g n a l . we have a
// 16 b i t c o n f i g u r a t i o n r e g i s t e r f o r t t l and want
// t o make i t c o n f i g u r a b l e up t o a l e n g t h o f a b o u t
// one second ( a 96MHz c o u n t e r would use 27 b i t ) .
// so we i n t r o d u c e a 11 b i t g a t e d c l o c k
reg [ 1 0 : 0 ] p e a k d e t e c t i o n g a t e d c l o c k = 0 ;
always @( posedge c l k ) begin
p e a k d e t e c t i o n g a t e d c l o c k <= p e a k d e t e c t i o n g a t e d c l o c k + 1 ;
end
reg [ 1 5 : 0 ] p e a k d e t e c t i o n r s t c o u n t e r r = 0 ;
20
d a t a s l o w l p o <= d a t a i s l o w l p ;
// a r e s e t w i l l c l e a r t h e peak d e t e c t i o n s i g n a l
// and t t l c o u n t e r i m m e d i a t e l y
i f ( p e a k d e t e c t e d r s t i == 0 ) begin
p e a k d e t e c t e d o <= 0 ;
p e a k d e t e c t i o n r s t c o u n t e r r <= 0 ;
end
end
endmodule // l p p e a k d e t e c t o r
References
[1] Eric D. Black. “An introduction to Pound-Drever-Hall laser frequency stabiliza-
tion”. In: American Journal of Physics 69.1 (Jan. 2001), pp. 79–87. issn: 00029505.
doi: 10.1119/1.1286663. url: http://dx.doi.org/10.1119/1.1286663.
[2] Christian Blatter. Laplace-Transformationen. German, p. 186. url: http://www.
math.ethz.ch/~blatter/complex_8.pdf.
[3] Luke Campagnola. PyQtGraph. Scientific Graphics and GUI Library for Python.
June 14, 2013. url: http://www.pyqtgraph.org/.
[4] Global Intepreter Lock. Python Wiki. June 13, 2013. url: http://wiki.python.
org/moin/GlobalInterpreterLock?action=recall&rev=27.
[5] J. D. Hunter. “Matplotlib: A 2D graphics environment”. In: Computing In Science
& Engineering 9.3 (2007), pp. 90–95.
[6] A. V. Oppenheim and R. W. Schafer. Discrete-time signal processing. Prentice
Hall, 1989.
[7] Athanasios Papoulis. Circuits and Systems. A Modern Approach. 1980, p. 100.
[8] Elena Punskaya. Basics of Digital Filters. url: http : / / www - sigproc . eng .
cam . ac . uk / ~op205 / 3F3 _ 4 _ Basics _ of _ Digital _ FIlters . pdf (visited on
06/26/2013).
[9] Wikipedia. A circuit diagram of a simple 1st order RC lowpass filter. url: http:
//en.wikipedia.org/wiki/File:1st_Order_Lowpass_Filter_RC.svg (visited
on 06/26/2013).
[10] Wikipedia. Low-pass filter — Wikipedia, The Free Encyclopedia. 2013. url: http:
/ / en . wikipedia . org / w / index . php ? title = Low - pass _ filter & oldid =
559549649 (visited on 06/27/2013).
21