differential input adc board K64F Compatible hal freescale K64F

Fork of AnalogIn_Diff by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AnalogIn_Diff.h Source File

AnalogIn_Diff.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  * Copyright (c) 2014 LAAS-CNRS
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef ANALOGIN_DIFF_H
00019 #define ANALOGIN_DIFF_H
00020 
00021 #include "mbed_assert.h"
00022 #include "analogin_api.h"
00023 #include "platform.h"
00024 #include "cmsis.h"
00025 #include "pinmap.h"
00026 #include "PeripheralNames.h"
00027 #include "fsl_adc_hal.h"
00028 #include "fsl_clock_manager.h"
00029 #include "PeripheralPins.h"
00030 #include "fsl_device_registers.h"
00031 
00032 #define VERSION_ADC_DIFF "2014_12_05"
00033 
00034 #if FSL_FEATURE_ADC_HAS_DIFF_MODE
00035 
00036 #define MAX_FADC 6000000
00037 #define ADC_DIFF(adc,ch) (((adc)<<1) | (ch)) 
00038 //adc ch -> ADC Diff pin+ ADC<adc>_DP<ch> and pin- ADC<adc>_DM<ch>
00039 
00040 
00041 /** class of AnalogIn_Diff for K64F
00042  * Example:
00043  * @code
00044  * #include "mbed.h"
00045  * #include "AnalogIn_Diff.h"
00046  * Ticker flipperADC;
00047  * bool flag_TX=false;
00048  * void flipADC()
00049  * {
00050  *     flag_TX=true;
00051  * }
00052  * int main()
00053  * {
00054  *   flipperADC.attach(&flipADC, 1.0);
00055  *   AnalogIn_Diff adc_diff(ADC_DIFF(0,1)); // ADC Diff pin+ ADC0_DP1 and pin- ADC0_DM1
00056  *   while (true) {
00057  *       if(flag_TX) {
00058  *           pc.printf("analog= %f \r\n",adc_diff.read()); //-0.5 < analog < 0.5 ; (-0.5 # ADC0_DP1=0.0V ADC0_DM1=3.3V) (0.0 # ADC0_DP1=1.65V ADC0_DM1=1.65V) (0.5 # ADC0_DP1=3.3V ADC0_DM1=0.0V)
00059  *           flag_TX=false;
00060  *       }
00061  *  }
00062  * }
00063  * @endcode
00064  */
00065 
00066 class AnalogIn_Diff
00067 {
00068 
00069 public:
00070     /** Create an AnalogIn_Diff
00071      *
00072      * @param adc_ch is ADC_DIFF(#adc, #ch)
00073      *
00074      */
00075     AnalogIn_Diff(int adc_ch);
00076 
00077     /** Destroy an AnalogIn_Diff
00078      */
00079     ~AnalogIn_Diff();
00080 
00081     /** Read the input voltage, represented as a float range [-0.5 ; 0.5]
00082      *
00083      * @returns A floating-point value representing the current input voltage, measured as a percentage
00084      */
00085     float read();
00086 
00087     /** Read the input voltage, represented as an 16-bit Signed 2's complement
00088      *
00089      * @returns
00090      *   16-bit signed representing the current input voltage, normalised to a 16-bit signed
00091      */
00092     int16_t read_raws16();
00093 
00094 #ifdef MBED_OPERATORS
00095     /** An operator shorthand for read()
00096      *
00097      * The float() operator can be used as a shorthand for read() to simplify common code sequences
00098      *
00099      * Example:
00100      * @code
00101      * float x = volume.read();
00102      * float x = volume;
00103      *
00104      * if(volume.read() > 0.25) { ... }
00105      * if(volume > 0.25) { ... }
00106      * @endcode
00107      */
00108     operator float() {
00109         return read();
00110     }
00111 
00112 #endif //MBED_OPERATORS
00113 
00114 private:
00115     uint8_t chnNum;
00116     uint32_t instance ;
00117     uint32_t adc_addrs[];
00118 };
00119 
00120 #endif //FSL_FEATURE_ADC_HAS_DIFF_MODE
00121 #endif //ANALOGIN_DIFF_H
00122 
00123