赞
踩
开发板环境:vivado2017.4
开发板:Zedboard 芯片型号:xc7z020clg484-1
本章主要使用zynq自带的xadc模块通过VP和VN测量外部电压
xadc硬件原理图
工程建立可以参考hello_world工程,这里调用zynq核进行配置,配置完成后如下图所示
调用xadc核并配置
点击OK,完成xadc的配置
xadc和zynq配置完成后进行自动连接,自动连接后如下图所示
生成顶层文件和生成bit文件后如下图所示
导出硬件配置
打开sdk后,新建fsbl
点击Finish
生成的fsbl
新建一个xadc_test工程
选择hello_world模版,点击Finish
更改hello_world工程
代码
- /******************************************************************************
- *
- * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * Use of the Software is limited solely to applications:
- * (a) running on a Xilinx device, or
- * (b) that interact with a Xilinx device through a bus or interconnect.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Except as contained in this notice, the name of the Xilinx shall not be used
- * in advertising or otherwise to promote the sale, use or other dealings in
- * this Software without prior written authorization from Xilinx.
- *
- ******************************************************************************/
-
- /*
- * helloworld.c: simple test application
- *
- * This application configures UART 16550 to baud rate 9600.
- * PS7 UART (Zynq) is not initialized by this application, since
- * bootrom/bsp configures it to baud rate 115200
- *
- * ------------------------------------------------
- * | UART TYPE BAUD RATE |
- * ------------------------------------------------
- * uartns550 9600
- * uartlite Configurable only in HW design
- * ps7_uart 115200 (configured by bootrom/bsp)
- */
-
- #include "xsysmon.h"
- #include "xparameters.h"
- #include "xstatus.h"
- #include "xil_exception.h"
- #include "xil_printf.h"
- #include "sleep.h"
-
- #define XPAR_AXI_XADC_0_DEVICE_ID 0
-
- #define C_BASEADDR 0x43C00000
-
-
-
- int main()
- {
-
- u16 data;
- u32 data1;
- u32 status;
-
-
- Xil_Out32(C_BASEADDR + 0x300 , 0x9103); //40
- Xil_Out32(C_BASEADDR + 0x304 , 0x3F0F);//41
- Xil_Out32(C_BASEADDR + 0x308 , 0x0400);//42
- Xil_Out32(C_BASEADDR + 0x320 , 0x800); //48
-
- while(1)
- {
- status = Xil_In32(C_BASEADDR + 0x04);
- if(status && 0x40 == 0x40)
- {
-
-
- data = Xil_In32(C_BASEADDR + 0x20C);
- data = data >> 4;
- data = data*0.244;
-
- xil_printf("data = %03dmv\n\r",data);
- }
-
- sleep(1);
- }
-
- return 0;
- }
读取序列是否结束
status = Xil_In32(C_BASEADDR + 0x04);
读取vp和vn对应寄存器
data = Xil_In32(C_BASEADDR + 0x20C);
虽然对应寄存器一共有16位,但有效值为高12位,所以往右移四位
data = data >> 4;
把1V的电压分成4096,所以每一个采样为0.244mv
data = data*0.244;
生成BOOT.bin文件
将 BOOT.bin文件拷贝到SD卡里运行
因测量的电压最大1V,测量的电压是3.3V,使用5个1K电阻分压,也就是3.3/5 = 66mv左右,外接的线路板如下图连接
开发板连接如下图所示
开发板上单运行,连接串口设置波特率为115200,使用putty打印输出结果
理论计算差不多66mv,实际打印71mv也差不多,毕竟1K的电阻也是有误差的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。