From 30e1d1e8be54cb0e05bc144e8a5d9313d536cad1 Mon Sep 17 00:00:00 2001
From: Kamal Alkahwati <kamal.alkahwati@gmail.com>
Date: Thu, 22 Dec 2016 19:02:44 +0100
Subject: [PATCH] added timer chapter in implementation, minor changes on
 different

---
 chapters/result.tex              |  5 +++++
 implementation/Timer.tex         | 34 ++++++++++++++++++++++++++++++++
 implementation/motor-stepper     |  2 ++
 implementation/motor-stepper.tex |  1 +
 implementation/ppm.tex           |  1 +
 implementation/sonar.tex         |  7 ++-----
 main.tex                         |  1 +
 7 files changed, 46 insertions(+), 5 deletions(-)
 create mode 100644 implementation/Timer.tex

diff --git a/chapters/result.tex b/chapters/result.tex
index 5671f08..566ccd7 100644
--- a/chapters/result.tex
+++ b/chapters/result.tex
@@ -51,6 +51,11 @@ The final result of the project, in regards to fulfilled goals, is as follows:
     The sensors were ordered and should accompany this project.
     The dev board shield has connectors dedicated to IR sensor connections, although these contacts have since been repurposed as general status LEDs.
 
+\subsection{Sonars - Final state}
+    \subsectionauthor{Author: Kamal Alkahwati}
+    The Sonars are implemented according to specification requirements but
+    upon testing it was discovered that they do malfunction sometimes. If HC-SR04 needs to measure a distance of more than ~600cm it will often malfuncion and give random measurement data. The problem is that the timeout of HC-SR04 doesn't work as it should, and instead of giving a timeout-pulse it just sends random data. It is suspected that this is a result of a too cheap assembly. This is solved using software filters, but they should be replace all in all in the future.
+
 
 \subsection{Collision Avoidance - Final state}
     \subsectionauthor{Author: Lars Jonsson}
diff --git a/implementation/Timer.tex b/implementation/Timer.tex
new file mode 100644
index 0000000..fa075d8
--- /dev/null
+++ b/implementation/Timer.tex
@@ -0,0 +1,34 @@
+\subsection{Timer}
+\subsectionauthor{Author: Kamal Alkahwati}
+	Six separate timers are implemented for a different range of functionalities.
+
+	\begin{itemize}
+            \item TIM1 - PWM generator for triggering sonars
+            \item TIM2 - Dedicated Input Capture for manipulating PPM signals.
+            \item TIM3 - Input capture channels 1 \& 2 are used for distance measuring on sonars.
+            \item TIM4 - Input capture channels 1,2,3,4 are used for distance measuring on sonars.
+            \item TIM5 - Used to regurlarly fetch data from LiDAR
+            \item TIM9 - PWM generator used to drive the stepper motor that the LiDAR is mounted on.
+        \end{itemize}
+
+Below follows pin description for timers.
+	\begin{table}[H]
+		\begin{center}
+			\begin{tabular}{ l l }
+				\textbf{Pin} & \textbf{Usage} \\
+				\hline
+				PE9 & TIM1 CH1 \\
+				PA15 & TIM2 CH1 \\
+				PC6 & TIM3 CH1 \\
+				PC7 & TIM3 CH2 \\
+				PD12 & TIM4 CH1 \\
+				PD13 & TIM4 CH2 \\
+				PD14 & TIM4 CH3 \\
+				PD15 & TIM4 CH4 \\
+				PE5 & TIM9 CH1
+
+			\end{tabular}
+		\end{center}
+		\caption{Timer Pin Description} \label{tab:TimerPinDescription}
+	\end{table}
+
diff --git a/implementation/motor-stepper b/implementation/motor-stepper
index 393b0d8..57e4c53 100644
--- a/implementation/motor-stepper
+++ b/implementation/motor-stepper
@@ -1,4 +1,6 @@
 \subsection{Stepper motor}
+\subsectionauthor{Author: Kamal Alkahwati}
+
 A stepper motor is used to rotate the lidar to perpendicular to its own movement, thus creating a three dimensional view for the lidar to record.
 \newline
 The stepper motor is controlled via PWM on Timer 9, and the processor receives an interrupt for every step taken to keep track of number of steps (0 - 400). At every lap, a hall effect sensor gets triggered, which induces an extended interrupt on GPIOG Pin 3 to reset the step counter.
