Beispiel #1
0
void Components_Init(void)
{
    /*! DMA_controller Auto initialization start */
    EDMA_DRV_Init(&DMA_controller_State,&DMA_controller_InitConfig0);
    /*! DMA_controller Auto initialization end */


    /*! OLED_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_OLED_SPI, &OLED_SPI_MasterState, &OLED_SPI_MasterConfig, &OLED_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_OLED_SPI, &OLED_SPI_BusConfig, &OLED_SPI_calculatedBaudRate);
    /*! OLED_SPI Auto initialization end */

    /*! FLASH_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_FLASH_SPI, &FLASH_SPI_MasterState, &FLASH_SPI_MasterConfig, &FLASH_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_FLASH_SPI, &FLASH_SPI_BusConfig, &FLASH_SPI_calculatedBaudRate);
    /*! FLASH_SPI Auto initialization end */

    /*! GPIO Auto initialization start */
    GPIO_DRV_Init(NULL,NULL);
    /*! GPIO Auto initialization end */

    /*! KW40_UART Auto initialization start */
    UART_DRV_Init(FSL_KW40_UART,&KW40_UART_State,&KW40_UART_InitConfig0);
    /*! KW40_UART Auto initialization end */
    /*! DEBUG_UART Auto initialization start */
    UART_DRV_Init(FSL_DEBUG_UART,&DEBUG_UART_State,&DEBUG_UART_InitConfig0);
    /*! DEBUG_UART Auto initialization end */
    /*! FS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_FS_I2C, &FS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_FS_I2C, &FS_I2C_MasterConfig);
    /*! FS_I2C Auto initialization end */

    /*! NFS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_NFS_I2C, &NFS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_NFS_I2C, &NFS_I2C_MasterConfig);
    /*! NFS_I2C Auto initialization end */

    /*! PWR_Manager Auto initialization start */
//  POWER_SYS_Init(powerConfigsArr, 2U, NULL , 0U);
    INT_SYS_EnableIRQ(LLWU_IRQn);
    /*! PWR_Manager Auto initialization end */
    /*! CLOCK Auto initialization start */
    RTC_DRV_Init(FSL_CLOCK);
    /*! CLOCK Auto initialization end */

    /*! BATTERY_ADC Auto initialization start */
    ADC16_DRV_Init(FSL_BATTERY_ADC, &BATTERY_ADC_InitConfig);
    ADC16_DRV_ConfigConvChn(FSL_BATTERY_ADC, 0U, &BATTERY_ADC_ChnConfig);
    /*! BATTERY_ADC Auto initialization end */

    /*! sensor_timer Auto initialization start */
    LPTMR_DRV_Init(FSL_SENSOR_TIMER,&sensor_timer_State,&sensor_timer_cfg);
    /*! sensor_timer Auto initialization end */

}
/*FUNCTION*********************************************************************
 *
 * Function Name : ADC16_DRV_PauseConv
 * Description   : Pause current conversion setting by software.
 *
 *END*************************************************************************/
void ADC16_DRV_PauseConv(uint32_t instance, uint32_t chnGroup)
{
    assert(instance < ADC_INSTANCE_COUNT);
    adc16_chn_config_t configStruct;

    configStruct.chnIdx = kAdc16Chn31;
    configStruct.convCompletedIntEnable = false;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    configStruct.diffConvEnable = false;
#endif
    ADC16_DRV_ConfigConvChn(instance, chnGroup, &configStruct);
}
Beispiel #3
0
/*!
 * @brief Initialize the ADCx for HW trigger.
 * @return Error code.
 */
