\section{aversive\_\-10-03-12/modules/hardware/pwm\_\-ng/pwm\_\-ng.c File Reference}
\label{pwm__ng_8c}\index{aversive\_\-10-03-12/modules/hardware/pwm\_\-ng/pwm\_\-ng.c@{aversive\_\-10-03-12/modules/hardware/pwm\_\-ng/pwm\_\-ng.c}}
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$aversive.h$>$}\par
{\tt \#include $<$aversive/parts.h$>$}\par
{\tt \#include $<$aversive/timers.h$>$}\par
{\tt \#include \char`\"{}pwm\_\-ng.h\char`\"{}}\par
{\tt \#include $<$stdio.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf PWM\_\-SIGNIFICANT\_\-BITS}~12
\item 
\#define {\bf PWM\_\-MAX}~((1$<$$<$ PWM\_\-SIGNIFICANT\_\-BITS)-1)
\item 
\#define {\bf PWM\_\-MIN}~(-PWM\_\-MAX)
\item 
\#define {\bf PWM\_\-NG\_\-TYPE\_\-8}~0
\item 
\#define {\bf PWM\_\-NG\_\-TYPE\_\-16}~1
\item 
\#define {\bf PWM\_\-NG\_\-NBITS\_\-8}~0
\item 
\#define {\bf PWM\_\-NG\_\-NBITS\_\-9}~1
\item 
\#define {\bf PWM\_\-NG\_\-NBITS\_\-10}~2
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf pwm\_\-ng\_\-init} (struct {\bf pwm\_\-ng} $\ast$pwm, uint8\_\-t timer\_\-nbits, uint8\_\-t pwm\_\-nbits, uint8\_\-t pwm\_\-mode, volatile void $\ast$ocrn, uint8\_\-t com0, volatile uint8\_\-t $\ast$tccrn, volatile uint8\_\-t $\ast$pwm\_\-port, uint8\_\-t pwm\_\-bit, volatile uint8\_\-t $\ast$sign\_\-port, uint8\_\-t sign\_\-bit)
\item 
void {\bf pwm\_\-ng\_\-set} (void $\ast$data, int32\_\-t value)
\end{CompactItemize}


\subsection{Define Documentation}
\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-MAX@{PWM\_\-MAX}}
\index{PWM\_\-MAX@{PWM\_\-MAX}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-MAX]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-MAX~((1$<$$<$ PWM\_\-SIGNIFICANT\_\-BITS)-1)}\label{pwm__ng_8c_391fa1e490bd712720989b58fa0d9904}




Definition at line 30 of file pwm\_\-ng.c.\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-MIN@{PWM\_\-MIN}}
\index{PWM\_\-MIN@{PWM\_\-MIN}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-MIN]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-MIN~(-PWM\_\-MAX)}\label{pwm__ng_8c_6a06d5e0af804c23442d316bd0b873d6}




Definition at line 31 of file pwm\_\-ng.c.\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-NG\_\-NBITS\_\-10@{PWM\_\-NG\_\-NBITS\_\-10}}
\index{PWM\_\-NG\_\-NBITS\_\-10@{PWM\_\-NG\_\-NBITS\_\-10}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-NG\_\-NBITS\_\-10]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-NG\_\-NBITS\_\-10~2}\label{pwm__ng_8c_189b93a735ebf4b1d332befe388b7036}




Definition at line 38 of file pwm\_\-ng.c.

Referenced by pwm\_\-ng\_\-init().\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-NG\_\-NBITS\_\-8@{PWM\_\-NG\_\-NBITS\_\-8}}
\index{PWM\_\-NG\_\-NBITS\_\-8@{PWM\_\-NG\_\-NBITS\_\-8}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-NG\_\-NBITS\_\-8]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-NG\_\-NBITS\_\-8~0}\label{pwm__ng_8c_92c40a9d26c8f698c3486b4c48e5274b}




Definition at line 36 of file pwm\_\-ng.c.