\ No newline at end of file
diff --git a/implementation/motor-stepper.tex b/implementation/motor-stepper.tex
index 393b0d8..f768f0f 100644
--- a/implementation/motor-stepper.tex
+++ b/implementation/motor-stepper.tex
@@ -1,4 +1,5 @@
 \subsection{Stepper motor}
+\subsectionauthor{Author: Kamal Alkahwati}
 A stepper motor is used to rotate the lidar to perpendicular to its own movement, thus creating a three dimensional view for the lidar to record.
 \newline
 The stepper motor is controlled via PWM on Timer 9, and the processor receives an interrupt for every step taken to keep track of number of steps (0 - 400). At every lap, a hall effect sensor gets triggered, which induces an extended interrupt on GPIOG Pin 3 to reset the step counter.
\ No newline at end of file
diff --git a/implementation/ppm.tex b/implementation/ppm.tex
index 8cf7f5a..2118a70 100644
--- a/implementation/ppm.tex
+++ b/implementation/ppm.tex
@@ -1,4 +1,5 @@
 \subsection{PPM}
+\subsectionauthor{Author: Kamal Alkahwati}
     The transmitter sends radio signals to the receiver, which converts these into PPM signals
     that the run on 8 different channels for controlling the copter. To be able to apply 
     automatic control to the quad, we need to modify these PPM signals as we'd like them. 
diff --git a/implementation/sonar.tex b/implementation/sonar.tex
index e8b9d7e..c0ff0a1 100644
--- a/implementation/sonar.tex
+++ b/implementation/sonar.tex
@@ -1,4 +1,5 @@
 \subsection{Sonar - HC-SR04}
+\subsectionauthor{Author: Kamal Alkahwati}
 The sonars are triggered by a PWM generator on TIM1, with pulses of $\SI{10}{\micro\second}$ every 65ms. This will result in each sonar measuring in approximately \SI{15}{\hertz}.
 Pulse width measurement is done by using the input capture function on TIM3 CH1-CH2 and TIM4 CH1-CH4 respectively.
 Each input capture pin generates an interrupt if triggered, which in turn calls \emph{computeWidth} function that returns the width in microsecs. The width is then divided by 58, to get distance in cm and then transferred to MSP\_newSonardata.
@@ -11,10 +12,6 @@ Each input capture pin generates an interrupt if triggered, which in turn calls
 \end{figure}
 
 
-To start a measurement, Trig of SR04 must receive high (5V) for at least 10$\mu$s.
-This will initiate the sensor to transmit 8 cycles of ultrasonic bursts at 40KHz and wait for the reflection.
-When the receiver has detected the reflection, it will set the echo pin high (5V) and delay and delay for a period (width) which is proportionate to the distance.
-\\* To get distance in cm: Time/58.
 
 The sensors come complete with an ultrasonic transmitter and receiver module.
 \emph{Note:} If HC-SR04 needs to measure a distance of more than ~600cm it will malfuncion and give random measurement data. It is suspected that this is a result of a too cheap assembly.
@@ -25,5 +22,5 @@ This will initiate the sensor to transmit $\SI{8}{}$ cycles of ultrasonic bursts
 $\SI{40}{\kilo\hertz}$ and wait for the reflection.
 When the receiver has detected the reflection, it will set the echo pin high ($\SI{5}{\volt}$)
 and delay and delay for a period (width) which is proportionate to the distance, before pulling the pin back down.
-\\* To get distance in cm: $Width/58$.
+\\* To get distance in cm: $\frac{Width}{58}$.
 
diff --git a/main.tex b/main.tex
index 6ee00f6..072b95e 100644
--- a/main.tex
+++ b/main.tex
@@ -104,6 +104,7 @@
     \input{./implementation/imu.tex}
 	\input{./implementation/usartComPro.tex}
     \input{./implementation/spi-uwb.tex}
+    \input{./implementation/Timer.tex}
     \input{./implementation/sonar.tex}
     \input{./implementation/ppm.tex}
     \input{./implementation/motor-stepper.tex}
-- 
GitLab