9.0难度系数★☆☆☆☆☆☆
9.1实验概述
这次借助zynq的内嵌的XADC来采集zynq内部的一些参数:
•VCCINT:内部PL核心电压
•VCCAUX:辅助PL电压
•VREFP:XADC正参考电压
•VREFN:XADC负参考电压
•VCCBram:PL BRAM电压
•VCCPInt:PS内部核心电压
•VCCPAux:PS辅助电压
•VCCDdr:DDR RAM的工作电压
9.2 新建一个VIVADO工程
Step1:新建一个名为为Miz702_sys的工程
Step2:选择RTL Project 勾选Do not specify source at this time
Step3:由于Miz702兼容zedboard 因此选择zedboard开发包
Step4:单击Finish
Step5:新建一个Block Design,并且向其中添加zynq核以及XADC IP。
Step6:新建一个Block Design,并且向其中添加zynq核以及XADC IP。
Step7:对XADC核进行设置
Step8:依次执行这两项
Step9:执行之后如下图所示
Step10:依次执行Generate Output Products 和 Create HDL Wrapper
9.3 产生bit文件
此时可以,开始生成bit文件了(这个过程会弹出保存对话框单击保存,然后弹出Implementation对话框单击OK,重新编译一次):
9.4 导出硬件和bit文件
编译成功之后,依然是导出硬件:
9.5 加载到SDK
9.5 .1编写代码
进入SDK,如何新建工程,就不再次啰嗦了,请参考之前的章节。新建main.c之后为其添加代码如下。
//#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 "); printf("新年快乐~~!!!2015-12-31 "); //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 "); 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 ", TempRawData, TempData); VccIntRawDat= XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCINT); VccIntData = XAdcPs_RawToVoltage(VccIntRawData); printf("Raw VccInt %lu Real VccInt %f ", VccIntRawData,VccIntData); VccAuxRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCAUX); VccAuxData = XAdcPs_RawToVoltage(VccAuxRawData); printf("Raw VccAux %lu Real VccAux %f ", VccAuxRawData,VccAuxData); VBramRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VBRAM); VBramData = XAdcPs_RawToVoltage(VBramRawData); printf("Raw VccBram %lu Real VccBram %f ", VBramRawData, VBramData); VccPIntRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCPINT); VccPIntData = XAdcPs_RawToVoltage(VccPIntRawData); printf("Raw VccPInt %lu Real VccPInt %f ", VccPIntRawData, VccPIntData); VccPAuxRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCPAUX); VccPAuxData = XAdcPs_RawToVoltage(VccPAuxRawData); printf("Raw VccPAux %lu Real VccPAux %f ", VccPAuxRawData, VccPAuxData); VDDRRawData = XAdcPs_GetAdcData(XADCInstPtr, XADCPS_CH_VCCPDRO); VDDRData = XAdcPs_RawToVoltage(VDDRRawData); printf("Raw VccDDR %lu Real VccDDR %f ", VDDRRawData, VDDRData); } return 0; } |
9.5 .2函数介绍
1. Use the "XAdcPs_SelfTest()" 这个自检就不用说了
2. Use "XAdcPs_SetSequencerMode()"这个是设置采样模式。
3. Use "XAdcPs_SetAlarmEnables()"这个是设置采样值报警的,直接关闭,不需要报警
4. Use "XAdcPs_SetSeqInputMode()" 这个是设置输入模式的
5. Use "XAdcPs_SetSeqChEnables() 这个是使能采样通道的
9.5 .3测试结果
编译之后,记得先下载bit文件~~连上串口,然后就可以执行程序了:
于是乎,通过打开串口调试助手,便能看见打印出如下信息~~
9.6 本章小结
本章讲解了如果采集片上电压以及温度的方法,这个实验在实际工程运用中可以通过测试自生的电压和稳定判断系统是否可以正常工作,是否要做出一些报警之类的行动。