BCL 00000027

MP TypeADC
OS TypeMulti-Thread Mbed , etc
Calculation accuracyinteger calculation
Characteristic ConversionNon-linear conversion(Two-dimensional table method)
Filter Exponential Moving Average ( EMA )
Diagnostics Non

Software Specifications

Caution)

Please note that the return value of the Mbed read_u16 function may be MSB-padded or LSB-packed. The adc_read_u16_wrapper function assumes LSB packing.

File ( Mbed C++)

main.cppapplication source code file
pcmp.cppADC Component source code file
pcmp.hADC Component header file
oss-ec.h OSS-EC header file

Source Code

  • Constants for components   Constants to match the component
  • Constants for MPU        Constants to match the microcontroller of the product
  • Constants for circuits      Constants to match the circuit of the product

// BCL No.00000027

// Interger constant
#define iInt_const              256U                    // Interger constant

// Filter definitons
#define iInt_EsfMax             65535U                  // Exponential Smoothing Factor in interger max value ( Corresponding to 1.0 )
#define iK_esf                  (uint16)( 0.75F*iInt_EsfMax ) // Exponential Smoothing Factor
                                                         // CAUTION: k is in the range of 0 to iInt_EsfMax ( Corresponding : 0 to 1.0 )

// MPU definitions
#define iADC_bit                16U                     // MPU ADC bit
                                                         // CAUTION : When Mbed is selected, 16 bit is fixed
#define iPIN_adc                A0                      // MPU Port Pin (ADC)

// P-CMP ( Sysyem Parts , Circuit , IC ) definitions
// Model type System Parts definitions
#define iData_num               5U                      // Number of characteristic table elements

const sint32 Data_x[iData_num] =                        // X axis for table search : Voltage [mV]
{
         0 , 500 , 1000 , 1500 , 2000                    // X data
};

const sint32 Data_y[iData_num] =                        // Y axis for table search : Physical [unit]
{
         10 , 15 , 30 , 50 , 100                         // Y data
};

// Circuit definitions
#define iADC_vdd                3300U                   // MPU Vdd [mV]
#define iK_tc                   ( 1*iInt_const )        // Circuit Transformation ratio


sint32 Phy_Read( void )
{
         return( pcmp() );
}

static sint32 pcmp( void )
{
         uint16  ai    = mp();           // A/D value read
         uint16  vi    = cp( ai );       // A/D value to Voltage value conversion
         sint32  phy   = sp( vi );       // Voltage value to Physical value
        
         return( phy );
}

static sint32 sp( uint16 vi )
{
         // Voltage value to Physical value conversion
         sint32 wk = lib_s32_Tbl2D( vi , &Tbl );
        
         // Physical value Exponential Moving Averages calculation
         wk = lib_s32_EMA( wk , &Phy_EMA );
        
         return( wk );
}

static uint16 cp( uint16 ai )
{
         // A/D value to Voltage value conversion
         uint16 wk = (uint16)mac_UpLmt( (uint32)ai * iK_tc / iInt_const , iUint16_Max );
        
         return( wk );
}

static uint16 mp( void )
{
         uint16 wk;
        
         // Read A/D convension value
         uint8 sts = adc_read_u16_wrapper( an , &wk );
        
         return( wk );
}

OSS-EC Site