\section{aversive\_\-10-03-12/modules/hardware/adc/adc.h File Reference}
\label{adc_8h}\index{aversive\_\-10-03-12/modules/hardware/adc/adc.h@{aversive\_\-10-03-12/modules/hardware/adc/adc.h}}
Interface of the ADC Module. 

{\tt \#include $<$aversive.h$>$}\par
{\tt \#include $<$adc\_\-archs.h$>$}\par
{\tt \#include $<$adc\_\-config.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf ADC\_\-MODE\_\-INT}~0x0200
\item 
\#define {\bf ADC\_\-MODE\_\-TRIGGERED}~0x0400
\item 
\#define {\bf ADC\_\-MODE\_\-10\_\-BITS}~0
\item 
\#define {\bf ADC\_\-MODE\_\-16\_\-BITS}~ADLAR\_\-MASK\_\-IN\_\-CONFIG
\item 
\#define {\bf ADC\_\-RESULT\_\-SIGNED}~0x1000
\item 
\#define {\bf ADC\_\-NO\_\-CONFIG}~0xFFFF
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf adc\_\-init} (void)
\item 
void {\bf adc\_\-shutdown} (void)
\item 
void {\bf adc\_\-register\_\-event} (void($\ast$f)(int16\_\-t))
\item 
void {\bf adc\_\-launch} (uint16\_\-t conversion\_\-config)
\item 
int16\_\-t {\bf adc\_\-get\_\-value} (uint16\_\-t conversion\_\-config)
\item 
int32\_\-t {\bf adc\_\-get\_\-value32} (void $\ast$conversion\_\-config)
\end{CompactItemize}


\subsection{Detailed Description}
Interface of the ADC Module. 

\begin{Desc}
\item[{\bf Todo}]some ATtiny support to add\end{Desc}
\begin{Desc}
\item[{\bf Test}]nothing done\end{Desc}
This module provides access to the built-in ADC unit of the AVR uCs. 

Definition in file {\bf adc.h}.

\subsection{Define Documentation}
\index{adc.h@{adc.h}!ADC\_\-MODE\_\-10\_\-BITS@{ADC\_\-MODE\_\-10\_\-BITS}}
\index{ADC\_\-MODE\_\-10\_\-BITS@{ADC\_\-MODE\_\-10\_\-BITS}!adc.h@{adc.h}}
\subsubsection[ADC\_\-MODE\_\-10\_\-BITS]{\setlength{\rightskip}{0pt plus 5cm}\#define ADC\_\-MODE\_\-10\_\-BITS~0}\label{adc_8h_0847708bfc6f1b047fcf4ba96257fca0}




Definition at line 102 of file adc.h.\index{adc.h@{adc.h}!ADC\_\-MODE\_\-16\_\-BITS@{ADC\_\-MODE\_\-16\_\-BITS}}
\index{ADC\_\-MODE\_\-16\_\-BITS@{ADC\_\-MODE\_\-16\_\-BITS}!adc.h@{adc.h}}
\subsubsection[ADC\_\-MODE\_\-16\_\-BITS]{\setlength{\rightskip}{0pt plus 5cm}\#define ADC\_\-MODE\_\-16\_\-BITS~ADLAR\_\-MASK\_\-IN\_\-CONFIG}\label{adc_8h_aa2377ac713caafbb50c626bee38680a}




Definition at line 103 of file adc.h.

Referenced by adc\_\-get\_\-value(), and SIGNAL().\index{adc.h@{adc.h}!ADC\_\-MODE\_\-INT@{ADC\_\-MODE\_\-INT}}
\index{ADC\_\-MODE\_\-INT@{ADC\_\-MODE\_\-INT}!adc.h@{adc.h}}
\subsubsection[ADC\_\-MODE\_\-INT]{\setlength{\rightskip}{0pt plus 5cm}\#define ADC\_\-MODE\_\-INT~0x0200}\label{adc_8h_38a02a089e244d30b98ff1186d46eb52}


Set this flag for using interruptions instead of polling. If you use this, do not call the \doxyref{adc\_\-get\_\-value()}{p.}{adc_8c_2383ba2c31776e417ed11773281f8350} function ! 

Definition at line 79 of file adc.h.

Referenced by adc\_\-launch().\index{adc.h@{adc.h}!ADC\_\-MODE\_\-TRIGGERED@{ADC\_\-MODE\_\-TRIGGERED}}
\index{ADC\_\-MODE\_\-TRIGGERED@{ADC\_\-MODE\_\-TRIGGERED}!adc.h@{adc.h}}
\subsubsection[ADC\_\-MODE\_\-TRIGGERED]{\setlength{\rightskip}{0pt plus 5cm}\#define ADC\_\-MODE\_\-TRIGGERED~0x0400}\label{adc_8h_c69741b2785248dc36edad399e33aa53}


Flag for triggered mode. 

Definition at line 84 of file adc.h.

Referenced by adc\_\-launch().\index{adc.h@{adc.h}!ADC\_\-NO\_\-CONFIG@{ADC\_\-NO\_\-CONFIG}}
\index{ADC\_\-NO\_\-CONFIG@{ADC\_\-NO\_\-CONFIG}!adc.h@{adc.h}}
\subsubsection[ADC\_\-NO\_\-CONFIG]{\setlength{\rightskip}{0pt plus 5cm}\#define ADC\_\-NO\_\-CONFIG~0xFFFF}\label{adc_8h_e87828460b2a1dc103a794b852c7c266}


This specifies a conversion with no config (uses the previous parameters) always use this flag alone !! 

Definition at line 116 of file adc.h.

Referenced by adc\_\-get\_\-value().\index{adc.h@{adc.h}!ADC\_\-RESULT\_\-SIGNED@{ADC\_\-RESULT\_\-SIGNED}}
\index{ADC\_\-RESULT\_\-SIGNED@{ADC\_\-RESULT\_\-SIGNED}!adc.h@{adc.h}}
\subsubsection[ADC\_\-RESULT\_\-SIGNED]{\setlength{\rightskip}{0pt plus 5cm}\#define ADC\_\-RESULT\_\-SIGNED~0x1000}\label{adc_8h_d35390695af5c1e04d1b2a130ab5f578}


this flag is used internally of the module, use it only if you set manually a differential channel. 

Definition at line 109 of file adc.h.

Referenced by adc\_\-get\_\-value(), adc\_\-launch(), and SIGNAL().

\subsection{Function Documentation}
\index{adc.h@{adc.h}!adc\_\-get\_\-value@{adc\_\-get\_\-value}}
\index{adc\_\-get\_\-value@{adc\_\-get\_\-value}!adc.h@{adc.h}}
\subsubsection[adc\_\-get\_\-value]{\setlength{\rightskip}{0pt plus 5cm}int16\_\-t adc\_\-get\_\-value (uint16\_\-t {\em conversion\_\-config})}\label{adc_8h_2383ba2c31776e417ed11773281f8350}


This function gets an ADC value. If a conversion has been previously started, with EXACTLY the same config (or specifying ADC\_\-NO\_\-CONFIG) then it waits for it to finish. Else it launches a new one with the given config, and polls the result.

This function should not be used if you use interrupts, but only can be used with triggered (or free run mode) 

Definition at line 176 of file adc.c.

References adc\_\-launch(), ADC\_\-MODE\_\-16\_\-BITS, ADC\_\-NO\_\-CONFIG, ADC\_\-RESULT\_\-SIGNED, ADFR, cbi, and sbi.

Referenced by adc\_\-get\_\-value32().\index{adc.h@{adc.h}!adc\_\-get\_\-value32@{adc\_\-get\_\-value32}}
\index{adc\_\-get\_\-value32@{adc\_\-get\_\-value32}!adc.h@{adc.h}}
\subsubsection[adc\_\-get\_\-value32]{\setlength{\rightskip}{0pt plus 5cm}int32\_\-t adc\_\-get\_\-value32 (void $\ast$ {\em conversion\_\-config})}\label{adc_8h_6e9a03c2afa03f741cc284ebeca7b9b1}


Just a int32\_\-t version for compatibility with control\_\-system function prototypes. 

Definition at line 229 of file adc.c.

References adc\_\-get\_\-value().\index{adc.h@{adc.h}!adc\_\-init@{adc\_\-init}}
\index{adc\_\-init@{adc\_\-init}!adc.h@{adc.h}}
\subsubsection[adc\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void adc\_\-init (void)}\label{adc_8h_2b815e6730e8723a6d1d06d9ef8f31c0}


Initialisation of ADC internal registers Can be called for a wake up after a shutdown command 

Definition at line 38 of file adc.c.

References ADC\_\-PRESCALE, and cbi.\index{adc.h@{adc.h}!adc\_\-launch@{adc\_\-launch}}
\index{adc\_\-launch@{adc\_\-launch}!adc.h@{adc.h}}
\subsubsection[adc\_\-launch]{\setlength{\rightskip}{0pt plus 5cm}void adc\_\-launch (uint16\_\-t {\em conversion\_\-config})}\label{adc_8h_85293f51c2bb1a849031e4e5015c33e7}


Launch a conversion : this function launches a conversion with the specified configuration. The conversion\_\-config is casted to an int. 

This disables and reenables the ADC when a different channel is selected AND the new channel is a differential one. Using this trick, the ADC recalibrates, and the time for this allows the amplifier to settle.

Datasheet says : When switching to a differential gain channel, the first conversion result may have a poor accuracy due to the required settling time for the automatic offset cancellation circuitry. The user should preferably disregard the first conversion result. 

Definition at line 111 of file adc.c.

References ADC\_\-MODE\_\-INT, ADC\_\-MODE\_\-TRIGGERED, ADC\_\-RESULT\_\-SIGNED, ADFR, cbi, MUX5\_\-MASK\_\-IN\_\-CONFIG, and sbi.

Referenced by adc\_\-get\_\-value().\index{adc.h@{adc.h}!adc\_\-register\_\-event@{adc\_\-register\_\-event}}
\index{adc\_\-register\_\-event@{adc\_\-register\_\-event}!adc.h@{adc.h}}
\subsubsection[adc\_\-register\_\-event]{\setlength{\rightskip}{0pt plus 5cm}void adc\_\-register\_\-event (void($\ast$)(int16\_\-t) {\em f})}\label{adc_8h_4de34b4cfbaf3afe1f70db5c4244fd6a}


Register callback event. The parameter function is called when the conversion is finished. 

Definition at line 72 of file adc.c.

References parse\_\-symbols::f, IRQ\_\-LOCK, and IRQ\_\-UNLOCK.\index{adc.h@{adc.h}!adc\_\-shutdown@{adc\_\-shutdown}}
\index{adc\_\-shutdown@{adc\_\-shutdown}!adc.h@{adc.h}}
\subsubsection[adc\_\-shutdown]{\setlength{\rightskip}{0pt plus 5cm}void adc\_\-shutdown (void)}\label{adc_8h_6418c68a3bedf1d38d2a7032f64d5bc9}


Shut down the ADC, for power consumption 

Definition at line 56 of file adc.c.

References sbi.