int adc16Init(adc16_converter_config_t *adcUserConfig, adc16_chn_config_t *adcChnConfig, adc16_calibration_param_t *adcCalibraitionParam)
{
    if(!adcUserConfig || !adcChnConfig)
    {
        return LPM_DEMO_RETURN_NULL;
    }

    memset(adcUserConfig, 0, sizeof(adc16_converter_config_t));
    memset(adcChnConfig, 0, sizeof(adc16_chn_config_t));
    memset(adcCalibraitionParam, 0, sizeof(adc16_calibration_param_t));

    adc16CalibrateParams();

    // Auto calibration
    if(adcCalibraitionParam)
    {
        ADC16_DRV_GetAutoCalibrationParam(HWADC_INSTANCE, adcCalibraitionParam);
        ADC16_DRV_SetCalibrationParam(HWADC_INSTANCE, adcCalibraitionParam);
    }

    // Initialization ADC for
    // 16bit resolution, interrupt mode, hw trigger enabled.
    // normal convert speed, VREFH/L as reference,
    // disable continuous convert mode.
    ADC16_DRV_StructInitUserConfigDefault(adcUserConfig);
    adcUserConfig->resolution = kAdc16ResolutionBitOf16;
    adcUserConfig->hwTriggerEnable = true;
    adcUserConfig->continuousConvEnable = false;
    adcUserConfig->clkSrc = kAdc16ClkSrcOfAsynClk;
#if BOARD_ADC_USE_ALT_VREF
    adcUserConfig->refVoltSrc = kAdc16RefVoltSrcOfValt;
#endif
    ADC16_DRV_Init(HWADC_INSTANCE, adcUserConfig);

    // Install Callback function into ISR
    ADC_InstallCallback(HWADC_INSTANCE, CHANNEL_0, adc1IrqHandler);

    adcChnConfig->chnIdx = ADC16_TEMPERATURE_CHN;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    adcChnConfig->diffConvEnable = false;
#endif
    adcChnConfig->convCompletedIntEnable = true;

    // Configure channel0
    ADC16_DRV_ConfigConvChn(HWADC_INSTANCE, CHANNEL_0, adcChnConfig);

    adc16InitPitTriggerSource(HWADC_INSTANCE);

    gConversionCompleteFlag = 0;

    return LPM_DEMO_RETURN_OK;
}
/*!
 * Get the temperature pointer
 * designed for BM version of I2C_RTOS demo
 * from the ISR context
 */
uint8_t* get_temp_pointer(void)
{
    uint32_t adcValue;
    // ADC starts conversion
    ADC16_DRV_ConfigConvChn(HWADC_INSTANCE, 0U, &tempSnseChannelConfig);
    // poll to complete status and read back result
    ADC16_DRV_WaitConvDone(HWADC_INSTANCE, 0U);
    adcValue = ADC16_DRV_GetConvValueRAW(HWADC_INSTANCE, 0U);
    adcValue = ADC16_DRV_ConvRAWData(adcValue, false, tempSnseAdcConfig.resolutionMode);
    // ADC stop conversion
    ADC16_DRV_PauseConv(HWADC_INSTANCE, 0U);
    // convert to temperature
    Temperature = (M1 - (adcValue - VTEMP25_ADC) * M2)/K;
    return (uint8_t*)&Temperature;
}
Beispiel #5
0
/*!
 * @brief Initialize the ADCx for HW trigger.
 *
 * @param instance The ADC instance number
 */
