XADC内嵌在PS端的使用

描述

XADC

  XADC内嵌在PS端,允许CPU或其他主机连接XADC,而不用使用PL端。XADC最大采样率为1MSPS,精度为12bits,内置电压和温度传感器,可监测芯片的电压及温度信息。如图所示电压传感器可监测芯片的VCCINT,VCCAUX,VCCBRAM等,VP_0和VN_0为一对专用的ADC模拟输入口。VAUXP[*]和VAUXN[*]也是ADC输入口,但是不用作ADC输入口时,可用作普通IO使用。

XADC                  

int XAdcPolledPrintfExample(u16 XAdcDeviceId)

{

    int Status;

    XAdcPs_Config *ConfigPtr;

    u32 TempRawData;

    u32 VccPintRawData;

    u32 VccPauxRawData;

    u32 VccPdroRawData;

    float TempData;

    float VccPintData;

    float VccPauxData;

    float MaxData;

    float MinData;

    XAdcPs *XAdcInstPtr = &XAdcInst;

 

    printf(" Entering the XAdc PolledExample. ");

 

    /*

     * Initialize the XAdc driver.

     */

    ConfigPtr= XAdcPs_LookupConfig(XAdcDeviceId);

    if (ConfigPtr == NULL) {

        return XST_FAILURE;

    }

    XAdcPs_CfgInitialize(XAdcInstPtr,ConfigPtr,

                ConfigPtr->BaseAddress);

 

    /*

     * Self Test the XADC/ADC device

     */

    Status= XAdcPs_SelfTest(XAdcInstPtr);

    if (Status != XST_SUCCESS) {

        return XST_FAILURE;

    }

 

    /*

     * Disable the Channel Sequencer beforeconfiguring the Sequence

     * registers.

     */

    XAdcPs_SetSequencerMode(XAdcInstPtr,XADCPS_SEQ_MODE_SAFE);

    /*

     * Read the on-chip Temperature Data(Current/Maximum/Minimum)

     * from the ADC data registers.

     */

    TempRawData= XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_TEMP);

    TempData= XAdcPs_RawToTemperature(TempRawData);

    printf(" The Current Temperature is%0d.%03d Centigrades. ",

                (int)(TempData), XAdcFractionToInt(TempData));

 

 

    TempRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_TEMP);

    MaxData= XAdcPs_RawToTemperature(TempRawData);

    printf("The Maximum Temperature is%0d.%03d Centigrades. ",

                (int)(MaxData), XAdcFractionToInt(MaxData));

 

    TempRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_TEMP);

    MinData= XAdcPs_RawToTemperature(TempRawData & 0xFFF0);

    printf("The Minimum Temperature is%0d.%03d Centigrades. ",

                (int)(MinData), XAdcFractionToInt(MinData));

 

    /*

     * Read the VccPint Votage Data(Current/Maximum/Minimum) from the

     * ADC data registers.

     */

    VccPintRawData= XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPINT);

    VccPintData= XAdcPs_RawToVoltage(VccPintRawData);

    printf(" The Current VCCPINT is%0d.%03d Volts. ",

            (int)(VccPintData),XAdcFractionToInt(VccPintData));

 

    VccPintRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,

                            XADCPS_MAX_VCCPINT);

    MaxData= XAdcPs_RawToVoltage(VccPintRawData);

    printf("The Maximum VCCPINT is %0d.%03dVolts. ",

            (int)(MaxData), XAdcFractionToInt(MaxData));

 

    VccPintRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,

                            XADCPS_MIN_VCCPINT);

    MinData= XAdcPs_RawToVoltage(VccPintRawData);

    printf("The Minimum VCCPINT is %0d.%03dVolts. ",

            (int)(MinData), XAdcFractionToInt(MinData));

 

    /*

     * Read the VccPaux Votage Data(Current/Maximum/Minimum) from the

     * ADC data registers.

     */

    VccPauxRawData= XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPAUX);

    VccPauxData= XAdcPs_RawToVoltage(VccPauxRawData);

    printf(" The Current VCCPAUX is%0d.%03d Volts. ",

            (int)(VccPauxData),XAdcFractionToInt(VccPauxData));

 

    VccPauxRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,

                                XADCPS_MAX_VCCPAUX);

    MaxData= XAdcPs_RawToVoltage(VccPauxRawData);

    printf("The Maximum VCCPAUX is %0d.%03dVolts. ",

                (int)(MaxData), XAdcFractionToInt(MaxData));

 

 

    VccPauxRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,

                                XADCPS_MIN_VCCPAUX);

    MinData= XAdcPs_RawToVoltage(VccPauxRawData);

    printf("The Minimum VCCPAUX is %0d.%03dVolts. ",

                (int)(MinData), XAdcFractionToInt(MinData));

 

 

    /*

     * Read the VccPdro Votage Data(Current/Maximum/Minimum) from the

     * ADC data registers.

     */

    VccPdroRawData= XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPDRO);

    VccPintData= XAdcPs_RawToVoltage(VccPdroRawData);

    printf(" The Current VCCPDDRO is%0d.%03d Volts. ",

            (int)(VccPintData), XAdcFractionToInt(VccPintData));

 

    VccPdroRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,

                            XADCPS_MAX_VCCPDRO);

    MaxData= XAdcPs_RawToVoltage(VccPdroRawData);

    printf("The Maximum VCCPDDRO is %0d.%03dVolts. ",

            (int)(MaxData), XAdcFractionToInt(MaxData));

 

    VccPdroRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,

                            XADCPS_MIN_VCCPDRO);

    MinData= XAdcPs_RawToVoltage(VccPdroRawData);

    printf("The Minimum VCCPDDRO is %0d.%03dVolts. ",

            (int)(MinData), XAdcFractionToInt(MinData));

 

 

    printf("Exiting the XAdc Polled Example. ");

 

    return XST_SUCCESS;

}

 

 

/****************************************************************************/

/**

*

* This function converts the fractionpart of the given floating point number

* (after the decimal point)to aninteger.

*

* @param    FloatNum is the floating point number.

*

* @return   Integer number to a precision of 3 digits.

*

* @note

* This function is used in the printingof floating point data to a STDIO device

* using the xil_printf function. Thexil_printf is a very small foot-print

* printf function and does notsupport the printing of floating point numbers.

*

*****************************************************************************/

int XAdcFractionToInt(float FloatNum)

{

    float Temp;

 

    Temp= FloatNum;

    if (FloatNum < 0) {

        Temp= -(FloatNum);

    }

 

    return( ((int)((Temp -(float)((int)Temp)) * (1000.0f))));

}

XADC

 

原文标题:Zynq中PS端XADC

文章出处:【微信公众号:FPGA之家】欢迎添加关注!文章转载请注明出处。

审核编辑:汤梓红
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分