\documentclass{article} 

\usepackage[english]{babel}
\usepackage[a4paper,top=2cm,bottom=2cm,left=2cm,right=2cm,marginparwidth=1.75cm]{geometry}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{float}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{listings}
\renewcommand{\familydefault}{\sfdefault}

\title{
    E-Smog detector PCB Design \linebreak
    \large{EV6 - Hardware Implementation}
}

\author{Arne van Iterson}
\date{\today}

\begin{document} 
\maketitle

\begin{abstract}
This document will describe the design process of a noise detection circuit (E-Smog) and data logger using an STM32 Microcontroller
\end{abstract}

    % Several choices have been made directly based on the AN4467 Application note by STMicroelectronics \cite{AN4467}
    % Datasheet \cite{stm32l071}

\begin{multicols}{2}
    \section{Introduction}
    Electronic Smog or E-Smog is electromagnetic radiation emitted by every electronic device. The radiation can interfere with sensors and microphones, in extreme cases, the radiation can be harmful for human beings and animals. The TAPIR E-Smog detector is a circuit featured in Elektor Magazine issue 585 to measure said electromagnetic radiation. \cite{elektor} 

    \begin{figure}[H]
        \includegraphics[width=\linewidth]{./img/esmog.png}
        \caption{Man holding commercial ESmog detector}
        \label{fig:man}
    \end{figure}

    Engineering Students of the University of Applied Sciences Utrecht have been tasked with designing a PCB for this circuit while extending the function of the circuit by including a STM32 microcontroller to log the amount of E-Smog detected.

    \section{Design choices}
    The complete circuit has been divided into several parts, each with its own function. The following sections will describe the design choices made for each distinct part of the circuit.

    \subsection{Power supply}
    \textit{The following parts can be found in the KiCad schematic sub-sheet 'power'.}

    \subsubsection{Voltage regulators}
    The circuit requires two voltages; 1,5 volts for the amplifier circuit and 3,3 volts for the STM32. The input voltage will be roughly between 3.0 and 3.6 volts based on three NiMH rechargeable batteries in series. 

    The amplifier circuit is rated to work at 1,5 volts, however, 1,5 volt low dropout regulators are not common. 1,8 volts is a lot more common, therefore the circuit has been simulated with 1,8 volts instead

    \subsubsection{Soft power-on circuit}
    To turn the device on, a soft power-on circuit has been implemented. The circuit is based on the design by A. Levido and consists of a set of P- and N-channel MOSFETs, a push button and two schottky diodes. \cite{latchcircuit} In the schematic, the IRF7319 package is used, which contains both the P- and N-channel MOSFETs.

    \begin{figure}[H]
        \includegraphics[width=\linewidth]{./img/softpower.png}
        \caption{Soft power-on circuit by A. Levido}
        \label{fig:spwr}
    \end{figure}
    
    The P-Channel MOSFET is in between the battery and the LDO's, when the user presses the button the P-Channel closes and allows the circuit to power on, once the STM has booted, it closes the N-Channel that will keep the circuit on for the duration of the program. The push button is connected via two schottky diodes so it can double as a regular input button for the STM. 
    
    The logger was, as first, supposed to have an SD card to store logs to and a sudden power off could damage the file system of the SD card. The power button also pulls an IO pin on the STM32 low and this would be used to trigger a graceful power off sequence. The SD card has since been removed from the design but the soft power-on circuit has been kept. 

    \subsubsection{Battery voltage feedback}
    The battery voltage is measured using a voltage divider and fed into the STM32 ADC. While this is a simple voltage divider. This is a very simple way to measure the battery voltage that has the disadvantage of constantly depleting the batteries, although very slowly. Using the current design, using two 1M resistors, the current flow is as follows:
    \begin{align*}
        R_{total} &= 2 & [M\Omega] \\
        U &= 3.6 & [V] \\
        I_{total} &= \frac{U}{R_{total}} \\
        &= \frac{3.6}{2 \cdot 10^6} \\
        &= 1.8 \cdot 10^{-3} & [mA] \\
    \end{align*}

    The self-discharge of the batteries is significantly higher than the current flow of the voltage divider, so the impact of the voltage divider is negligible.

    \subsection{E-Smog circuit}
    \textit{The following parts can be found in the KiCad schematic sub-sheet 'smog'.}

    \begin{figure}[H]
        \includegraphics[width=\linewidth]{./img/circuit.png}
        \caption{Original Circuit}
        \label{fig:man}
    \end{figure}

    \subsubsection{Base circuit}
    The base receiving circuit is identical to the one found in the original Elektor Magazine

    \subsubsection{Amplifier}


    \subsubsection{Anti-aliasing filter}
    For the ADC input, we want to attenuate the input signal above the Nyquist frequency to less than half LSB to prevent any aliasing. 

    The STM32L071 has a 12-bit ADC with a maximum sampling rate of 1.14Msps. The Nyquist frequency is half  the sampling rate, so 570kHz.
    For a 12 bit ADC, this LSB value is as follows:
    \begin{align*}
        U_{ref} &= 3.3 & [V] \\
        LSB &= \frac{U_{ref}}{2^{12}} \\
        &= \frac{3.3}{4096} \\
        &= 0.0008056641 & [V] \\
        &= 0.806 & [mV] \\
        \frac{1}{2} LSB &= 0.403 & [mV]
    \end{align*}
    The amplifier can output 3.3V, so the input signal should be attenuated by a factor of:
    \begin{align*}
        20 \cdot \log{\frac{0.403e^{-3}}{3.3}} &= -78,26 & [dB]
    \end{align*}

    Since the circuits purpose is to measure E-Smog within the hearing range, the cutoff should ideally be near between 10 and 20 kHz. Attenuating the signal to a factor of -80dB at 570kHz would mean a cutoff frequency of 5,7 kHz using an LRC filter with a -40dB/decade slope, this is simply not acceptable. 

    Using the full 12-bits of the STM would reduce the amount of bandwidth and maximum measurable frequency, instead, the 10 bit mode of the ADC will be used. While this does limit resolution, the difference will be small since the effective resolution of the particular STM used is only 10.2 bits. \cite{stm32l071} This makes the LSB and cutoff frequency:
    \begin{align*}
        U_{ref} &= 3.3 & [V] \\
        LSB &= \frac{U_{ref}}{2^{10}} \\
        &= \frac{3.3}{1024} \\
        &= 0.003222656 & [V] \\
        &= 3.223 & [mV] \\
        \frac{1}{2} LSB &= 1.611 & [mV] \\
        \\
        20 \cdot \log{\frac{1.611e^{-3}}{3.3}} &= -66.23 & [dB] \\  
        \\
        f_{cutoff} &= 570000 \cdot 10^{-\frac{66.23}{40}} \\
        &= 570000 \cdot 10^{-1.65575} \\
        &= 12595.33 & [Hz]\\
    \end{align*}

    \subsection{Microcontroller}
    \textit{The following parts can be found in the KiCad schematic sub-sheet 'stm'.}

    \subsubsection{Choice of microcontroller}
    The assignment requires 


\end{multicols}

\newpage 

\bibliographystyle{IEEEtran}
\bibliography{main}

\end{document}