%! TEX root = ../thesis.tex
\chapter{Theory}
<containing the theoretical evaluation of the Problem and excludes possible procedures used in the experimental setup>

\section{Hardware Component Behavior}
Before discussing the experimental results it needs to be clear what circuitry is used in these experiments and what behavior we expect. 
Keeping in mind, that these values are purely theoretical and will most likely not correspond to those found in actual harware.

Each of the three voltage regimes that will be observed on the PowerIt Board, has a Voltage and in the cases of 48V and 1.8V also a current measuremet circuit. Additionaly we have a temperature sensor built into the STM32 Chip used on the Board.
\subsection{48V Input Voltage}
\begin{figure}[H]
    \centering
    \includegraphics[width=.9\textwidth]{./tikz/mon48v.pdf}
    \caption{Circuit for measuring the 48V input Voltage, consisting of input potential, two resistors as voltage divider, one full differential operational amplifier (full Diff Op Amp), one operational Amplifier, output voltage as well as the connection to the STM32-Chips input pin}
    \label{mon48v}
\end{figure}

The circuits for measuring input Voltage and current are the most complex, because for Voltage measurement the circuit needs to
\begin{itemize}
    \item divide our input voltage into a usable potential range
    \item decouple the input from our signal potential
    \item operate within the Chips possible Voltage range of 0 -- 3.3V
\end{itemize}

The already implemented Cicuit can be seen in \autoref{mon48v}. It consists of a 1:240 Voltage Divider, a full differential operational amplifier taking in the ~200mV (nominal), and amplifying it by a factor of 8 ($r_\text{diffOpAmp}$). It is also decoupling the input and output voltages, so our 48V and 3.3V circuit parts are electricly insulated. The remaining operational amplifier provides futher amplification by a factor of 1.1 ($r_\text{OpAmp}$)

This circuit results in the following equation for calculating the input voltage from a pin voltage:

\begin{equation}
    V_\text{48V in}\cdot\frac{R_1}{R_1+R_2} \cdot r_\text{diffOpAmp} \cdot r_\text{OpAmp} = V_\text{48V pin}
\end{equation}

% and the expected behavior, as seen in \autoref{beh48v}
% 
% \begin{figure}[h]
%     \centering
%     \hspace*{-.16\textwidth}
%     \includegraphics[width=1.3\textwidth]{./data/theory/v48.pdf}
%     \caption{Expected behavior of our 48V measurement circuit}
%     \label{beh48v}
% \end{figure}

\subsection{48V Input Current}

\begin{figure}[H]
    \centering
    \includegraphics[width=.9\textwidth]{./tikz/mon48i.pdf}
    \caption{Circuit for measuring the 48V input Current, consisting of the powerit Input Circuit, one shunt-resistor, one full diff Op Amp, one Op Amp, output potential, as well as the connection to the STM32-Chip input pin}
    \label{mon48i}
\end{figure}

In case of the current measurement circuit we require the following:
\begin{enumerate}
    \item use a shunt resistor, with minimal heat dissipation 
    \item still providing a good resolution also within the Chips Specifications
\end{enumerate}

Our calculation is based on:
\begin{equation}
    I_\text{48V IN}\cdot R_{shunt} \cdot r_\text{diffOpAmp} \cdot r_\text{OpAmp} = V_\text{48I pin}
\end{equation}

% so we expect:
% \begin{figure}[h]
%     \centering
%     \caption{Expected behavior of our input current measurement circuit}
%     \hspace*{-.16\textwidth}
%     \includegraphics[width=1.3\textwidth]{./data/theory/i48.pdf}
%     \label{beh48i}
% \end{figure}

\subsection{9.6V Output Voltage}
Consists of a a simple 1:4 Voltage Divider.

\subsection{1.8V Output Voltage}

\begin{figure}[H]
    \centering
    \includegraphics[width=.6\textwidth]{./tikz/gen18v.pdf}
    \caption{Circuit for generating a changable Output Voltage}
    \label{fig:gen18v}
\end{figure}

The in \autoref{fig:gen18v} used 1.8V stepdown modules have a characteristic formual \cite{pth08t}

\begin{align}
    R_{potentiometer} = P_{val} \frac{10k\Omega}{256} \label{eq:rpot}\\
    R_{SET} =& 1 / \left(\frac{1}{R_{potentiometer}} + \frac{1}{R_{parallel}}\right) + R_{series}\nonumber\\
    =& \frac{R_\text{potentiometer}\cdot R_\text{parallel}}{R_\text{potentiometer} + R_\text{parallel}} + R_\text{series}\label{eq:rset}\\
    V_O =& \frac{30.1 k\Omega}{R_{SET} + 6.49 k\Omega} \cdot 0.7V + 0.7V\label{eq:vout}
