1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| #include<iostream> #include<xparameters.h> #include<xadcps.h> #include<xstatus.h> #include<sleep.h>
using namespace std;
#define XADC_DEVICE_ID XPAR_XADCPS_0_DEVICE_ID
static int XAdcPolledPrintfExample(u16 XAdcDeviceId); static int XAdcFractionToInt(float FloatNum);
static XAdcPs XAdcInst;
int main(void) {
while(1) { cout<<"======================================"<<endl; XAdcPolledPrintfExample(XADC_DEVICE_ID); cout<<"************************************************************"<<endl; usleep(5000000); }
return 0; }
int XAdcPolledPrintfExample(u16 XAdcDeviceId) { XAdcPs_Config *ConfigPtr; u32 TempRawData; u32 VccPintRawData; u32 VccPauxRawData; u32 VccPdroRawData;
u32 VccintRawData; u32 VccauxRawData; u32 VccdroRawData;
float TempData; float VccPintData; float VccPauxData; float MaxData; float MinData; float VccintData; float VccauxData; float vccBRAM;
XAdcPs *XAdcInstPtr = &XAdcInst;
ConfigPtr = XAdcPs_LookupConfig(XAdcDeviceId); XAdcPs_CfgInitialize(XAdcInstPtr, ConfigPtr, ConfigPtr->BaseAddress);
XAdcPs_SetSequencerMode(XAdcInstPtr, XADCPS_SEQ_MODE_SAFE);
TempRawData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_TEMP); TempData = XAdcPs_RawToTemperature(TempRawData); printf("芯片当前温度为: %0d.%03d ℃.\r\n", (int)(TempData), XAdcFractionToInt(TempData));
TempRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_TEMP); MaxData = XAdcPs_RawToTemperature(TempRawData); printf("芯片最高温度为: %0d.%03d ℃. \r\n", (int)(MaxData), XAdcFractionToInt(MaxData));
TempRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_TEMP); MinData = XAdcPs_RawToTemperature(TempRawData & 0xFFF0); printf("芯片最低温度为: %0d.%03d ℃. \r\n", (int)(MinData), XAdcFractionToInt(MinData));
VccPintRawData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPINT); VccPintData = XAdcPs_RawToVoltage(VccPintRawData); printf("\r\n当前VCCPINT为: %0d.%03d V. \r\n", (int)(VccPintData), XAdcFractionToInt(VccPintData));
VccPintRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_VCCPINT); MaxData = XAdcPs_RawToVoltage(VccPintRawData); printf("最大VCCPINT为: %0d.%03d V. \r\n", (int)(MaxData), XAdcFractionToInt(MaxData));
VccPintRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_VCCPINT); MinData = XAdcPs_RawToVoltage(VccPintRawData); printf("最小VCCPINT为: %0d.%03d V. \r\n", (int)(MinData), XAdcFractionToInt(MinData));
VccPauxRawData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPAUX); VccPauxData = XAdcPs_RawToVoltage(VccPauxRawData); printf("\r\n当前VCCPAUX为: %0d.%03d V. \r\n", (int)(VccPauxData), XAdcFractionToInt(VccPauxData));
VccPauxRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_VCCPAUX); MaxData = XAdcPs_RawToVoltage(VccPauxRawData); printf("最大VCCPAUX为: %0d.%03d V. \r\n", (int)(MaxData), XAdcFractionToInt(MaxData));
VccPauxRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_VCCPAUX); MinData = XAdcPs_RawToVoltage(VccPauxRawData); printf("最小VCCPAUX为: %0d.%03d V. \r\n", (int)(MinData), XAdcFractionToInt(MinData));
VccPdroRawData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCPDRO); VccPintData = XAdcPs_RawToVoltage(VccPdroRawData); printf("\r\n当前VCCPDDRO为: %0d.%03d V. \r\n", (int)(VccPintData), XAdcFractionToInt(VccPintData));
VccPdroRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_VCCPDRO); MaxData = XAdcPs_RawToVoltage(VccPdroRawData); printf("最大VCCPDDRO为: %0d.%03d V. \r\n", (int)(MaxData), XAdcFractionToInt(MaxData));
VccPdroRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_VCCPDRO); MinData = XAdcPs_RawToVoltage(VccPdroRawData); printf("最小VCCPDDRO为: %0d.%03d V. \r\n", (int)(MinData), XAdcFractionToInt(MinData));
VccintRawData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCINT); VccintData = XAdcPs_RawToVoltage(VccintRawData); printf("\r\n当前VCCINT为: %0d.%03d V. \r\n", (int)(VccintData), XAdcFractionToInt(VccintData));
VccintRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_VCCINT); MaxData = XAdcPs_RawToVoltage(VccintRawData); printf("最大VCCINT为: %0d.%03d V. \r\n", (int)(MaxData), XAdcFractionToInt(MaxData));
VccintRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_VCCINT); MinData = XAdcPs_RawToVoltage(VccintRawData); printf("最小VCCINT为: %0d.%03d V. \r\n", (int)(MinData), XAdcFractionToInt(MinData));
VccauxRawData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VCCAUX); VccauxData = XAdcPs_RawToVoltage(VccauxRawData); printf("\r\n当前VCCAUX为: %0d.%03d V. \r\n", (int)(VccauxData), XAdcFractionToInt(VccauxData));
VccauxRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_VCCAUX); MaxData = XAdcPs_RawToVoltage(VccauxRawData); printf("最大VCCAUX为: %0d.%03d V. \r\n", (int)(MaxData), XAdcFractionToInt(MaxData));
VccauxRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_VCCAUX); MinData = XAdcPs_RawToVoltage(VccauxRawData); printf("最小VCCAUX为: %0d.%03d V. \r\n", (int)(MinData), XAdcFractionToInt(MinData));
VccdroRawData = XAdcPs_GetAdcData(XAdcInstPtr, XADCPS_CH_VBRAM); vccBRAM = XAdcPs_RawToVoltage(VccdroRawData); printf("\r\n当前VCCBRAM为: %0d.%03d V. \r\n", (int)(vccBRAM), XAdcFractionToInt(vccBRAM));
VccdroRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MAX_VBRAM); MaxData = XAdcPs_RawToVoltage(VccdroRawData); printf("最大VCCBRAM为: %0d.%03d V. \r\n", (int)(MaxData), XAdcFractionToInt(MaxData));
VccdroRawData = XAdcPs_GetMinMaxMeasurement(XAdcInstPtr, XADCPS_MIN_VBRAM); MinData = XAdcPs_RawToVoltage(VccdroRawData); printf("最小VCCBRAM为: %0d.%03d V. \r\n", (int)(MinData), XAdcFractionToInt(MinData));
return 0; }
int XAdcFractionToInt(float FloatNum) { float Temp;
Temp = FloatNum; if (FloatNum < 0) { Temp = -(FloatNum); }
return( ((int)((Temp -(float)((int)Temp)) * (1000.0f)))); }
|