Referenced by pwm\_\-ng\_\-init().\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-NG\_\-NBITS\_\-9@{PWM\_\-NG\_\-NBITS\_\-9}}
\index{PWM\_\-NG\_\-NBITS\_\-9@{PWM\_\-NG\_\-NBITS\_\-9}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-NG\_\-NBITS\_\-9]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-NG\_\-NBITS\_\-9~1}\label{pwm__ng_8c_a0223f0b0cf7532b6b1591a2e0e28cca}




Definition at line 37 of file pwm\_\-ng.c.

Referenced by pwm\_\-ng\_\-init().\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-NG\_\-TYPE\_\-16@{PWM\_\-NG\_\-TYPE\_\-16}}
\index{PWM\_\-NG\_\-TYPE\_\-16@{PWM\_\-NG\_\-TYPE\_\-16}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-NG\_\-TYPE\_\-16]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-NG\_\-TYPE\_\-16~1}\label{pwm__ng_8c_8ea4775f9f53fa8bdfc7b7b6c478b2ca}




Definition at line 34 of file pwm\_\-ng.c.

Referenced by pwm\_\-ng\_\-init().\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-NG\_\-TYPE\_\-8@{PWM\_\-NG\_\-TYPE\_\-8}}
\index{PWM\_\-NG\_\-TYPE\_\-8@{PWM\_\-NG\_\-TYPE\_\-8}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-NG\_\-TYPE\_\-8]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-NG\_\-TYPE\_\-8~0}\label{pwm__ng_8c_43644fd0b6e5cfb3d222b4c821735e13}




Definition at line 33 of file pwm\_\-ng.c.

Referenced by pwm\_\-ng\_\-init(), and pwm\_\-ng\_\-set().\index{pwm\_\-ng.c@{pwm\_\-ng.c}!PWM\_\-SIGNIFICANT\_\-BITS@{PWM\_\-SIGNIFICANT\_\-BITS}}
\index{PWM\_\-SIGNIFICANT\_\-BITS@{PWM\_\-SIGNIFICANT\_\-BITS}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[PWM\_\-SIGNIFICANT\_\-BITS]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-SIGNIFICANT\_\-BITS~12}\label{pwm__ng_8c_a266101c8fc60ae17f1f27311dee1e4f}




Definition at line 29 of file pwm\_\-ng.c.

Referenced by pwm\_\-ng\_\-set().

