BCL 00000007

MP TypeADC
OS TypeMulti-Thread Mbed , etc
Calculation accuracyfloating-point calculation
Characteristic Conversionlinear conversion
Filter Exponential Moving Average ( EMA )
Diagnostics SP Max/Min , CP Max/Min , MP AnalogIn fault

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.00000006

// 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 iX_offset               0.0F                    // X offset [V]
#define iY_offset               0.0F                    // Y offset [unit]
#define iK_gain                 1.0F                    // Gain [V/unit]
#define iVout_max               3.3F                    // Vout Max [V]
#define iVout_min               0.0F                    // Vout Min [V]
#define iPhysical_max           100.0F                  // Physical Max [unit]
#define iPhysical_min           0.0F                    // Physical Min [unit]

// Circuit definitions
#define iADC_vdd                3.3F                    // MPU Vdd [V]
#define iK_tc                   1.0F                    // Circuit Transformation ratio


sp2ap_t Phy_Read( uint16 cmd )
{
         return( pcmp( cmd ) );
}

static sp2ap_t pcmp( uint16 cmd )
{
         mp2cp_t ai    = mpw( cmd );     // A/D value read
         cp2sp_t vi    = cp( ai );       // A/D value to Voltage value conversion
         sp2ap_t phy   = sp( vi );       // Voltage value to Physical value conversion
        
         return( phy );
}

static sp2ap_t sp( cp2sp_t in )
{
         sp2ap_t out = { iMP_Read , iNormal ,iNormal , iNormal , 0.0F };
         cp2sp_t wk;
        
         // Input buffering
         wk = in;
        
         if( ( wk.cp_stt == iMP_Read ) &&
             ( wk.cp_dia == iNormal )  &&
             ( wk.mp_dia == iNormal ) )
         {
                 // Voltage value to Physical value conversion
                 out.phy = ( wk.vi – iX_offset ) / iK_gain + iY_offset;
                
                 // Physical value Simple Moving Average calculation
                 out.phy = lib_f32_SMA( out.phy , &Phy_SMA );
                
                 // Physical value Max or Min Diagnostics
                 out.sp_dia = lib_f32_MaxMin( &out.phy , iPhysical_max , iPhysical_min );
         }
         else
         {
                 // Nothing to do
         }
        
         out.sp_stt = wk.cp_stt;
         out.cp_dia = wk.cp_dia;
         out.mp_dia = wk.mp_dia;
        
         return( out );
}

static cp2sp_t cp( mp2cp_t in )
{
         cp2sp_t out = { iMP_Read , iNormal , iNormal , 0.0F };
         mp2cp_t wk;
        
         // Input buffering
         wk = in;
        
         if( ( wk.mp_stt == iMP_Read ) &&
             ( wk.mp_dia == iNormal ) )
         {
                 // A/D value to Voltage value conversion
                 out.vi = (float32)wk.ai * iADC_vdd / ( 1<<iADC_bit ) * iK_tc;
                
                 // Voltage value Max or Min Diagnostics
                 out.cp_dia = lib_f32_MaxMin( &out.vi , iVout_max , iVout_min );
         }
         else
         {
                 // Nothing to do
         }
        
         out.cp_stt = wk.mp_stt;
         out.mp_dia = wk.mp_dia;
        
         return( out );
}

static mp2cp_t mpw( uint16 cmd )
{
         mp2cp_t out = { iMP_Read , iNormal , 0U };
        
         if( cmd == iMP_Read )
         {
                 out = mp();
         }
         else
         {
                 // Non Command Error
                 out.mp_dia = iMPL_NG;
                 out.mp_stt = iError;
         }

        return( out );
}


OSS-EC Site