这次借助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()
{
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 ;
}
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