added read ADC function
This commit is contained in:
parent
900c8122f7
commit
c0b9a7358e
@ -387,10 +387,56 @@ int read_4_20_input ( int * value ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{\vbox{
|
||||||
|
\footnotesize
|
||||||
|
\begin{verbatim}
|
||||||
|
/* Software function to read voltage from a */
|
||||||
|
/* specified ADC MUX channel */
|
||||||
|
/* Assume 10 ADC MUX channels 0..9 */
|
||||||
|
/* ADC_CHAN_RANGE = 9 */
|
||||||
|
/* Assume ADC is 12 bit and ADCRANGE = 4096 */
|
||||||
|
/* returns voltage read as double precision */
|
||||||
|
double read_ADC( int channel ) {
|
||||||
|
int timeout = 0;
|
||||||
|
/* require: input channel from ADC to be
|
||||||
|
in valid ADC range */
|
||||||
|
|
||||||
|
/* return out of range result */
|
||||||
|
/* if invalid channel selected */
|
||||||
|
if ( channnel > ADC_CHAN_RANGE )
|
||||||
|
return -2.0;
|
||||||
|
|
||||||
|
/* set the multiplexer to the desired channel */
|
||||||
|
ADCMUX = channel;
|
||||||
|
|
||||||
|
ADCGO = 1; /* initiate ADC conversion hardware */
|
||||||
|
|
||||||
|
/* wait for ADC conversion with timeout */
|
||||||
|
while ( ADCGO == 1 || timeout < 100 )
|
||||||
|
timeout++;
|
||||||
|
|
||||||
|
if ( timeout < 100 )
|
||||||
|
dval = (double) ADCOUT * 5.0 / ADCRANGE;
|
||||||
|
else
|
||||||
|
dval = -1.0; /* indicate invalid reading */
|
||||||
|
|
||||||
|
/* return voltage as a floating point value */
|
||||||
|
return dval;
|
||||||
|
}
|
||||||
|
\end{verbatim}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
\subsection{FMMD Process}
|
\subsection{FMMD Process}
|
||||||
|
|
||||||
\paragraph{Functional Group - Convert mA to Voltage - CMATV}
|
\paragraph{Functional Group - Convert mA to Voltage - CMATV}
|
||||||
|
|
||||||
|
This functional group contains the load resistor
|
||||||
|
and the physical Analogue to Digital Converter (ADC).
|
||||||
|
|
||||||
|
|
||||||
\paragraph{Functional Group - Software - voltage to per mil - VTPM }
|
\paragraph{Functional Group - Software - voltage to per mil - VTPM }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user