[X]关闭
0

(基础篇)S05-CH04-XADC测试

摘要: 软件版本:VIVADO2017.4操作系统:WIN10硬件平台:ARTIX-7 系列开发板米联客(MSXBO)论坛www.osrc.cn答疑解惑专栏开通,欢迎大家给我提供!!!4.1 概述使用Artix7内嵌的XADC来采集芯片内部的一些参数:•VCCINT: ...

软件版本:VIVADO2017.4

操作系统:WIN10

硬件平台: ARTIX-7 系列开发板

米联客(MSXBO)论坛www.osrc.cn答疑解惑专栏开通,欢迎大家给我提供!!!

4.1 概述

使用Artix7内嵌的XADC来采集芯片内部的一些参数:

•VCCINT:内部核心电压

•VCCAUX:辅助电压

•TempData:芯片内部温度

4.2 搭建硬件系统

Step1:创建一个新的vivado工程,命令为System.

Step2:将第一章生成的tcl文件复制到当前文件目录中来,并在tcl控制台中输入如下指令(注意tcl文件路径根据自身情况进行调整):

Step5:双击MIG IP图标,一直单击Next,直至跳转到FPGA Option,然后在下图圈出部分禁止XADC访问DDR选项(这一步至关重要,不然会报错!),之后根据提示完成配置的修改即可。

Step6:添加Constant IP,设置如下。将Constant IP的dout与MIG ip的 device_temp_i连接。


Step6: 选中top.bd,右单击然后选择Generate Output Products。

Step7:在弹出来的窗口中,如下图所示,然后单击OK。

Step8:选中top.bd,右单击然后选择Create HDL Wrapper,在弹出来的窗口中直接点击OK。


4.3 软件设计

Step1:单击File-New-Application Project开始创建一个SDK工程。

Step2:在新弹出来的窗口中,输入工程名字XADC_Test (注意不能有非法字符)。

Step3:单击Next,然后在左侧选择Empty Application(空白工程),最后选择Finish。

Step4:展开XADC_Test,然后选中src,右单击选择New-Source file,然后命名为main.c。

Step5:双击main.c,将以下程序拷贝进去:

#include "xsysmon.h"

#include "xparameters.h"

#include "xstatus.h"

#include "stdio.h"

#include "sleep.h"

/************************** Constant Definitions ****************************/


/*

 * The following constants map to the XPAR parameters created in the

 * xparameters.h file. They are defined here such that a user can easily

 * change all the needed parameters in one place.

 */

#define SYSMON_DEVICE_ID XPAR_SYSMON_0_DEVICE_ID



/**************************** Type Definitions ******************************/



/***************** Macros (Inline Functions) Definitions ********************/


#define printf xil_printf /* Small foot-print printf function */


/************************** Function Prototypes *****************************/


static int SysMonPolledPrintfExample(u16 SysMonDeviceId);

static int SysMonFractionToInt(float FloatNum);


/************************** Variable Definitions ****************************/


static XSysMon SysMonInst;      /* System Monitor driver instance */


/****************************************************************************/

/**

*

* Main function that invokes the polled example in this file.

*

* @param None.

*

* @return

* - XST_SUCCESS if the example has completed successfully.

* - XST_FAILURE if the example has failed.

*

* @note None.

*

*****************************************************************************/

int main(void)

{


int Status;


/*

 * Run the SysMonitor polled example, specify the Device ID that is

 * generated in xparameters.h.

 */

while(1){

Status = SysMonPolledPrintfExample(SYSMON_DEVICE_ID);

if (Status != XST_SUCCESS) {

return XST_FAILURE;

}

usleep(5000);

}


return XST_SUCCESS;

}



/****************************************************************************/

/**

*

* This function runs a test on the System Monitor/ADC device using the

* driver APIs.

* This function does the following tasks:

* - Initiate the System Monitor device driver instance

* - Run self-test on the device

* - Setup the sequence registers to continuously monitor on-chip

* temperature, VCCINT and VCCAUX

* - Setup configuration registers to start the sequence

* - Read the latest on-chip temperature, VCCINT and VCCAUX

*

* @param SysMonDeviceId is the XPAR_<SYSMON_ADC_instance>_DEVICE_ID value

* from xparameters.h.

*

* @return

* - XST_SUCCESS if the example has completed successfully.

* - XST_FAILURE if the example has failed.

*

* @note    None

*

****************************************************************************/

int SysMonPolledPrintfExample(u16 SysMonDeviceId)

