8 years, 7 months ago.

AnalogIn Diff on the FRDMK64F ?

Hello

how to use SIM_HAL_EnableAdcClock () function?

how to use BW_SIM_SCGC3_ADC1() macro ?

Thank you.

my code

AnalogIn_Diff::AnalogIn_Diff(int a2d_number) : ch(a2d_number)
{
    SIM_HAL_EnableAdcClock(SIM_BASE,ch);

    BW_ADC_SC1n_DIFF(ch, 0, 1);     //  Differential Mode
    BW_ADC_CFG1_ADICLK(ch, 0);      //  Bus Clock
    BW_ADC_CFG1_MODE(ch, 3);        //  16Bit differential mode
    BW_ADC_CFG1_ADLSMP(ch, 0);      //  Short Sample Window
    BW_ADC_CFG1_ADIV(ch, 3);        //  Clock / 8
    BW_ADC_CFG1_ADLPC(ch, 0);       //  Normal Power Mode
    //modif
    // BW_ADC_SC2_REFSEL(ch, 1);//internal sources depending on the MCU
}

targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/MK64F12/fsl_sim_hal_K64F12.c

line 442
/*FUNCTION**********************************************************************
 *
 * Function Name : SIM_HAL_EnableAdcClock
 * Description   : Enable the clock for ADC module
 * This function enables the clock for ADC moudle
 *
 *END**************************************************************************/
void SIM_HAL_EnableAdcClock(uint32_t baseAddr, uint32_t instance)
{
    switch (instance)
    {
    case 0:
        BW_SIM_SCGC6_ADC0(baseAddr, 1);
        break;
    case 1:
        BW_SIM_SCGC3_ADC1(baseAddr, 1);
        break;
    default:
        break;
    }
}

targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/device/device/MK64F12/MK64F12_sim.h

line 2738
/*!
 * @name Constants and macros for entire SIM_SCGC6 register
 */
/*@{*/
#define HW_SIM_SCGC6_ADDR(x)     ((x) + 0x103CU)
...
line 3100
#define BP_SIM_SCGC6_ADC0    (27U)         /*!< Bit position for SIM_SCGC6_ADC0. */
...
line 3110
/*! @brief Set the ADC0 field to a new value. */
#define BW_SIM_SCGC6_ADC0(x, v) (BITBAND_ACCESS32(HW_SIM_SCGC6_ADDR(x), BP_SIM_SCGC6_ADC0) = (v))
Be the first to answer this question.