Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: trms_helloworld AnalogIn_Diff_helloworld
Fork of AnalogIn_Diff by
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 #include "mbed.h" 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 #include "fsl_interrupt_manager.h" 00032 00033 #define VERSION_ADC_DIFF "2016_01_07" 00034 #define MAX_ADC 2 00035 #if FSL_FEATURE_ADC_HAS_DIFF_MODE 00036 00037 #define MAX_FADC 6000000 00038 #define ADC_DIFF(adc,ch) (((adc)<<1) | (ch)) 00039 //adc ch -> ADC Diff pin+ ADC<adc>_DP<ch> and pin- ADC<adc>_DM<ch> 00040 00041 00042 /** class of AnalogIn_Diff for K64F 00043 * Example: 00044 * @code 00045 * #include "mbed.h" 00046 * #include "AnalogIn_Diff.h" 00047 * Ticker flipperADC; 00048 * bool flag_TX=false; 00049 * void flipADC() 00050 * { 00051 * flag_TX=true; 00052 * } 00053 * int main() 00054 * { 00055 * flipperADC.attach(&flipADC, 1.0); 00056 * AnalogIn_Diff adc_diff(ADC_DIFF(0,1)); // ADC Diff pin+ ADC0_DP1 and pin- ADC0_DM1 00057 * while (true) { 00058 * if(flag_TX) { 00059 * 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) 00060 * flag_TX=false; 00061 * } 00062 * } 00063 * } 00064 * @endcode 00065 */ 00066 00067 class AnalogIn_Diff 00068 { 00069 00070 public: 00071 /** Create an AnalogIn_Diff 00072 * 00073 * @param adc_ch is ADC_DIFF(#adc, #ch) 00074 * 00075 */ 00076 AnalogIn_Diff(int adc_ch); 00077 00078 00079 /** Destroy an AnalogIn_Diff 00080 */ 00081 ~AnalogIn_Diff(); 00082 00083 /** Read the input voltage, represented as a float range [-0.5 ; 0.5] 00084 * 00085 * @returns A floating-point value representing the current input voltage, measured as a percentage 00086 */ 00087 float read(); 00088 00089 /** Read the input voltage, represented as an 16-bit Signed 2's complement 00090 * 00091 * @returns 00092 * 16-bit signed representing the current input voltage, normalised to a 16-bit signed 00093 */ 00094 int16_t read_raws16(); 00095 00096 #ifdef MBED_OPERATORS 00097 /** An operator shorthand for read() 00098 * 00099 * The float() operator can be used as a shorthand for read() to simplify common code sequences 00100 * 00101 * Example: 00102 * @code 00103 * float x = volume.read(); 00104 * float x = volume; 00105 * 00106 * if(volume.read() > 0.25) { ... } 00107 * if(volume > 0.25) { ... } 00108 * @endcode 00109 */ 00110 operator float() { 00111 return read(); 00112 } 00113 00114 #endif //MBED_OPERATORS 00115 00116 private: 00117 uint8_t chnNum; 00118 uint32_t instance ; 00119 uint32_t adc_addrs[MAX_ADC]; 00120 }; 00121 00122 #endif //FSL_FEATURE_ADC_HAS_DIFF_MODE 00123 #endif //ANALOGIN_DIFF_H 00124 00125
Generated on Wed Jul 13 2022 17:40:15 by
1.7.2

ADC DIFF K64F