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.
ana.cpp
00001 #include "mbed.h" 00002 #include "ana.h" 00003 #include "filter.h" 00004 00005 00006 //--------------------------------------- 00007 // Hardware recources 00008 //--------------------------------------- 00009 AnalogIn ana1(p15); 00010 AnalogIn ana2(p16); 00011 AnalogIn ana3(p17); 00012 Ticker ana_sw_timer; 00013 00014 00015 //--------------------------------------- 00016 // Prototypes 00017 //--------------------------------------- 00018 static void ANA_periodical( void ); 00019 00020 00021 00022 //--------------------------------------- 00023 // Internal variables 00024 //--------------------------------------- 00025 static sFLT_LP1Order16BitHandler filterHandlerAna1; 00026 static sFLT_LP1Order16BitHandler filterHandlerAna2; 00027 static sFLT_LP1Order16BitHandler filterHandlerAna3; 00028 static unsigned short ANA_rawSamples[CNT_eANA_Channels]; 00029 static unsigned short ANA_filteredSamples[CNT_eANA_Channels]; 00030 00031 00032 //--------------------------------------- 00033 // External variables 00034 //--------------------------------------- 00035 00036 00037 00038 //--------------------------------------- 00039 // Global Functions 00040 //--------------------------------------- 00041 void ANA_init( void ) 00042 { 00043 int i; 00044 00045 for( i = 0; i < CNT_eANA_Channels; i++ ) 00046 { 00047 ANA_rawSamples[i] = 0; 00048 ANA_filteredSamples[i] = 0; 00049 } 00050 00051 filterHandlerAna1.filterShift = ANA_LP_FILTER_SHIFT_ANA1; 00052 filterHandlerAna2.filterShift = ANA_LP_FILTER_SHIFT_ANA2; 00053 filterHandlerAna3.filterShift = ANA_LP_FILTER_SHIFT_ANA3; 00054 00055 FLT_LP_1Order_16Bit_Init( &filterHandlerAna1 ); 00056 FLT_LP_1Order_16Bit_Init( &filterHandlerAna2 ); 00057 FLT_LP_1Order_16Bit_Init( &filterHandlerAna3 ); 00058 00059 ana_sw_timer.attach_us(&ANA_periodical, ANA_SW_TIMER_PERIOD ); 00060 } 00061 00062 00063 unsigned short ANA_getRaw(int channel) 00064 { 00065 00066 if( (channel < 0) || (channel >= CNT_eANA_Channels) ) 00067 { 00068 return 0; 00069 } 00070 00071 return ANA_rawSamples[channel]; 00072 } 00073 00074 00075 unsigned short ANA_getFiltered( int channel ) 00076 { 00077 if( (channel < 0) || (channel >= CNT_eANA_Channels) ) 00078 { 00079 return 0; 00080 } 00081 00082 return ANA_filteredSamples[channel]; 00083 } 00084 00085 00086 float ANA_scale(float offset, float gain, unsigned short input) 00087 { 00088 return (float)input * gain - offset; 00089 } 00090 00091 00092 00093 //--------------------------------------- 00094 // Internal Functions 00095 //--------------------------------------- 00096 00097 static void ANA_periodical( void ) 00098 { 00099 ANA_rawSamples[ANA_CH1] = ana1.read_u16(); 00100 ANA_rawSamples[ANA_CH2] = ana2.read_u16(); 00101 ANA_rawSamples[ANA_CH3] = ana3.read_u16(); 00102 00103 ANA_filteredSamples[ANA_CH1] = FLT_LP_1Order_16Bit( &filterHandlerAna1, ANA_rawSamples[ANA_CH1] ); 00104 ANA_filteredSamples[ANA_CH2] = FLT_LP_1Order_16Bit( &filterHandlerAna2, ANA_rawSamples[ANA_CH2] ); 00105 ANA_filteredSamples[ANA_CH3] = FLT_LP_1Order_16Bit( &filterHandlerAna3, ANA_rawSamples[ANA_CH3] ); 00106 }
Generated on Sat Jul 16 2022 03:23:51 by
