XADC内嵌在PS端,允许CPU或其他主机连接XADC,而不用使用PL端。XADC最大采样率为1MSPS,精度为12bits,内置电压和温度传感器,可监测芯片的电压及温度信息。如图所示电压传感器可监测芯片的VCCINT,VCCAUX,VCCBRAM等,VP_0和VN_0为一对专用的ADC模拟输入口。VAUXP[*]和VAUXN[*]也是ADC输入口,但是不用作ADC输入口时,可用作普通IO使用。
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("rnEntering the XAdc PolledExample. rn");
/*
* 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("rnThe Current Temperature is .d Centigrades.rn",
(int)(TempData), XAdcFractionToInt(TempData));
TempRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_TEMP);
MaxData= XAdcPs_RawToTemperature(TempRawData);
printf("The Maximum Temperature is .d Centigrades. rn",
(int)(MaxData), XAdcFractionToInt(MaxData));
TempRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_TEMP);
MinData= XAdcPs_RawToTemperature(TempRawData & 0xFFF0);
printf("The Minimum Temperature is .d Centigrades. rn",
(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("rnThe Current VCCPINT is .d Volts. rn",
(int)(VccPintData),XAdcFractionToInt(VccPintData));
VccPintRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,
XADCPS_MAX_VCCPINT);
MaxData= XAdcPs_RawToVoltage(VccPintRawData);
printf("The Maximum VCCPINT is .dVolts. rn",
(int)(MaxData), XAdcFractionToInt(MaxData));
VccPintRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,
XADCPS_MIN_VCCPINT);
MinData= XAdcPs_RawToVoltage(VccPintRawData);
printf("The Minimum VCCPINT is .dVolts. rn",
(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("rnThe Current VCCPAUX is .d Volts. rn",
(int)(VccPauxData),XAdcFractionToInt(VccPauxData));
VccPauxRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,
XADCPS_MAX_VCCPAUX);
MaxData= XAdcPs_RawToVoltage(VccPauxRawData);
printf("The Maximum VCCPAUX is .dVolts. rn",
(int)(MaxData), XAdcFractionToInt(MaxData));
VccPauxRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,
XADCPS_MIN_VCCPAUX);
MinData= XAdcPs_RawToVoltage(VccPauxRawData);
printf("The Minimum VCCPAUX is .dVolts. rnrn",
(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("rnThe Current VCCPDDRO is .d Volts. rn",
(int)(VccPintData), XAdcFractionToInt(VccPintData));
VccPdroRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,
XADCPS_MAX_VCCPDRO);
MaxData= XAdcPs_RawToVoltage(VccPdroRawData);
printf("The Maximum VCCPDDRO is .dVolts. rn",
(int)(MaxData), XAdcFractionToInt(MaxData));
VccPdroRawData= XAdcPs_GetMinMaxMeasurement(XAdcInstPtr,
XADCPS_MIN_VCCPDRO);
MinData= XAdcPs_RawToVoltage(VccPdroRawData);
printf("The Minimum VCCPDDRO is .dVolts. rn",
(int)(MinData), XAdcFractionToInt(MinData));
printf("Exiting the XAdc Polled Example.rn");
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))));
}
(1)ZYNQ中PS端MIO操作
(2)ZYNQ中PS端MIO中断
(3)ZYNQ中PS端UART通信