BCL 00000010

MP TypeADC
OS TypeMulti-Thread Mbed , etc
Calculation accuracyfloating-point calculation
Characteristic ConversionNon-linear conversion(Two-dimensional table method)
Filter Simple Moving Average ( SMA )
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.00000010

// Filter definitions
#define iSMA_num                4U                      // Simple moving average number

// 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 float32 Data_x[iData_num] =                       // X axis for table search : Voltage [V]
{
         0.0F , 0.5F , 1.0F , 1.5F , 2.0F                // X data
};

const float32 Data_y[iData_num] =                       // Y axis for table search : Physical [unit]
{
         10.0F , 15.0F , 30.0F , 50.0F , 100.0F          // Y data
};
// Circuit definitions
#define iADC_vdd                3.3F                    // MPU Vdd [V]
#define iK_tc                   1.0F                    // Circuit Transformation ratio


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

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

static float32 sp( float32 vi )
{
         // Voltage value to Physical value conversion
         float32 wk = lib_f32_Tbl2D( vi , &Tbl );
        
         // Physical value Simple Moving Average calculation
         wk = lib_f32_SMA( wk , &Phy_SMA );
        
         return( wk );
}

static float32 cp( uint16 ai )
{
         // A/D value to Voltage value conversion
         float32 wk = (float32)ai * iADC_vdd / ( 1<<iADC_bit ) * iK_tc;
        
         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