
\section{ARTIQ SU-Servo}

    ARTIQ also allows for the joint configuration of one or two 4410 DDS Urukul cards and a 5108 Sampler as an integrated servo for laser intensity stabilization and similar purposes. SU-Servo also supports other additional features, such as preconfigured profiles per channel and automatic integrator hold. Urukuls must be 4410 AD9910 variants (not 4412 AD9912) and set to SU-Servo mode by DIP switch.

\subsection{SU-Servo System Description Entry}

    SU-Servo should be entered in the peripherals list of the corresponding core device in a single entry in the following format:

    \begin{tcolorbox}[colback=white]
        \begin{minted}{json}
            {
                "type": "suservo",
                "sampler_ports": [0, 1],
                "urukul0_ports": [2, 3],
                "urukul1_ports": [4, 5], // optional
                "clk_sel": 2 // select 1 to 3
            }
        \end{minted}
    \end{tcolorbox}

    Enter the actual EEM port numbers used on the core device. Any ports can be used. If using only one Urukul (and half of the available Sampler channels), the \texttt{urukul1\_ports} field may be left out entirely.

% miraculously, this newpage is good for both Sampler and Urukul datasheets!
% will probably break if any sections are added though
\newpage

\section{Example SU-Servo Code}

    In SU-Servo configuration, amplitude of the Urukul DDS output can be controlled with the Sampler ADC input through PI control, characterised by the following transfer function:

    \[H(s)=k_p+\frac{k_i}{s+\frac{k_i}{g}}\]

    In the following example, the DDS amplitude is set proportionally to the ADC input from Sampler. We initialize SU-Servo and all channels first. Note that the programmable gain of the Sampler is $10^0=1$ and the input range is [-10V, 10V].

    \inputcolorboxminted{firstline=10,lastline=17}{examples/suservo.py}

    Next, we set up the PI control as an IIR filter. It has -1 proportional gain $k_p$ and no integrator gain $k_i$.

    \inputcolorboxminted{firstline=18,lastline=25}{examples/suservo.py}

    Then, configure the DDS frequency to 10 MHz with 3V input offset. When input voltage $\geq$ offset voltage, the DDS output amplitude is 0.

    \inputcolorboxminted{firstline=26,lastline=30}{examples/suservo.py}

    SU-Servo encodes the ADC voltage on a linear scale [-1, 1]. Therefore, 3V is converted to 0.3. Note that the ASF of all DDS channels ss capped at 1.0 and the amplitude clips when ADC input $\leq -7V$ with the above IIR filter.

    Finally, enable the SU-Servo channel with the IIR filter programmed beforehand:

    \inputcolorboxminted{firstline=32,lastline=33}{examples/suservo.py}

    A 10 MHz DDS signal is generated from the example above, with amplitude controllable by ADC. The RMS voltage of the DDS channel against the ADC voltage is plotted. The DDS channel is terminated with 50\textOmega.

    \begin{center}
    \begin{tikzpicture}[
        declare function={
            func(\x)= and(\x>=-10, \x<-7) * (160) +
                and(\x>=-7, \x<3) * (16*(3-x)) +
                and(\x>=3, \x<10) * (0);
        }
    ]
    \begin{axis}[
        axis x line=middle, axis y line=middle,
        every axis x label/.style={
            at={(axis description cs:0.5,-0.1)},
            anchor=north,
        },
        every axis y label/.style={
            at={(ticklabel* cs:1.05)},
            anchor=south,
        },
        minor x tick num=3,
        grid=both,
        height=8cm,
        width=12cm,
        ymin=-5, ymax=180, ytick={0,16,...,160}, ylabel=DDS RMS Voltage ($mV_{rms}$),
        xmin=-10, xmax=10, xtick={-10,-8,...,10}, xlabel=Sampler Voltage ($V$),
    ]

    \addplot[very thick, blue, samples=21, domain=-10:10]{func(x)};
    \end{axis}
    \end{tikzpicture}
    \end{center}

    DDS signal should be attenuated. High output power affects the linearity due to the 1 dB compression point of the amplifier at 13 dBm output power. 15 dB attenuation at the digital attenuator was applied in this example.