static int32_t init_adc(uint32_t instance)
{
    adc16_converter_config_t adcUserConfig;
    adc16_chn_config_t adcChnConfig;
#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    // Initialization ADC for calibration purposes
    adc16_calibration_param_t adcCalibrationParam;
    adc16_chn_config_t adcCalibrationChnConfig;
    const adc16_hw_average_config_t adcAverageConfig = {
      .hwAverageEnable = true,
      .hwAverageCountMode = kAdc16HwAverageCountOf32
    };
    
    ADC16_DRV_StructInitUserConfigDefault(&adcUserConfig);
#if BOARD_ADC_USE_ALT_VREF
    adcUserConfig.refVoltSrc = kAdc16RefVoltSrcOfValt;
#endif
    ADC16_DRV_Init(instance, &adcUserConfig);
    ADC16_DRV_ConfigHwAverage(instance, &adcAverageConfig);

    adcChnConfig.chnIdx = kAdc16Chn31;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    adcCalibrationChnConfig.diffConvEnable = false;
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
    adcCalibrationChnConfig.convCompletedIntEnable = false;

    // Configure channel0
    ADC16_DRV_ConfigConvChn(instance, 0U, &adcCalibrationChnConfig);

    // Configure channel1, which is used in PDB trigger case
    ADC16_DRV_ConfigConvChn(instance, 1U, &adcCalibrationChnConfig);
    
    // Auto calibration.
    ADC16_DRV_GetAutoCalibrationParam(instance, &adcCalibrationParam);
    ADC16_DRV_SetCalibrationParam(instance, &adcCalibrationParam);
#endif

    // Initialization ADC for
    // 12bit resolution, interrrupt mode, hw trigger enabled.
    // normal convert speed, VREFH/L as reference,
    // disable continuouse convert mode.
    ADC16_DRV_StructInitUserConfigDefault(&adcUserConfig);
    adcUserConfig.hwTriggerEnable = true;
    adcUserConfig.continuousConvEnable = false;
#if BOARD_ADC_USE_ALT_VREF
    adcUserConfig.refVoltSrc = kAdc16RefVoltSrcOfValt;
#endif
    ADC16_DRV_Init(instance, &adcUserConfig);

    // Install Callback function into ISR
    ADC_TEST_InstallCallback(instance, 0U, adc_chn0_isr_callback);
    ADC_TEST_InstallCallback(instance, 1U, adc_chn1_isr_callback);

    adcChnConfig.chnIdx = (adc16_chn_t)ADC_INPUT_CHAN;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    adcChnConfig.diffConvEnable = false;
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
    adcChnConfig.convCompletedIntEnable = true;

    // Configure channel0
    ADC16_DRV_ConfigConvChn(instance, 0U, &adcChnConfig);

    // Configure channel1, which is used in PDB trigger case
    ADC16_DRV_ConfigConvChn(instance, 1U, &adcChnConfig);

    return 0;
}

/*!
 * @brief Reset the sparse matrix
 */
void sparse_reset(void)
{
    memset(gChartHead, 0, sizeof(gChartHead));
    memset(gChartNodes, 0, sizeof(gChartNodes));
    gFreeNode = 0;
}
/*!
 * @brief Parameters calibration: VDD and ADCR_TEMP25
 *
 * This function used BANDGAP as reference voltage to measure vdd and
 * calibrate V_TEMP25 with that vdd value.
 */
void calibrateParams(void)
{

    adc16_chn_config_t adcChnConfig;
    pmc_bandgap_buffer_config_t pmcBandgapConfig = {
        .enable = true,
#if FSL_FEATURE_PMC_HAS_BGEN
        .enableInLowPower = false,
#endif
#if FSL_FEATURE_PMC_HAS_BGBDS
        .drive = kPmcBandgapBufferDriveLow,
#endif
    };
    uint32_t bandgapValue;  // ADC value of BANDGAP
    uint32_t vdd;           // VDD in mV

    // Enable BANDGAP reference voltage
    PMC_HAL_BandgapBufferConfig(PMC_BASE_PTR, &pmcBandgapConfig);

    // Configure the conversion channel
    // differential and interrupt mode disable.
    adcChnConfig.chnIdx     = kAdc16Chn27;    // ADC Bandgap channel
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    adcChnConfig.diffConvEnable = false;
#endif
    adcChnConfig.convCompletedIntEnable  = false;

    ADC16_DRV_ConfigConvChn(ADC_INSTANCE, 0U, &adcChnConfig);

    // Wait for the conversion to be done
    ADC16_DRV_WaitConvDone(ADC_INSTANCE, 0U);

    // Get current ADC BANDGAP value and format it.
    bandgapValue = ADC16_DRV_GetConvValueSigned(ADC_INSTANCE, 0U);
    // Calculates bandgapValue in 16bit resolution
    // from 12bit resolution to calibrate.
#if (FSL_FEATURE_ADC16_MAX_RESOLUTION < 16)
    bandgapValue = bandgapValue << 4U;
#endif
    // ADC stop conversion
    ADC16_DRV_PauseConv(ADC_INSTANCE, 0U);

    // Get VDD value measured in mV
    // VDD = (ADCR_VDD x V_BG) / ADCR_BG
    vdd = ADCR_VDD * V_BG / bandgapValue;
    // Calibrate ADCR_TEMP25
    // ADCR_TEMP25 = ADCR_VDD x V_TEMP25 / VDD
    adcrTemp25 = ADCR_VDD * V_TEMP25 / vdd;
    // Calculate conversion value of 100mV.
    // ADCR_100M = ADCR_VDD x 100 / VDD
    adcr100m = ADCR_VDD * 100/ vdd;

    // Disable BANDGAP reference voltage
    pmcBandgapConfig.enable = false;
    PMC_HAL_BandgapBufferConfig(PMC_BASE_PTR, &pmcBandgapConfig);
}
/*!
 * Get the temperature pointer
 * designed for BM version of I2C_RTOS demo
 * from the ISR context
 */
