BSL 00000038

MP TypeADC
OS TypeMulti-Task AUTOSAR , etc
Calculation accuracyfloating-point calculation
Characteristic Conversionlinear conversion
Filter Simple Moving Average ( SMA )
Diagnostics SP Max/Min , CP Max/Min , MP Adc_ReadGroup 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

main.c application source code file
pcmp.cADC 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.00000038

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

// MPU definitions
#define iADC_bit                12U                     // MPU ADC bit 8/10/12
#define iADC_group              1U                      // ADC group
#define iADC_GrChNum            8U                      // Number channel in ADC group
#define iPIN_pos                7U                      // Sensor position in ADC group

// 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               5.0F                    // 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                5.0F                    // MPU Vdd [V]
#define iK_tc                   1.0F                    // Circuit Transformation ratio


void spw( void )
{
         PHY = sp( VI );
}

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 );
}

void cpw( void )
{
         VI_ECU = cp( AI );
}

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 );
}

void mpw( void )
{
         AI = mp();
}

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