{

int Status;

XSysMon_Config *ConfigPtr;

u32 TempRawData;

u32 VccAuxRawData;

u32 VccIntRawData;

float TempData;

float VccAuxData;

float VccIntData;

float MaxData;

float MinData;

XSysMon *SysMonInstPtr = &SysMonInst;



/*

 * Initialize the SysMon driver.

 */

ConfigPtr = XSysMon_LookupConfig(SysMonDeviceId);

if (ConfigPtr == NULL) {

return XST_FAILURE;

}

XSysMon_CfgInitialize(SysMonInstPtr, ConfigPtr,

ConfigPtr->BaseAddress);


/*

 * Self Test the System Monitor/ADC device

 */

Status = XSysMon_SelfTest(SysMonInstPtr);

if (Status != XST_SUCCESS) {

return XST_FAILURE;

}


/*

 * Disable the Channel Sequencer before configuring the Sequence

 * registers.

 */

XSysMon_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_SAFE);



/*

 * Disable all the alarms in the Configuration Register 1.

 */

XSysMon_SetAlarmEnables(SysMonInstPtr, 0x0);



/*

 * Setup the Averaging to be done for the channels in the

 * Configuration 0 register as 16 samples:

 */

XSysMon_SetAvg(SysMonInstPtr, XSM_AVG_16_SAMPLES);


/*

 * Setup the Sequence register for 1st Auxiliary channel

 * Setting is:

 * - Add acquisition time by 6 ADCCLK cycles.

 * - Bipolar Mode

 *

 * Setup the Sequence register for 16th Auxiliary channel

 * Setting is:

 * - Add acquisition time by 6 ADCCLK cycles.

 * - Unipolar Mode

 */

Status = XSysMon_SetSeqInputMode(SysMonInstPtr, XSM_SEQ_CH_AUX00);

if (Status != XST_SUCCESS) {

return XST_FAILURE;

}


Status = XSysMon_SetSeqAcqTime(SysMonInstPtr, XSM_SEQ_CH_AUX15 |

XSM_SEQ_CH_AUX00);

if (Status != XST_SUCCESS) {

return XST_FAILURE;

}



/*

 * Enable the averaging on the following channels in the Sequencer

 * registers:

 * - On-chip Temperature, VCCINT/VCCAUX  supply sensors

 * - 1st/16th Auxiliary Channels

  * - Calibration Channel

 */

Status =  XSysMon_SetSeqAvgEnables(SysMonInstPtr, XSM_SEQ_CH_TEMP |

XSM_SEQ_CH_VCCINT |

XSM_SEQ_CH_VCCAUX |

XSM_SEQ_CH_AUX00 |

XSM_SEQ_CH_AUX15 |

XSM_SEQ_CH_CALIB);

if (Status != XST_SUCCESS) {

return XST_FAILURE;

}


/*

 * Enable the following channels in the Sequencer registers:

 * - On-chip Temperature, VCCINT/VCCAUX supply sensors

 * - 1st/16th Auxiliary Channel

 * - Calibration Channel

 */

Status =  XSysMon_SetSeqChEnables(SysMonInstPtr, XSM_SEQ_CH_TEMP |

XSM_SEQ_CH_VCCINT |

XSM_SEQ_CH_VCCAUX |

XSM_SEQ_CH_AUX00 |

XSM_SEQ_CH_AUX15 |

XSM_SEQ_CH_CALIB);

if (Status != XST_SUCCESS) {

return XST_FAILURE;

}



/*

 * Set the ADCCLK frequency equal to 1/32 of System clock for the System

 * Monitor/ADC in the Configuration Register 2.

 */

XSysMon_SetAdcClkDivisor(SysMonInstPtr, 32);



/*

 * Set the Calibration enables.

 */

XSysMon_SetCalibEnables(SysMonInstPtr,

XSM_CFR1_CAL_PS_GAIN_OFFSET_MASK |

XSM_CFR1_CAL_ADC_GAIN_OFFSET_MASK);


/*

 * Enable the Channel Sequencer in continuous sequencer cycling mode.

 */

XSysMon_SetSequencerMode(SysMonInstPtr, XSM_SEQ_MODE_CONTINPASS);


/*

 * Wait till the End of Sequence occurs

 */

XSysMon_GetStatus(SysMonInstPtr); /* Clear the old status */

while ((XSysMon_GetStatus(SysMonInstPtr) & XSM_SR_EOS_MASK) !=

XSM_SR_EOS_MASK);


/*

 * Read the on-chip Temperature Data (Current/Maximum/Minimum)

 * from the ADC data registers.

 */

TempRawData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_TEMP);

TempData = XSysMon_RawToTemperature(TempRawData);

printf("\r\nThe Current Temperature is %0d.%03d Centigrades.\r\n",

(int)(TempData), SysMonFractionToInt(TempData));



TempRawData = XSysMon_GetMinMaxMeasurement(SysMonInstPtr, XSM_MAX_TEMP);

MaxData = XSysMon_RawToTemperature(TempRawData);

printf("The Maximum Temperature is %0d.%03d Centigrades. \r\n",

(int)(MaxData), SysMonFractionToInt(MaxData));


TempRawData = XSysMon_GetMinMaxMeasurement(SysMonInstPtr, XSM_MIN_TEMP);