uint8_t* get_temp_pointer(void)
{
    uint32_t adcValue;
    // ADC starts conversion
    ADC16_DRV_ConfigConvChn(ADC_INSTANCE, 0U, &tempSnseChannelConfig);
    // poll to complete status and read back result
    ADC16_DRV_WaitConvDone(ADC_INSTANCE, 0U);
    // Get ADC converted value
    adcValue = ADC16_DRV_GetConvValueSigned(ADC_INSTANCE, 0U);
    // ADC stop conversion
    ADC16_DRV_PauseConv(ADC_INSTANCE, 0U);
    // Calculates adcValue in 16bit resolution
    // from 12bit resolution in order to convert to temperature.
#if (FSL_FEATURE_ADC16_MAX_RESOLUTION < 16)
    adcValue = adcValue << 4U;
#endif
    // convert to temperature
    // Multiplied by 1000 because M in uM/oC
    // temperature = 25 - (ADCR_T - ADCR_TEMP25) * 100*1000 / ADCR_100M*M
    temperature = (int32_t)(STANDARD_TEMP - ((int32_t)adcValue - (int32_t)adcrTemp25) * 100000 /(int32_t)(adcr100m*M));

    return (uint8_t*)&temperature;
}
Beispiel #7
0
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.5 [05.21]
**     for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
void calibrateParams(void)
{
    adc16_chn_config_t adcChnConfig;
#if FSL_FEATURE_ADC16_HAS_HW_AVERAGE
    adc16_hw_average_config_t userHwAverageConfig;
#endif
    pmc_bandgap_buffer_config_t pmcBandgapConfig = {
        .enable = true,
#if FSL_FEATURE_PMC_HAS_BGEN
        .enableInLowPower = false,
#endif
#if FSL_FEATURE_PMC_HAS_BGBDS
        .drive = kPmcBandgapBufferDriveLow,
#endif
    };

    uint32_t bandgapValue = 0;  // ADC value of BANDGAP
    uint32_t vdd = 0;           // VDD in mV

#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    // Auto calibration
    adc16_calibration_param_t adcCalibraitionParam;
    ADC16_DRV_GetAutoCalibrationParam(ADC16_INSTANCE, &adcCalibraitionParam);
    ADC16_DRV_SetCalibrationParam(ADC16_INSTANCE, &adcCalibraitionParam);
#endif // FSL_FEATURE_ADC16_HAS_CALIBRATION.

    // Enable BANDGAP reference voltage
    PMC_HAL_BandgapBufferConfig(PMC_BASE_PTR, &pmcBandgapConfig);

#if FSL_FEATURE_ADC16_HAS_HW_AVERAGE
    // Use hardware average to increase stability of the measurement.
    userHwAverageConfig.hwAverageEnable = true;
    userHwAverageConfig.hwAverageCountMode = kAdc16HwAverageCountOf32;
    ADC16_DRV_ConfigHwAverage(ADC16_INSTANCE, &userHwAverageConfig);
#endif // FSL_FEATURE_ADC16_HAS_HW_AVERAGE

    // Configure the conversion channel
    // differential and interrupt mode disable.
    adcChnConfig.chnIdx                  = (adc16_chn_t)ADC16_BANDGAP_CHN;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    adcChnConfig.diffConvEnable          = false;
#endif
    adcChnConfig.convCompletedIntEnable  = false;
    ADC16_DRV_ConfigConvChn(ADC16_INSTANCE, ADC16_CHN_GROUP, &adcChnConfig);

    // Wait for the conversion to be done
    ADC16_DRV_WaitConvDone(ADC16_INSTANCE, ADC16_CHN_GROUP);

    // Get current ADC BANDGAP value and format it.
    bandgapValue = ADC16_DRV_GetConvValueSigned(ADC16_INSTANCE, ADC16_CHN_GROUP);
    // Calculates bandgapValue in 16bit resolution
    // from 12bit resolution to calibrate.
#if (FSL_FEATURE_ADC16_MAX_RESOLUTION < 16)
    bandgapValue = bandgapValue << 4;
#endif
    // ADC stop conversion
    ADC16_DRV_PauseConv(ADC16_INSTANCE, ADC16_CHN_GROUP);

    // Get VDD value measured in mV
    // VDD = (ADCR_VDD x V_BG) / ADCR_BG
    vdd = ADCR_VDD * V_BG / bandgapValue;
    // Calibrate ADCR_TEMP25
    // ADCR_TEMP25 = ADCR_VDD x V_TEMP25 / VDD
    adcrTemp25 = ADCR_VDD * V_TEMP25 / vdd;
    // Calculate conversion value of 100mV.
    // ADCR_100M = ADCR_VDD x 100 / VDD
    adcr100m = ADCR_VDD*100/ vdd;

    // Disable BANDGAP reference voltage
    pmcBandgapConfig.enable = false;
    PMC_HAL_BandgapBufferConfig(PMC_BASE_PTR, &pmcBandgapConfig);
}



