From c0b9a7358e7d8720153887e8bb266c7084477302 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 3 Apr 2012 16:47:56 +0100 Subject: [PATCH] added read ADC function --- papers/software_fmea/software_fmea.tex | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/papers/software_fmea/software_fmea.tex b/papers/software_fmea/software_fmea.tex index 17ccbab..6f33f56 100644 --- a/papers/software_fmea/software_fmea.tex +++ b/papers/software_fmea/software_fmea.tex @@ -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} \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 }