This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Temperature of ADC

I want an example of the ADC collecting the internal temperature, but I don't want to use interrupt reading, I want polling.

  • Hello RU,

    Please provide more information.  Is this for the ADC internal to a processor, if so, which one?  

    Or is it for a stand-alone ADC, again, if so, which one?

    Thank you,

    ~Leonard  

  • It will be easier to help you if you specify which microcontroller or board that you are using. If you ever consider something  simpler, you can check this Graphical Temperature & Humidity Control Unit:

    www.pcbway.com/.../Graphical_Temperature_Humidity_Control_Unit_Using_a_Raspberry_Pi_Pico_7d5db042.html

  • volatile bool gCheckADC;
    volatile float gTemperatureDegC;
    _iq15 qVTrim;
    void Tem_initial(void)
    {

    qVTrim = _IQ15div(_IQ15mpy((_IQ15(DL_SYSCTL_getTempCalibrationConstant()) -
    _IQ15(0.5)), _IQ15(3.45)), ((uint32_t)(1) << 27));

    }


    uint8_t Get_IC_Temp(void)
    {
    uint32_t adcResult;
    _iq15 qVSample, qTsample;

    NVIC_DisableIRQ(ADC12_0_INST_INT_IRQN);
    DL_ADC12_stopConversion(ADC12_0_INST);
    adcResult = DL_ADC12_getMemResult(ADC12_0_INST, ADC12_0_ADCMEM_0); //808
    qVSample = _IQ15div(_IQ15mpy((adcResult << 15) -
    _IQ15(0.5),_IQ15(ADC_VREF_VOLTAGE)), _IQ15(ADC_BIT_RESOLUTION));
    qTsample = _IQ15mpy(_IQ15(TEMP_TS_COEF_mV_C), (qVSample - qVTrim)) +
    (TEMP_TS_TRIM_C << 15); // 890469
    gTemperatureDegC = _IQ15toF(qTsample);
    return ((uint8_t)(gTemperatureDegC));
    }

    void Start_Temperature(void)
    {
    DL_ADC12_startConversion(ADC12_0_INST);
    NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);
    }

    volatile uint8_t tem;
    void ADC0_IRQHandler(void)
    {


    switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST)) {
    case DL_ADC12_IIDX_MEM0_RESULT_LOADED:

    tem= Get_IC_Temp();
    DataBuffer[Realtime_Tem]=tem+100;
    break;
    default:
    break;
    }
    }

    • The above is obtained by interrupt, whether there is a polling way

  • Hi RU,

    Refers to the code example of the SDK, the interrupt is used for judge whether ADC conversion is finished:

    If so, just use the interrupt flag judgement in the polling task and you can let it work as expected:

    DL_ADC12_getRawInterruptStatus(ADC12_0_INST, ADC12_CPU_INT_IMASK_MEMRESIFG0_MASK) -> If there is a new conversion data in MEM0, then this function will return a value of "1", or return "0".

    B.R.

    Sal

    • I don't want to use interrupt 

    • I put the break point here(after while) and it can't pass

  • Hi,

    You make something wrong with your code.

    Below is what I use based on the code example and I test it works well:

    B.R.

    Sal

  • OK, I have done. Thanks!

    By the way, Apply the following two methods to division which is faster?

    1)

    DL_MathACL_startDivOperation(MATHACL, &gDivConfig, a, b);
    DL_MathACL_waitForOperation(MATHACL);
     DL_MathACL_getResultOne(MATHACL);

    2)Qmath

    a=_IQ15toF(_IQ15div(10,5));

  • Hi,

    As for MSPM0G device, IQmath opetation wii auto call the MATHACL if you enable it. So these two method is basically the same. The (1) method is little faster, because IQ math operation will have some data format handle operation.

    By the way:

    1)MATHACL operation suggest to use IQ format data.

    2)_IQ15div(10,5) suggest to follow the IQ input format:_IQ15div(_IQ15(10),_IQ15(5)).

    B.R.

    Sal