/*!
 * @brief Gets current temperature of chip.
 *
 * This function gets convertion value, converted temperature and print them to terminal.
 */
void ADC16_Measure(void)
{
    adc16_chn_config_t chnConfig;

    // Configure the conversion channel
    // differential and interrupt mode disable.
    chnConfig.chnIdx     = (adc16_chn_t)ADC16_TEMPERATURE_CHN;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    chnConfig.diffConvEnable = false;
#endif
    chnConfig.convCompletedIntEnable  = false;

    // Software trigger the conversion.
    ADC16_DRV_ConfigConvChn(ADC16_INSTANCE, ADC16_CHN_GROUP, &chnConfig);

    //ADC16_DRV_ConfigConvChn(FSL_ADCONV1, 0U, &adConv1_ChnConfig0);
    // Wait for the conversion to be done.
    ADC16_DRV_WaitConvDone(ADC16_INSTANCE, ADC16_CHN_GROUP);

    // Fetch the conversion value.
    adcValue = ADC16_DRV_GetConvValueSigned(ADC16_INSTANCE, ADC16_CHN_GROUP);

    // Show the current temperature value.
    PRINTF("\r\n ADC converted value: %ld\t", adcValue );
    // Calculates adcValue in 16bit resolution
    // from 12bit resolution in order to convert to temperature.
#if (FSL_FEATURE_ADC16_MAX_RESOLUTION < 16)
    adcValue = adcValue << 4;
#endif
    PRINTF("\r\n Temperature %ld\r\n", get_current_temperature(adcValue));
    // Pause the conversion.
    ADC16_DRV_PauseConv(ADC16_INSTANCE, ADC16_CHN_GROUP);

}
Beispiel #8
0
void DutVSense::updateADCVal(void)	{
	ADC16_DRV_ConfigConvChn(dut_adc_IDX, SELFADC_CHNGROUP, &adcChConfig);
	rawADCVal = ADC16_DRV_GetConvValueRAW(dut_adc_IDX, SELFADC_CHNGROUP);
	floatADCVal.asFloat = (float)rawADCVal*scalingFactor;
}
Beispiel #9
0
/*!
 * @brief calibrate param for adc.
 */
