這次藉助zynq的內嵌的XADC來採集zynq內部的一些參數:•VCCINT:內部PL核心電壓•VCCAUX:輔助PL電壓•VREFP:XADC正參考電壓•VREFN:XADC負參考電壓•VCCBram:PL BRAM電壓•VCCPInt:PS內部核心電壓•VCCPAux:PS輔助電壓•VCCDdr...
這次藉助zynq的內嵌的XADC來採集zynq內部的一些參數:
•VCCINT:內部PL核心電壓
•VCCAUX:輔助PL電壓
•VREFP:XADC正參考電壓
•VREFN:XADC負參考電壓
•VCCBram:PL BRAM電壓
•VCCPInt:PS內部核心電壓
•VCCPAux:PS輔助電壓
•VCCDdr:DDR RAM的工作電壓
這次這個程式的開發流程和之前講的別無二致,希望大家能夠完全的熟悉這個流程~~
還是和往常一樣,新建一個Block Design,並且向其中添加zynq核以及XADC IP。
對XADC核進行設置
執行之後如下圖所示:
依次執行Generate Output Products 和 Create HDL Wrapper
最後編譯,直到生成bit文件。
導出硬體,並通過vivado打開SDK。
進入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文件~~連上串口,然後就可以執行程式了:
於是乎,通過打開串口調試助手,便能看見列印出如下信息~~
新年新氣象~~從這篇文章開始,vivado升級到2015.2版本~~如果你需要下載,網盤地址如下~~
vivado 2015.2 http://yunpan.cn/c3I7aVCGVneEh 訪問密碼 7d64