• examples里的main.c
/******************************************************************************/
/*                                                                            */
/* main.c -- Example program using the PmodAD5 IP                            */
/*                                                                            */
/******************************************************************************/
/* Author: Jon Peyron                                                         */
/*                                                                            */
/******************************************************************************/
/* File Description:                                                          */
/*                                                                            */
/* This demo continuously reads analog data from the PmodAD5 converts it into */
/* digital data. Then it converts the digital data into voltage and prints    */
/* the value through uart to a serial terminal                                */
/*                                                                            */
/******************************************************************************/
/* Revision History:                                                          */
/*                                                                            */
/*    12/19/17(JPEYRON):  Created                                             */
/*                                                                            */
/******************************************************************************//************ Include Files ************/#include "PmodAD5.h"
#include "sleep.h"
#include "xil_cache.h"
#include <stdio.h>
#include "xparameters.h"/************ Macro Definitions ************//************ Function Prototypes ************/void DemoInitialize();void DemoRun();void DemoCleanup();void EnableCaches();void DisableCaches();/************ Global Variables ************/PmodAD5 myDevice;/************ Function Definitions ************/int main(void) {DemoInitialize();DemoRun();DemoCleanup();return 0;
}void DemoInitialize() {EnableCaches();AD5_begin(&myDevice, XPAR_PMODAD5_0_AXI_LITE_SPI_BASEADDR);}void DemoRun() {xil_printf("starting...\n\r");while (1) {float voltage= 0;AD5_readData(&myDevice);voltage = AD5_DataToVoltage(&myDevice);printf("Voltage is: %lf \n\r", voltage); // format text for displaysleep(10);}
}void DemoCleanup() {AD5_end(&myDevice);DisableCaches();
}void EnableCaches() {#ifdef __MICROBLAZE__
#ifdef XPAR_MICROBLAZE_USE_DCACHEXil_DCacheEnable();
#endif
#ifdef XPAR_MICROBLAZE_USE_ICACHEXil_ICacheEnable();
#endif
#endif
}void DisableCaches() {#ifdef __MICROBLAZE__
#ifdef XPAR_MICROBLAZE_USE_DCACHEXil_DCacheDisable();
#endif
#ifdef XPAR_MICROBLAZE_USE_ICACHEXil_ICacheDisable();
#endif
#endif
}
  • src里的PmodAD5.c
/*************************************************************************/
/*                                                                       */
/*     PmodAD5.c --     PmodAD5 Driver Source                            */
/*                                                                       */
/*************************************************************************/
/*     Author: Jon Peyron                                                */
/*     Copyright 2017, Digilent Inc.                                     */
/*************************************************************************/
/*  Module Description:                                                  */
/*                                                                       */
/*            This file contains source code for the PmodAD5 driver      */
/*                                                                       */
/*************************************************************************/
/*  Revision History:                                                    */
/*                                                                       */
/*            12/19/2017(JPEYRON): Created                                */
/*                                                                       */
/*************************************************************************//***************************** Include Files *******************************/#include "PmodAD5.h"/************************** Function Definitions ***************************/
XSpi_Config AD5Config =
{0,0,1,0,1,8,0,0,0,0,0
};
/* ------------------------------------------------------------ */
/***    void AD1_begin(PmodAD5* InstancePtr, u32 BaseAddress)
**
**  Parameters:
**      InstancePtr: A PmodAD5 object to start
**      BaseAddress: The base address of the PmodAD5 AXI_LITE_SAMPLE interface
**
**  Description:
**      Initialize the PmodAD5 device - note that the AD5 IP is free-running, and this function just prepares the driver for use.
**      Also calls AD5_WriteConfig which configures the AD5 for a gain of 1 and set to differential.
*/
void AD5_begin(PmodAD5* InstancePtr, u32 SPI_Address)
{AD5Config.BaseAddress = SPI_Address;AD5_SPIInit(&InstancePtr->AD5Spi);AD5_WriteConfig(InstancePtr);}/* ------------------------------------------------------------ */
/***    AD5_end(void)****      Parameters:**              InstancePtr - PmodAd5 object to stop****      Return Value:**              none****      Errors:**              none****      Description:**              Stops the device*/
void AD5_end(PmodAD5* InstancePtr) {XSpi_Stop(&InstancePtr->AD5Spi);
}/* ------------------------------------------------------------ */
/***    AD5_SPIInit****     Parameters:**             none****     Return Value:**             none****     Errors:**             none****     Description:**             Initializes the PmodAD5 SPI.*/
int AD5_SPIInit(XSpi *SpiInstancePtr) {int Status;Status = XSpi_CfgInitialize(SpiInstancePtr, &AD5Config,AD5Config.BaseAddress);if (Status != XST_SUCCESS) {return XST_FAILURE;}Status = XSpi_SetOptions(SpiInstancePtr, (XSP_MASTER_OPTION| XSP_CLK_ACTIVE_LOW_OPTION | XSP_CLK_PHASE_1_OPTION)| XSP_MANUAL_SSELECT_OPTION);if (Status != XST_SUCCESS) {return XST_FAILURE;}Status = XSpi_SetSlaveSelect(SpiInstancePtr, 1);if (Status != XST_SUCCESS) {return XST_FAILURE;}/** Start the SPI driver so that the device is enabled.*/XSpi_Start(SpiInstancePtr);/** Disable Global interrupt to use polled mode operation*/XSpi_IntrGlobalDisable(SpiInstancePtr);return XST_SUCCESS;
}/* ------------------------------------------------------------ */
/***   AD5_readData****     Synopsis:**            AD5_readData(PmodAD5* InstancePtr);****     Parameters:**             PmodAD5* InstancePtr - the PmodAD5 object to communicate with****     Return Value:**             none****     Errors:**             none****     Description:**             Reads data in through SPI. It sends the first byte to the communication register which sets communication to read for**             the next 3 bytes.**             Data is stored into data1, data2 and data3.*/
void AD5_readData(PmodAD5* InstancePtr) {u8 bytes[4];bytes[0]= 0x58; //first byte is sent to the communication register which sets communication to//reading the next 3 bytes from the Data registerInstancePtr->data1 = 0;InstancePtr->data2 = 0;InstancePtr->data3 = 0;XSpi_Transfer(&InstancePtr->AD5Spi, bytes, bytes, 4);InstancePtr->data1 = bytes[1];InstancePtr->data2 = bytes[2];InstancePtr->data3 = bytes[3];}
/* ------------------------------------------------------------ */
/***   AD5_WriteConfig****     Synopsis:**            AD5_WriteConfig(PmodAD5* InstancePtr);****     Parameters:**             PmodAD5* InstancePtr - the PmodAD5 object to communicate with****     Return Value:**             none****     Errors:**             none****     Description:**             writes data to the configuration register through SPI. It sends the first byte to the communication**             register which sets communication to write for the next 3 bytes.**             gain is set to 1 and in differential mode*/
void AD5_WriteConfig(PmodAD5* InstancePtr)
{u8 bytes[4];bytes[0] = 0x10; //first byte is sent to the communication register which sets communication to//writing the next 3 bytes to the Configuration register//gain is set to 1 and in differential modebytes[1] = 0x00;bytes[2] = 0x01;bytes[3] = 0x10;XSpi_Transfer(&InstancePtr->AD5Spi, bytes, bytes, 4);}/* ------------------------------------------------------------ */
/***   AD5_DataToVoltage****     Synopsis:**            AD5_DataToVoltage(PmodAD5* InstancePtr);****     Parameters:**             PmodAD5* InstancePtr - the PmodAD5 object to communicate with****     Return Value:**             none****     Errors:**             none****     Description:**             Combines the 3 bytes into a unsigned long integer and then converts the digital data into a float voltage value*/float AD5_DataToVoltage(PmodAD5* InstancePtr)  {float voltage = 0;
//  char mGain = 0;float mVref = 2.5;
//  char mPolarity = 0;int PGAGain = 1;unsigned long rawdata=0;//combining the 3 byte data to one unsigned long integerrawdata = InstancePtr->data1;rawdata = rawdata * 256 +InstancePtr->data2;rawdata = rawdata * 256 + InstancePtr->data3;//converting from digital data to voltagevoltage = (((float)rawdata / (float)8388608) - (float)1) * (mVref / (float)PGAGain);return(voltage);
}
  • src里的PmodAD5.c
/*************************************************************************/
/*                                                                       */
/*     PmodAD5.h --     PmodAD5 Driver Source                            */
/*                                                                       */
/*************************************************************************/
/*     Author: Jon Peyron                                                */
/*     Copyright 2017, Digilent Inc.                                     */
/*************************************************************************/
/*  Module Description:                                                  */
/*                                                                       */
/*            This file contains source code for the PmodAD5 driver      */
/*                                                                       */
/*************************************************************************/
/*  Revision History:                                                    */
/*                                                                       */
/*            12/19/2017(JPEYRON): Created                                */
/*                                                                       */
/*************************************************************************/#ifndef PMODAD5_H
#define PMODAD5_H/****************** Include Files ********************/#include "xil_types.h"
#include "xstatus.h"
#include "xspi_l.h"
#include "xspi.h"/* ------------------------------------------------------------ */
/*                  Definitions                                 */
/* ------------------------------------------------------------ */typedef struct PmodAD5 {XSpi AD5Spi;u8 data1;u8 data2;u8 data3;} PmodAD5;/* ------------------------------------------------------------ */
/*                  Procedure Declarations                      */
/* ------------------------------------------------------------ */void   AD5_begin(PmodAD5* InstancePtr, u32 SPI_Address);
void   AD5_end(PmodAD5* InstancePtr);
int    AD5_SPIInit(XSpi *SpiInstancePtr);
void   AD5_readData(PmodAD5* InstancePtr);
void   AD5_WriteConfig(PmodAD5* InstancePtr);
float  AD5_DataToVoltage(PmodAD5* InstancePtr);#endif // PMODAD5_H

Digilent提供的Pmod AD5驱动程序相关推荐

  1. Digilent提供的Pmod AD1驱动程序

    在github上下载Digilent提供的IP核,在路径\ip\Pmods下找到PmodAD1 点进去\drivers\PmodAD1中examples是main主程序 /************** ...

  2. 简单分析Pmod AD5的文档和官方例程

    根据官方文档Pmod AD5是24位AD,用得芯片是AD7193(我尝试阅读了这个芯片手册,麻了太多了,还是直接看Digilent官方提供的程序),使用通信协议是SPI,使用Pmod的好处是不用关心接 ...

  3. pmod ad2 digilent 提供的pmodad2.c和pmodad2.h

    配合原理图服用 PmodAD2.h /******************************************************************************/ / ...

  4. Digilent提供的PmodOLEDrgb驱动程序

    examples里的main.c /******************************************************************************/ /* ...

  5. 开启Digilent提供的Linux内核的NFS支持

    ZEDBoard上出厂的SD卡中自带了一个较完整的linux系统,虽然是精简版,但是对于开发来说已经足够了,在嵌入式linux开发中,挂载NFS协助调试非常常见,但是Digilent给出的内核中并没有 ...

  6. linux内核配置nfs,【参赛手记】开启Digilent提供的Linux内核的NFS支持

    ZEDBoard上出厂的SD卡中自带了一个较完整的linux系统,虽然是精简版,但是对于开发来说已经足够了,在嵌入式linux开发中,挂载NFS协助调试非常常见,但是Digilent给出的内核中并没有 ...

  7. 下载pyboard的flash中的驱动程序_NVIDIA提供了STUDIO图形驱动程序版本441.12--立即下载...

    NVIDIA提供了一个新的STUDIO图形软件包,该软件包与其多个视频卡兼容,即版本441.12,该软件包支持最新的Adobe MAX,包括与OptiX 7的兼容性,并修复了多个问题. 具体而言,生产 ...

  8. WinUSB - 微软为所有 USB 设备提供的常规驱动程序

    WinUSB - 微软为所有 USB 设备提供的常规驱动程序  [复制链接]     shangdawei 20 主题 0 好友 717 积分 高级会员 莫元 696 发消息 电梯直达 1楼  发表于 ...

  9. ENC28j60以太网芯片驱动程序简介

    转载: 本介绍可分为三块内容: 1.以太网数据帧结构 符合IEEE802.3标准的以太网帧的长度是介于64-1516字节之间.主要由目标MAC地址.源MAC地址.类型/长度字段.数据有效负载.可选填充 ...

最新文章

  1. Genome-scale de novo assembly using ALGA 使用ALGA进行 基因组规模的从头组装
  2. AI战“疫”!人工智能在疫情中的重要作用
  3. Android 解锁屏启动过程
  4. python flask解决上传下载的问题
  5. 【机房真是】。。。各种蛋疼。。。
  6. FireMonkey 保存图片到JPG的方法 BMP转JPG
  7. 数据结构:单链表和双向链表
  8. Spring中的ApplicationContextAware使用
  9. c#多线程thread实例详解
  10. java实现自动定位,java swing 如何自动定位尾部
  11. JS基础-百度换肤案例
  12. 写给Javaer看的Kotlin教程
  13. Android人脸识别活体检测开发入门--基于虹软免费SDK实现
  14. word中公式和文字不在一条水平线上
  15. 【CV】细粒度图像分割 (FGIS)
  16. dos下masm的out of memory 怎么解决,求大佬指教
  17. 拜师——python基础入门—第3大节课—列表,排序,revered逆序,max,min,sum——day15
  18. 程序员面试必备,HR 的那些黑话大全,太真实了!
  19. java中整数的整数次方_数值的整数次方java
  20. 事务 Transcation 是什么?

热门文章

  1. php dropdownlist,下拉列表多级联动dropDownList示例代码
  2. html中grid布局,CSS:玩转grid布局
  3. python 选择多个文件_python-PyQt QFileDialog-多目录选择
  4. python非法变量名_python – DatabaseError:ORA-01036:非法变量名称/编号
  5. android java代码打印系统日志_Java快速开发平台源码
  6. java keydown_键盘事件keydown、keypress、keyup随笔整理总结
  7. 【Ahoi2005】【BZOJ1968】COMMON 约数研究(水题,乱搞,约数)
  8. oracle对象不在回收站中,Oracle PURGE子句清除回收站中的对象
  9. css样式让样式失效,如何让css样式失效
  10. 梯度消失和梯度爆炸_梯度消失和梯度爆炸详解