当前位置:   article > 正文

ZedBoard教程PS篇(5):XADC测量输入电压_zedboard的ps端如何学习?

zedboard的ps端如何学习?

 开发板环境: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工程

 代码

  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * Use of the Software is limited solely to applications:
  16. * (a) running on a Xilinx device, or
  17. * (b) that interact with a Xilinx device through a bus or interconnect.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *
  27. * Except as contained in this notice, the name of the Xilinx shall not be used
  28. * in advertising or otherwise to promote the sale, use or other dealings in
  29. * this Software without prior written authorization from Xilinx.
  30. *
  31. ******************************************************************************/
  32. /*
  33. * helloworld.c: simple test application
  34. *
  35. * This application configures UART 16550 to baud rate 9600.
  36. * PS7 UART (Zynq) is not initialized by this application, since
  37. * bootrom/bsp configures it to baud rate 115200
  38. *
  39. * ------------------------------------------------
  40. * | UART TYPE BAUD RATE |
  41. * ------------------------------------------------
  42. * uartns550 9600
  43. * uartlite Configurable only in HW design
  44. * ps7_uart 115200 (configured by bootrom/bsp)
  45. */
  46. #include "xsysmon.h"
  47. #include "xparameters.h"
  48. #include "xstatus.h"
  49. #include "xil_exception.h"
  50. #include "xil_printf.h"
  51. #include "sleep.h"
  52. #define XPAR_AXI_XADC_0_DEVICE_ID 0
  53. #define C_BASEADDR 0x43C00000
  54. int main()
  55. {
  56. u16 data;
  57. u32 data1;
  58. u32 status;
  59. Xil_Out32(C_BASEADDR + 0x300 , 0x9103); //40
  60. Xil_Out32(C_BASEADDR + 0x304 , 0x3F0F);//41
  61. Xil_Out32(C_BASEADDR + 0x308 , 0x0400);//42
  62. Xil_Out32(C_BASEADDR + 0x320 , 0x800); //48
  63. while(1)
  64. {
  65. status = Xil_In32(C_BASEADDR + 0x04);
  66. if(status && 0x40 == 0x40)
  67. {
  68. data = Xil_In32(C_BASEADDR + 0x20C);
  69. data = data >> 4;
  70. data = data*0.244;
  71. xil_printf("data = %03dmv\n\r",data);
  72. }
  73. sleep(1);
  74. }
  75. return 0;
  76. }

 读取序列是否结束

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的电阻也是有误差的

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/491024
推荐阅读
相关标签
  

闽ICP备14008679号