void adc16CalibrateParams(void)
{
#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    adc16_calibration_param_t adcCalibraitionParam;
#endif
    adc16_converter_config_t adcUserConfig;
#if FSL_FEATURE_ADC16_HAS_HW_AVERAGE
    adc16_hw_average_config_t hwAverageConfig;
#endif
    adc16_chn_config_t adcChnConfig;
    pmc_bandgap_buffer_config_t pmcBandgapConfig = {
        .enable = true,
#if FSL_FEATURE_PMC_HAS_BGEN
        .enableInLowPower = false,
#endif
#if FSL_FEATURE_PMC_HAS_BGBDS
        .drive = kPmcBandgapBufferDriveLow,
#endif
    };
    uint32_t bandgapValue = 0;  /*! ADC value of BANDGAP */
    uint32_t vdd = 0;           /*! VDD in mV */

    // Enable BANDGAP reference voltage
    PMC_HAL_BandgapBufferConfig(PMC_BASE_PTR, &pmcBandgapConfig);

    // Initialization ADC for
    // 16bit resolution, interrupt mode, hw trigger disabled.
    // normal convert speed, VREFH/L as reference,
    // disable continuous convert mode.
    ADC16_DRV_StructInitUserConfigDefault(&adcUserConfig);
    adcUserConfig.resolution = kAdc16ResolutionBitOf16;
    adcUserConfig.continuousConvEnable = false;
    adcUserConfig.clkSrc = kAdc16ClkSrcOfAsynClk;
#if BOARD_ADC_USE_ALT_VREF
    adcUserConfig.refVoltSrc = kAdc16RefVoltSrcOfValt;
#endif
    ADC16_DRV_Init(HWADC_INSTANCE, &adcUserConfig);

#if FSL_FEATURE_ADC16_HAS_HW_AVERAGE
    hwAverageConfig.hwAverageEnable = true;
    hwAverageConfig.hwAverageCountMode = kAdc16HwAverageCountOf32;
    ADC16_DRV_ConfigHwAverage(HWADC_INSTANCE, &hwAverageConfig);
#endif // FSL_FEATURE_ADC16_HAS_HW_AVERAGE

#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    // Auto calibration
    ADC16_DRV_GetAutoCalibrationParam(HWADC_INSTANCE, &adcCalibraitionParam);
    ADC16_DRV_SetCalibrationParam(HWADC_INSTANCE, &adcCalibraitionParam);
#endif

    adcChnConfig.chnIdx = ADC16_BANDGAP_CHN;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    adcChnConfig.diffConvEnable = false;
#endif
    adcChnConfig.convCompletedIntEnable = false;
    ADC16_DRV_ConfigConvChn(HWADC_INSTANCE, CHANNEL_0, &adcChnConfig);

    // Wait for the conversion to be done
    ADC16_DRV_WaitConvDone(HWADC_INSTANCE, CHANNEL_0);

    // Get current ADC BANDGAP value
    bandgapValue = ADC16_DRV_GetConvValueSigned(HWADC_INSTANCE, CHANNEL_0);

    // ADC stop conversion
    ADC16_DRV_PauseConv(HWADC_INSTANCE, CHANNEL_0);

    // Get VDD value measured in mV: VDD = (ADCR_VDD x V_BG) / ADCR_BG
    vdd = ADCR_VDD * V_BG / bandgapValue;
    // Calibrate ADCR_TEMP25: ADCR_TEMP25 = ADCR_VDD x V_TEMP25 / VDD
    sAdcrTemp25 = ADCR_VDD * V_TEMP25 / vdd;
    // ADCR_100M = ADCR_VDD x M x 100 / VDD
    sAdcr100m = (ADCR_VDD * M) / (vdd * 10);

#if FSL_FEATURE_ADC16_HAS_HW_AVERAGE
    hwAverageConfig.hwAverageEnable = false;
    ADC16_DRV_ConfigHwAverage(HWADC_INSTANCE, &hwAverageConfig);
#endif // FSL_FEATURE_ADC16_HAS_HW_AVERAGE

    // Disable BANDGAP reference voltage
    pmcBandgapConfig.enable = false;
    PMC_HAL_BandgapBufferConfig(PMC_BASE_PTR, &pmcBandgapConfig);
}

/*!
 * @brief Getting current temperature value.
 * @return Current temperature.
 */
int32_t adc16GetCurrentTempValue(void)
{
    int32_t currentTemperature = 0;

    currentTemperature = (int32_t)(STANDARD_TEMP - ((int32_t)sAdcValue - (int32_t)sAdcrTemp25) * 100 / (int32_t)sAdcr100m);
    return currentTemperature;
}
Beispiel #10
0
/*!
 * @brief Initialize the ADCx for HW trigger.
 *
 * @param instance The ADC instance number
 */
