MiZ702學習筆記9——XADC採集片上數據PS版

此次藉助zynq的內嵌的XADC來採集zynq內部的一些參數:app

•VCCINT:內部PL核心電壓spa

•VCCAUX:輔助PL電壓3d

•VREFP:XADC正參考電壓調試

•VREFN:XADC負參考電壓code

•VCCBram:PL BRAM電壓orm

•VCCPInt:PS內部核心電壓blog

•VCCPAux:PS輔助電壓ip

•VCCDdr:DDR RAM的工做電壓開發

此次這個程序的開發流程和以前講的別無二致,但願你們可以徹底的熟悉這個流程~~get

仍是和往常同樣,新建一個Block Design,而且向其中添加zynq核以及XADC IP。

wps85C2.tmp

對XADC核進行設置

wps8611.tmp

依次執行這兩項:wps8612.tmp

執行以後以下圖所示:

wps874B.tmp

依次執行Generate Output Products 和 Create HDL Wrapper

wps874C.tmp

最後編譯,直到生成bit文件。

導出硬件,並經過vivado打開SDK。

wps875C.tmp

進入SDK,如何新建工程,就再也不次囉嗦了,請參考以前的章節。新建main.c以後爲其添加代碼以下~~(這段代碼是參考國外的一個大神Adam寫的,向大神致敬~~)

#include <stdio.h>
//#include "platform.h"
#include "xadcps.h"
#include "xil_types.h"
#define XPAR_AXI_XADC_0_DEVICE_ID 0


//void print(char *str);

static XAdcPs XADCMonInst;

int main()
{

  XAdcPs_Config *ConfigPtr;
  XAdcPs *XADCInstPtr = &XADCMonInst;

  //status of initialisation
  int Status_ADC;

  //temperature readings
  u32 TempRawData;
  float TempData;

  //Vcc Int readings
  u32 VccIntRawData;
  float VccIntData;

  //Vcc Aux readings
  u32 VccAuxRawData;
  float VccAuxData;

  //Vbram readings
  u32 VBramRawData;
  float VBramData;

  //VccPInt readings
  u32 VccPIntRawData;
  float VccPIntData;

  //VccPAux readings
  u32 VccPAuxRawData;
  float VccPAuxData;

  //Vddr readings
  u32 VDDRRawData;
  float VDDRData;

 // init_platform();

    //printf("Adam Edition MicroZed Using Vivado How To Printf \n\r");
    printf("新年快樂~~!!!2015-12-31 \n\r");
    //XADC initilization

     ConfigPtr = XAdcPs_LookupConfig(XPAR_AXI_XADC_0_DEVICE_ID);
       if (ConfigPtr == NULL) {
           return XST_FAILURE;
         }

       Status_ADC = XAdcPs_CfgInitialize(XADCInstPtr,ConfigPtr,ConfigPtr->BaseAddress);
       if(XST_SUCCESS != Status_ADC){
           print("ADC INIT FAILED\n\r");
           return XST_FAILURE;
        }

       //self test
       Status_ADC = XAdcPs_SelfTest(XADCInstPtr);
     if (Status_ADC != XST_SUCCESS) {
       return XST_FAILURE;
     }

        //stop sequencer
        XAdcPs_SetSequencerMode(XADCInstPtr,XADCPS_SEQ_MODE_SINGCHAN);

        //disable alarms
        XAdcPs_SetAlarmEnables(XADCInstPtr, 0x0);

        //configure sequencer to just sample internal on chip parameters
        XAdcPs_SetSeqInputMode(XADCInstPtr, XADCPS_SEQ_MODE_SAFE);


        //configure the channel enables we want to monitor

        XAdcPs_SetSeqChEnables(XADCInstPtr,XADCPS_CH_TEMP|XADCPS_CH_VCCINT|XADCPS_CH_VCCAUX|XADCPS_CH_VBRAM|XADCPS_CH_VCCPINT| XADCPS_CH_VCCPAUX|XADCPS_CH_VCCPDRO);

        while(1)
        {
            TempRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_TEMP);
            TempData = XAdcPs_RawToTemperature(TempRawData);
            printf("Raw Temp %lu Real Temp %f \n\r", TempRawData, TempData);

            VccIntRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCINT);
            VccIntData = XAdcPs_RawToVoltage(VccIntRawData);
            printf("Raw VccInt %lu Real VccInt %f \n\r", VccIntRawData,VccIntData);

            VccAuxRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCAUX);
            VccAuxData = XAdcPs_RawToVoltage(VccAuxRawData);
            printf("Raw VccAux %lu Real VccAux %f \n\r", VccAuxRawData,VccAuxData);


            VBramRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VBRAM);
            VBramData = XAdcPs_RawToVoltage(VBramRawData);
            printf("Raw VccBram %lu Real VccBram %f \n\r", VBramRawData, VBramData);

            VccPIntRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCPINT);
            VccPIntData = XAdcPs_RawToVoltage(VccPIntRawData);
            printf("Raw VccPInt %lu Real VccPInt %f \n\r", VccPIntRawData, VccPIntData);

            VccPAuxRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCPAUX);
            VccPAuxData = XAdcPs_RawToVoltage(VccPAuxRawData);
            printf("Raw VccPAux %lu Real VccPAux %f \n\r", VccPAuxRawData, VccPAuxData);

            VDDRRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCPDRO);
            VDDRData = XAdcPs_RawToVoltage(VDDRRawData);
            printf("Raw VccDDR %lu Real VccDDR %f \n\r", VDDRRawData, VDDRData);
         }

        return 0;
}

 

1.  Use the "XAdcPs_SelfTest()"   這個自檢就不用說了

2.  Use "XAdcPs_SetSequencerMode()"  這個是設置採樣模式。

3.  Use "XAdcPs_SetAlarmEnables()"   這個是設置採樣值報警的,直接關閉,不須要報警

4.  Use "XAdcPs_SetSeqInputMode()"   這個是設置輸入模式的

5.  Use "XAdcPs_SetSeqChEnables()    這個是使能採樣通道的

編譯以後,記得先下載bit文件~~連上串口,而後就能夠執行程序了:

wps875D.tmp

因而乎,經過打開串口調試助手,便能看見打印出以下信息~~

wps876E.tmp

新年新氣象~~從這篇文章開始,vivado升級到2015.2版本~~若是你須要下載,網盤地址以下~~

vivado 2015.2 http://yunpan.cn/c3I7aVCGVneEh  訪問密碼 7d64

相關文章
相關標籤/搜索