\end{align}

\begin{figure}[H]
    \centering
    \hspace*{-.13\textwidth}
    \includegraphics[width=1.3\textwidth]{./data/theory/v18.pdf}
    \caption{Expected bahavior of our output voltage by setting the potentiometer}
    \label{beh1v8}
\end{figure}
\subsection{1.8V Output Current}

\section{ADC Calibration}

As mentioned beforehand, the actual hardware will differ in behavior from its theoretical counterpart. THese discrepancies will in fact differ by more than a safe to assume noise on our signal. Therefore we can say that all signals with a signoficant difference of behavior ($\approx 5\%$) will need to be corrected.

To calibrate these readouts we need to employ some simple actions.

\subsection{serial ADC readout}
While the measurements done by the STM32-Chip are using a 12bit ADC, we don't have enough of these inside to be able to completely parallelize the measurements, also only one ADC will be connected to all connected Pins and switch between them.

\section{1.8V Output Regulation}
%\section{Firmware Requirements}

\section{Power Wafer}
To test the 1.8V Regulation the so called Power Wafer is going to be used, it bahves similarly to a in BrainScales used "fuctional" Wafer module. But it is fundamentally different, as it cannot be used for computation, but only to test for voltages and currents. Its internals behave like switchable ohmic resistors, which provides us with a macimum power draw per section (Reticle) of what is allowed inside a usable wafer.

Like its counterparts, it has the same Layout

\begin{figure}[H]
    \centering
    \includegraphics[width=\columnwidth]{./pitstop/20180727/ret_pic.pdf}
    \caption{example diagram of power wafer, 16 Reticles in use}
\end{figure}

and each of the 48 Reticles can be accessed, digitaly as well as electricaly.

For this work the circuit model in \autoref{retmodel} can be used to describe the connections, powering these Reticles.

\begin{figure}[H]
    \centering
    \includegraphics[width=.4\columnwidth]{./tikz/reticlepower.pdf}
    \caption{model of the to measure resistances and their currents, $R_0$ describes the resistance of a connection between the PowerIt Output and up to the switch, while $R_1$ is a Resistance between the switches and Reticles. }
    \label{retmodel}
\end{figure}

This model allowes for two fixed resistance values and their respective currents. The current flowing through $R_1$ will be either 0 or a constant current $I_{ret}$. The current through $R_0$ will change depending on the number of reticles that are powered $n_{ret}$

\begin{align}
    I_{ges} = n_{ret} \cdot I_{ret}
\end{align}

Therefore the voltage Differential as measured by a Voltmeter (\autoref{retmodel}) can be described with \autoref{eq:vdip}

\begin{align} \label{eq:vdip}
    V_{dip} =&\ V_{R_1} + V_{R_0} \nonumber\\
            =&\ R_1 \cdot I_{ret} + R_0 \cdot I_{ges} \nonumber\\
            =&\ I_{ret} \cdot \left( R_1 + R_0 \cdot n_{ret} \right)
\end{align}

Combining Equations \ref{eq:rset}, \ref{eq:vout} and  %TODO
we gather \autoref{eq:fullreg}

\begin{align} \label{eq:fullreg}
    P_{val} = \frac{
        R_{par} \left[ \left( \frac{0.7V \cdot 30.1k\Omega}{V_{O}-0.7V} - 6.49k\Omega \right) - R_{ser}\right]
    }{
        R_{par} + \left( \frac{0.7V \cdot 30.1k\Omega}{V_{O}-0.7V} - 6.49k\Omega \right) - R_{ser}
    }\cdot
    \frac{256}{10k\Omega}
\end{align}

inside the code used for Regulation %TODO: reference
, \autoref{eq:fullreg} will be used to create a lookup table, while \autoref{eq:vout2} will be used at runtime, for which Equations \ref{eq:vdip} and \ref{eq:voff} are needed.

\begin{align} \label{eq:voff}
    V_{dip} =& V_O - V_{off}\\
    \Rightarrow V_O =& I_{ret} \cdot \left( R_1 + R_0 \cdot n_{ret} \right) + V{off}\label{eq:vout2}
\end{align}


Alternatively:

\begin{figure}[H]
    \centering
    \includegraphics[width=.5\columnwidth]{tikz/reticlepower_2}
    \caption{retpow2}
    \label{fir:retmodelshell}
\end{figure}

so we expect the voltage to change depending on the reticles distance to the nearest voltage supply pad.