\subsection{Function Documentation}
\index{pwm\_\-ng.c@{pwm\_\-ng.c}!pwm\_\-ng\_\-init@{pwm\_\-ng\_\-init}}
\index{pwm\_\-ng\_\-init@{pwm\_\-ng\_\-init}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[pwm\_\-ng\_\-init]{\setlength{\rightskip}{0pt plus 5cm}void pwm\_\-ng\_\-init (struct {\bf pwm\_\-ng} $\ast$ {\em pwm}, \/  uint8\_\-t {\em timer\_\-nbits}, \/  uint8\_\-t {\em pwm\_\-nbits}, \/  uint8\_\-t {\em pwm\_\-mode}, \/  volatile void $\ast$ {\em ocrn}, \/  uint8\_\-t {\em com0}, \/  volatile uint8\_\-t $\ast$ {\em tccrn}, \/  volatile uint8\_\-t $\ast$ {\em pwm\_\-port}, \/  uint8\_\-t {\em pwm\_\-bit}, \/  volatile uint8\_\-t $\ast$ {\em sign\_\-port}, \/  uint8\_\-t {\em sign\_\-bit})}\label{pwm__ng_8c_ec71511876da9c859dd174f8d01db8cb}


Inititialize a PWM: set its mode, output pin DDR, DDR for sign bit if any. Example for 8 bits (for atmega128): pwm\_\-ng\_\-init(\&pwm, 8, 8, PWM\_\-NG\_\-MODE\_\-SIGNED$|$PWM\_\-NG\_\-MODE\_\-SIGN\_\-INVERTED, \&OCR0, COM00, \&TCCR0, \&PORTB, 4, \&PORTE, 3); Example for 16 bits (for atmega32): pwm\_\-ng\_\-init(\&pwm, 16, 9, PWM\_\-NG\_\-MODE\_\-NORMAL, \&OCR1B, COM1B0, \&TCCR1A, \&PORTD, 5, NULL, 0); Note that you can use the helper macros \doxyref{PWM\_\-NG\_\-INIT8()}{p.}{pwm__ng_8h_4a6dbe41f581170242e319fcc43159af} or \doxyref{PWM\_\-NG\_\-INIT16()}{p.}{pwm__ng_8h_baed42251af85bffdfce84db38033dc3} instead. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em pwm}]is the pointer to the pwm structure that will be filled. \item[{\em nbits}]is the number of bits for the timer (8 or 16). \item[{\em pwm\_\-mode}]is the mode of the PWM. See the PWM\_\-NG\_\-MODE\_\-xxx flags above. \item[{\em ocrn}]is a pointer to the OCRn register for this PWM. \item[{\em com0}]is the COMn0 for this PWM. \item[{\em pwm\_\-port}]is the pointer to the PORT of the pwm corresponding to the configured PWM. For instance \&PORTB. This is specified in the datasheets, and depends on the AVR part. \item[{\em pwm\_\-bit}]is the bitnum of the configured pwm output. This is specified in the datasheets, and depends on the AVR part. \item[{\em sign\_\-port}]is a poinrter to the PORT for the sign bit if any, else, it can be set to NULL. \item[{\em sign\_\-bit}]is the bitnum of the configured sign output. \end{description}
\end{Desc}


Definition at line 40 of file pwm\_\-ng.c.

References DDR, pwm\_\-ng::mode, pwm\_\-ng::nbits, pwm\_\-ng::ocr16, pwm\_\-ng::ocr8, PWM\_\-NG\_\-MODE\_\-REVERSE, PWM\_\-NG\_\-MODE\_\-SIGNED, PWM\_\-NG\_\-NBITS\_\-10, PWM\_\-NG\_\-NBITS\_\-8, PWM\_\-NG\_\-NBITS\_\-9, PWM\_\-NG\_\-TYPE\_\-16, PWM\_\-NG\_\-TYPE\_\-8, pwm\_\-ng::sign\_\-bit, pwm\_\-ng::sign\_\-port, pwm\_\-ng::type, and pwm\_\-ng::u.\index{pwm\_\-ng.c@{pwm\_\-ng.c}!pwm\_\-ng\_\-set@{pwm\_\-ng\_\-set}}
\index{pwm\_\-ng\_\-set@{pwm\_\-ng\_\-set}!pwm_ng.c@{pwm\_\-ng.c}}
\subsubsection[pwm\_\-ng\_\-set]{\setlength{\rightskip}{0pt plus 5cm}void pwm\_\-ng\_\-set (void $\ast$ {\em pwm}, \/  int32\_\-t {\em value})}\label{pwm__ng_8c_9e732a1c8fef62b52fe146079a78e9ce}


apply a PWM. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em pwm}]is a pointer to the struct pwm. \item[{\em value}]is the value of the pwm. The value is between 0 and 4095 for a non-signed pwm or -4096 and 4095 for a signed one. \end{description}
\end{Desc}


Definition at line 112 of file pwm\_\-ng.c.

References MAX, MIN, pwm\_\-ng::mode, pwm\_\-ng::nbits, pwm\_\-ng::ocr16, pwm\_\-ng::ocr8, pwm\_\-invert\_\-value, PWM\_\-MAX, PWM\_\-MIN, PWM\_\-NG\_\-MODE\_\-SIGNED, PWM\_\-NG\_\-TYPE\_\-8, PWM\_\-SIGNIFICANT\_\-BITS, pwm\_\-ng::type, and pwm\_\-ng::u.