BCL 00000022

MP TypeADC
OS TypeMulti-Thread Mbed , etc
Calculation accuracyinteger calculation
Characteristic Conversionlinear conversion
Filter Simple Moving Average ( SMA )
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.00000022

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

// Filter definitons
#define iSMA_num                4U                      // Simple Moving Average Times

// 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]
#define iVout_max               3300                    // Vout Max [mV]
#define iVout_min               0                       // Vout Min [mV]
#define iPhysical_max           100                     // Physical Max [unit]
#define iPhysical_min           0                       // Physical Min [unit]

// Circuit definitions
#define iADC_vdd                3300U                    // MPU Vdd [mV]
#define iK_tc                   ( 1*iInt_const )        // 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 };
         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 = ( (sint32)wk.vi – iX_offset ) * iInt_const;
                 out.phy = mac_rnd( out.phy , iK_gain ) + iY_offset;
                
                 // Physical value Simple Moving Average calculation
                 out.phy = lib_s32_SMA( out.phy , &Phy_SMA );
                
                 // Physical value Max or Min Diagnostics
                 out.sp_dia = lib_s32_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 , 0U };
         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 = (uint16)mac_UpLmt( (uint32)wk.ai * iK_tc / iInt_const , iUint16_Max );
                
                 // Voltage value Max or Min Diagnostics
                 out.cp_dia = lib_u16_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 );
}

static mp2cp_t mp( void )
{
         mp2cp_t out = { iMP_Read , iNormal , 0U };
         uint16 wk;
         uint8 sts;
        
         // Read A/D convension value
         sts = adc_read_u16_wrapper( an , &wk );
        
         // M-CAL judgment
         if( sts != iNg )                // M-CAL normal
         {
                 out.ai = wk;
                 out.mp_dia = iNormal;
                 out.mp_stt = iMP_Read;
         }
         else                            // M-CAL abnormal
         {
                 out.mp_dia = iMPL_NG;
                 out.mp_stt = iError;
         }
        
         return( out );
}


OSS-EC Site