MinData = XSysMon_RawToTemperature(TempRawData);

printf("The Minimum Temperature is %0d.%03d Centigrades. \r\n",

(int)(MinData), SysMonFractionToInt(MinData));


/*

 * Read the VccInt Votage Data (Current/Maximum/Minimum) from the

 * ADC data registers.

 */

VccIntRawData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_VCCINT);

VccIntData = XSysMon_RawToVoltage(VccIntRawData);

printf("\r\nThe Current VCCINT is %0d.%03d Volts. \r\n",

(int)(VccIntData), SysMonFractionToInt(VccIntData));


VccIntRawData = XSysMon_GetMinMaxMeasurement(SysMonInstPtr,

XSM_MAX_VCCINT);

MaxData = XSysMon_RawToVoltage(VccIntRawData);

printf("The Maximum VCCINT is %0d.%03d Volts. \r\n",

(int)(MaxData), SysMonFractionToInt(MaxData));


VccIntRawData = XSysMon_GetMinMaxMeasurement(SysMonInstPtr,

XSM_MIN_VCCINT);

MinData = XSysMon_RawToVoltage(VccIntRawData);

printf("The Minimum VCCINT is %0d.%03d Volts. \r\n",

(int)(MinData), SysMonFractionToInt(MinData));


/*

 * Read the VccAux Votage Data (Current/Maximum/Minimum) from the

 * ADC data registers.

 */

VccAuxRawData = XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_VCCAUX);

VccAuxData = XSysMon_RawToVoltage(VccAuxRawData);

printf("\r\nThe Current VCCAUX is %0d.%03d Volts. \r\n",

(int)(VccAuxData), SysMonFractionToInt(VccAuxData));


VccAuxRawData = XSysMon_GetMinMaxMeasurement(SysMonInstPtr,

XSM_MAX_VCCAUX);

MaxData = XSysMon_RawToVoltage(VccAuxRawData);

printf("The Maximum VCCAUX is %0d.%03d Volts. \r\n",

(int)(MaxData), SysMonFractionToInt(MaxData));



VccAuxRawData = XSysMon_GetMinMaxMeasurement(SysMonInstPtr,

XSM_MIN_VCCAUX);

MinData = XSysMon_RawToVoltage(VccAuxRawData);

printf("The Minimum VCCAUX is %0d.%03d Volts. \r\n\r\n",

(int)(MinData), SysMonFractionToInt(MinData));


return XST_SUCCESS;

}



/****************************************************************************/

/*

*

* This function converts the fraction part of the given floating point number

* (after the decimal point)to an integer.

*

* @param FloatNum is the floating point number.

*

* @return Integer number to a precision of 3 digits.

*

* @note

* This function is used in the printing of floating point data to a STDIO device

* using the xil_printf function. The xil_printf is a very small foot-print

* printf function and does not support the printing of floating point numbers.

*

*****************************************************************************/

int SysMonFractionToInt(float FloatNum)

{

float Temp;


Temp = FloatNum;

if (FloatNum < 0) {

Temp = -(FloatNum);

}


return( ((int)((Temp -(float)((int)Temp)) * (1000.0f))));

}

Step6:选中SDK工程文件,右单击选择Debug as-Debug configuration。

Step7:在弹出来的新窗口中,双击下图圈出部分,然后勾选箭头所示参数

Step8:单击Apply,然后单击Debug(进行这一步之前,先给开发板上电)。

Step9:在下图所示区域找到SDK Terminal(这是软件自带的串口调试软件,记住如何使用,下次会直接跳过具体操作),然后单击加号图标

Step10:单击加号图标之后,再新弹出来的窗口中设置好对应的端口号和波特率,然后单击OK。


4.4 程序分析 

       本章的程序根据官方例程修改得来,在此不对其进行详细的讲解,只需要学会如何使用即可,这里介绍一下各个函数的功能:

函数名

功能

XSysMon_SelfTest

XADC系统自检

XSysMon_SetSequencerMode

设置采样模式

XSysMon_SetAlarmEnables

设置采样值报警的,直接关闭,不需要报警

XSysMon_SetAvg

设置采样数量

XSysMon_SetSeqInputMode

设置输入模式

XSysMon_SetSeqAvgEnables

使能采样通道

4.5 本章小结

       本章讲解了如果采集片上电压以及温度的方法,这个实验在实际工程运用中可以通过测试自生的电压和稳定判断系统是否可以正常工作,是否要做出一些报警之类的行动。  


路过

雷人

握手

鲜花

鸡蛋

最新评论

本文作者
2019-11-6 16:22
  • 1
    粉丝
  • 3779
    阅读
  • 0
    回复

关注uisrc网络

扫描关注,了解最新资讯

电话:0519-80699907
EMAIL:270682667@qq.com
地址:常州溧阳市天目云谷3号楼北楼
热门评论
排行榜