int32_t init_adc(uint32_t instance)
{
#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    adc16_calibration_param_t adcCalibraitionParam;
#endif
    adc16_converter_config_t adcUserConfig;
    adc16_chn_config_t adcChnConfig;
    adc16_hw_average_config_t adchwaverageConfig;

    //ADC16_DRV_StructInitUserConfigDefault(&adcUserConfig);    
    /* Special configuration for highest accuracy. */
    adcUserConfig.lowPowerEnable = false;
    adcUserConfig.clkDividerMode = kAdc16ClkDividerOf1;
    adcUserConfig.longSampleTimeEnable = false;
    //yanglliang
    adcUserConfig.resolution = kAdc16ResolutionBitOfSingleEndAs16;
    //adcUserConfig.resolution = kAdc16ResolutionBitOfSingleEndAs12;
    adcUserConfig.clkSrc = kAdc16ClkSrcOfBusClk;   //kAdc16ClkSrcOfAsynClk;
    adcUserConfig.asyncClkEnable = true;
    adcUserConfig.highSpeedEnable = true;
    adcUserConfig.longSampleCycleMode = kAdc16LongSampleCycleOf24;
    adcUserConfig.hwTriggerEnable = false;
    adcUserConfig.refVoltSrc = kAdc16RefVoltSrcOfVref;
    adcUserConfig.continuousConvEnable = false;
    
#if (  defined(FRDM_KL43Z)   /* CPU_MKL43Z256VLH4 */ \
    || defined(TWR_KL43Z48M) /* CPU_MKL43Z256VLH4 */ \
    || defined(FRDM_KL27Z)   /* CPU_MKL27Z64VLH4  */ \
    )
    adcUserConfig.refVoltSrc = kAdc16RefVoltSrcOfValt;
#endif
    ADC16_DRV_Init(instance, &adcUserConfig);

#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    // Auto calibraion.
    ADC16_DRV_GetAutoCalibrationParam(instance, &adcCalibraitionParam);
    ADC16_DRV_SetCalibrationParam(instance, &adcCalibraitionParam);
#endif

    // Initialization ADC for
    // 12bit resolution, interrrupt mode, hw trigger enabled.
    // normal convert speed, VREFH/L as reference,
    // disable continuouse convert mode.
    //ADC16_DRV_StructInitUserConfigDefault(&adcUserConfig);
    adcUserConfig.hwTriggerEnable = true;
    adcUserConfig.continuousConvEnable = false;
#if (  defined(FRDM_KL43Z)   /* CPU_MKL43Z256VLH4 */ \
    || defined(TWR_KL43Z48M) /* CPU_MKL43Z256VLH4 */ \
    || defined(FRDM_KL27Z)   /* CPU_MKL27Z64VLH4  */ \
    )
    adcUserConfig.refVoltSrc = kAdc16RefVoltSrcOfValt;
#endif
    
    
    ADC16_DRV_Init(instance, &adcUserConfig);

    // Install Callback function into ISR
    ADC_TEST_InstallCallback(instance, 0U, adc_chn0_isr_callback);
    //ADC_TEST_InstallCallback(instance, 1U, adc_chn1_isr_callback);

    adcChnConfig.chnIdx = (adc16_chn_t)ADC_AI1;
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    adcChnConfig.diffConvEnable = false;
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
    adcChnConfig.convCompletedIntEnable = true;
    
    ADC0_CFG2 |= ADC_CFG2_MUXSEL_MASK;

    // Configure channel0
    ADC16_DRV_ConfigConvChn(instance, 0U, &adcChnConfig);
    
    adchwaverageConfig.hwAverageEnable=false;
    //yangliang for hardware average
    adchwaverageConfig.hwAverageCountMode=kAdc16HwAverageCountOf4;
    //adchwaverageConfig.hwAverageCountMode=kAdc16HwAverageCountOf16;
    ADC16_DRV_ConfigHwAverage(0, & adchwaverageConfig);                  //Set Hardware Average numbers

    // Configure channel1, which is used in PDB trigger case
    //ADC16_DRV_ConfigConvChn(instance, 1U, &adcChnConfig);

    return 0;
}