BCL 00000019

MP TypeADC
OS TypeMulti-Thread Mbed , etc
Calculation accuracyinteger calculation
Characteristic Conversionlinear conversion
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.00000019

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

// Filter definitions
#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 iX_offset               0                       // X offset [mV]
#define iY_offset               0                       // Y offset [unit]
#define iK_gain                 ( 1*iInt_const )        // Gain [mV/unit]

// 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 )
{
         sint32 wk = 0;
        
         // Voltage value to Physical value conversion
         wk = ( (sint32)vi – iX_offset ) * iInt_const;
         wk = mac_rnd( wk , iK_gain ) + iY_offset;
        
         // 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