\section{aversive\_\-10-03-12/modules/devices/encoders/encoders\_\-microb/encoders\_\-microb.c File Reference}
\label{encoders__microb_8c}\index{aversive\_\-10-03-12/modules/devices/encoders/encoders\_\-microb/encoders\_\-microb.c@{aversive\_\-10-03-12/modules/devices/encoders/encoders\_\-microb/encoders\_\-microb.c}}
Implementation for getting motor position. 

{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$aversive.h$>$}\par
{\tt \#include $<$aversive/wait.h$>$}\par
{\tt \#include $<$encoders\_\-microb.h$>$}\par
{\tt \#include $<$encoders\_\-microb\_\-config.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf SEL\_\-A}()~cbi(ENCODERS\_\-MICROB\_\-SEL\_\-PORT,ENCODERS\_\-MICROB\_\-SEL\_\-BIT)
\item 
\#define {\bf SEL\_\-B}()~sbi(ENCODERS\_\-MICROB\_\-SEL\_\-PORT,ENCODERS\_\-MICROB\_\-SEL\_\-BIT)
\item 
\#define {\bf READ}(n)
\item 
\#define {\bf INIT}(n)
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf encoders\_\-microb\_\-init} (void)
\item 
void {\bf encoders\_\-microb\_\-manage} (void $\ast$dummy)
\item 
int32\_\-t {\bf encoders\_\-microb\_\-get\_\-value} (void $\ast$number)
\item 
void {\bf encoders\_\-microb\_\-set\_\-value} (void $\ast$number, int32\_\-t v)
\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
int32\_\-t {\bf g\_\-encoders\_\-microb\_\-values} [ENCODERS\_\-MICROB\_\-NUMBER]
\item 
int8\_\-t {\bf g\_\-encoders\_\-microb\_\-previous} [ENCODERS\_\-MICROB\_\-NUMBER]
\end{CompactItemize}


\subsection{Detailed Description}
Implementation for getting motor position. 

\begin{Desc}
\item[{\bf Todo}]test the module\end{Desc}
\begin{Desc}
\item[{\bf Test}]nothing done\end{Desc}
This module provides functions for getting position from coders. Its implementation depends on hardware, so that's why there is (or will be) multiple implementation of this module.

The harware is quite simple here :



\footnotesize\begin{verbatim}
 * ----------
 * |        |  8
 * |    PINx|<-/---  value
 * |        |   
 * |        |  8
 * |    PINy|<-/---  value
 * |        |
 * |        |  8
 * |    PINz|<-/---  value
 * |        |
 * |    ....|
 * |        |
 * |    SEL |---->  (1 bit)
 * |        |  
 * |        |
 * |        |
 * ----------
 * \end{verbatim}
\normalsize
 

Definition in file {\bf encoders\_\-microb.c}.

\subsection{Define Documentation}
\index{encoders\_\-microb.c@{encoders\_\-microb.c}!INIT@{INIT}}
\index{INIT@{INIT}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[INIT]{\setlength{\rightskip}{0pt plus 5cm}\#define INIT(n)}\label{encoders__microb_8c_7ad07e49fae706120827feee991d1191}


\textbf{Value:}

\begin{Code}\begin{verbatim}do {                              \
g_encoders_microb_values[n] = 0;                    \
} while(0)
\end{verbatim}
\end{Code}


Definition at line 91 of file encoders\_\-microb.c.

Referenced by encoders\_\-microb\_\-init().\index{encoders\_\-microb.c@{encoders\_\-microb.c}!READ@{READ}}
\index{READ@{READ}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[READ]{\setlength{\rightskip}{0pt plus 5cm}\#define READ(n)}\label{encoders__microb_8c_4428896e01d3b7905e87873255117382}


\textbf{Value:}

\begin{Code}\begin{verbatim}do {                                                \
val = ENCODERS_MICROB##n##_PIN;                     \
nop();                                              \
if (val != ENCODERS_MICROB##n##_PIN)                \
     val = ENCODERS_MICROB##n##_PIN;                \
                                                    \
res = (val - g_encoders_microb_previous[n]);        \
g_encoders_microb_previous[n] = val;                \
                                                    \
g_encoders_microb_values[n] += (int32_t)res ;           \
} while(0)
\end{verbatim}
\end{Code}


Definition at line 76 of file encoders\_\-microb.c.

Referenced by encoders\_\-microb\_\-manage().\index{encoders\_\-microb.c@{encoders\_\-microb.c}!SEL\_\-A@{SEL\_\-A}}
\index{SEL\_\-A@{SEL\_\-A}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[SEL\_\-A]{\setlength{\rightskip}{0pt plus 5cm}\#define SEL\_\-A()~cbi(ENCODERS\_\-MICROB\_\-SEL\_\-PORT,ENCODERS\_\-MICROB\_\-SEL\_\-BIT)}\label{encoders__microb_8c_240d047d4ae92370b7510bbc900404bc}




Definition at line 71 of file encoders\_\-microb.c.

Referenced by encoders\_\-microb\_\-init(), and encoders\_\-microb\_\-manage().\index{encoders\_\-microb.c@{encoders\_\-microb.c}!SEL\_\-B@{SEL\_\-B}}
\index{SEL\_\-B@{SEL\_\-B}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[SEL\_\-B]{\setlength{\rightskip}{0pt plus 5cm}\#define SEL\_\-B()~sbi(ENCODERS\_\-MICROB\_\-SEL\_\-PORT,ENCODERS\_\-MICROB\_\-SEL\_\-BIT)}\label{encoders__microb_8c_4c909f2f3eaa972ee1dfda9a423f009a}




Definition at line 72 of file encoders\_\-microb.c.

Referenced by encoders\_\-microb\_\-init(), and encoders\_\-microb\_\-manage().

\subsection{Function Documentation}
\index{encoders\_\-microb.c@{encoders\_\-microb.c}!encoders\_\-microb\_\-get\_\-value@{encoders\_\-microb\_\-get\_\-value}}
\index{encoders\_\-microb\_\-get\_\-value@{encoders\_\-microb\_\-get\_\-value}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[encoders\_\-microb\_\-get\_\-value]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t encoders\_\-microb\_\-get\_\-value (void $\ast$ {\em number})}\label{encoders__microb_8c_9d9adaec8e6d0d3da17df30f1a9e6b5d}


Extract encoder value.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em number}]: a (void $\ast$) that is casted in (int) containing the number of the encoder to be read. \end{description}
\end{Desc}


Definition at line 230 of file encoders\_\-microb.c.

References g\_\-encoders\_\-microb\_\-values, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{encoders\_\-microb.c@{encoders\_\-microb.c}!encoders\_\-microb\_\-init@{encoders\_\-microb\_\-init}}
\index{encoders\_\-microb\_\-init@{encoders\_\-microb\_\-init}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[encoders\_\-microb\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-microb\_\-init (void)}\label{encoders__microb_8c_2073f9583e96f003e587b88ca942f563}


Initialisation of encoders, variables 

Definition at line 104 of file encoders\_\-microb.c.

References DDR, encoders\_\-microb\_\-manage(), INIT, IRQ\_\-LOCK, IRQ\_\-UNLOCK, sbi, SEL\_\-A, SEL\_\-B, and wait\_\-4cyc.\index{encoders\_\-microb.c@{encoders\_\-microb.c}!encoders\_\-microb\_\-manage@{encoders\_\-microb\_\-manage}}
\index{encoders\_\-microb\_\-manage@{encoders\_\-microb\_\-manage}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[encoders\_\-microb\_\-manage]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-microb\_\-manage (void $\ast$ {\em dummy})}\label{encoders__microb_8c_e3d9e9664caa710b4fa3642d585b940c}


Update encoders values, need to be done quite often (Fmax\_\-encoders/64). First, encoders 0 2 4 6 are read, and at next call encoders 1 3 5 7.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dummy}]: a (void $\ast$) pointer that is not used. It is here according to the encoders interface. \end{description}
\end{Desc}


Definition at line 166 of file encoders\_\-microb.c.

References IRQ\_\-LOCK, IRQ\_\-UNLOCK, READ, SEL\_\-A, and SEL\_\-B.

Referenced by encoders\_\-microb\_\-init().\index{encoders\_\-microb.c@{encoders\_\-microb.c}!encoders\_\-microb\_\-set\_\-value@{encoders\_\-microb\_\-set\_\-value}}
\index{encoders\_\-microb\_\-set\_\-value@{encoders\_\-microb\_\-set\_\-value}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[encoders\_\-microb\_\-set\_\-value]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-microb\_\-set\_\-value (void $\ast$ {\em number}, \/  int32\_\-t {\em v})}\label{encoders__microb_8c_d092fd840e8a0f207e6f0961245a1e69}


Set an encoder value

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em number}]: a (void $\ast$) that is casted in (int) containing the number of the encoder to be read. \item[{\em v}]: the value \end{description}
\end{Desc}


Definition at line 248 of file encoders\_\-microb.c.

References g\_\-encoders\_\-microb\_\-values, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.

\subsection{Variable Documentation}
\index{encoders\_\-microb.c@{encoders\_\-microb.c}!g\_\-encoders\_\-microb\_\-previous@{g\_\-encoders\_\-microb\_\-previous}}
\index{g\_\-encoders\_\-microb\_\-previous@{g\_\-encoders\_\-microb\_\-previous}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[g\_\-encoders\_\-microb\_\-previous]{\setlength{\rightskip}{0pt plus 5cm}int8\_\-t {\bf g\_\-encoders\_\-microb\_\-previous}[ENCODERS\_\-MICROB\_\-NUMBER]}\label{encoders__microb_8c_277d10e8f786a4ded94db24834de8956}




Definition at line 67 of file encoders\_\-microb.c.\index{encoders\_\-microb.c@{encoders\_\-microb.c}!g\_\-encoders\_\-microb\_\-values@{g\_\-encoders\_\-microb\_\-values}}
\index{g\_\-encoders\_\-microb\_\-values@{g\_\-encoders\_\-microb\_\-values}!encoders_microb.c@{encoders\_\-microb.c}}
\subsubsection[g\_\-encoders\_\-microb\_\-values]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t {\bf g\_\-encoders\_\-microb\_\-values}[ENCODERS\_\-MICROB\_\-NUMBER]}\label{encoders__microb_8c_20236195bfe55fa3a731efc2ef794d13}




Definition at line 66 of file encoders\_\-microb.c.

Referenced by encoders\_\-microb\_\-get\_\-value(), and encoders\_\-microb\_\-set\_\-value().