×

AD4112微控制器无操作系统驱动程序

消耗积分:5 | 格式:pdf | 大小:173.48KB | 2021-03-23

王银喜

分享资料个

This version (02 Oct 2020 12:22) was approved by Andrei Drimbarean.The Previously approved version (22 Jul 2019 10:19) is available.Diff

AD717X No-OS Software Drivers

Introduction

This document describes the No-OS software used to control the AD717X family parts and the AD4111 device. It also includes an example of how to initialize a AD7176 part.

Overview

The AD717x family of products are fast settling, high resolution, highly accurate, multiplexed Σ-Δ analog-to-digital converters (ADC) for low bandwidth input signals, with resolution options of both 32bit and 24bit available. The products are available in both TSSOP of LFCSP depending on the product selected. AD717x family of devices include:

The inputs to the ADC can be configured as fully differential or pseudo differential inputs depending on the product chosen, this can be done via the integrated crosspoint multiplexer. An integrated precision, 2.5 V, low drift (2ppm/°C), band gap internal reference (with an output reference buffer) adds functionality and reduces the external component count. A maximum channel scan data rate is 50 kSPS (with a settling time of 20 μs), resulting in fully settled data of 17 noise free bits. User-selectable output data rates range from 5 SPS to 250 kSPS can be obtained from AD7175, AD7176 and AD7177 devices. A maximum channel scan data rate is 6.1 kSPS (with a settling time of 161 μs). User-selectable output data rates range from 1.25 SPS to 31.25 kSPS can be obtained from AD7172, AD7173 devices. The AD717x devices offers three key digital filters. The fast settling filter maximizes the channel scan rate. The Sinc3 filter maximizes the resolution for single-channel, low speed applications. For 50 Hz and 60 Hz environments, the AD717x specific filter minimizes the settling times or maximizes the rejection of the line frequency. These enhanced filters enable simultaneous 50 Hz and 60 Hz rejection with a 27 SPS output data rate (with a settling time of 36 ms). System offset and gain errors can be corrected on a per channel basis. This per channel configurability extends to the type of filter and output data rate used for each channel. All switching of the crosspoint multiplexer is controlled by the ADC and can be configured to automatically control an external multiplexer via the GPIO pins. The specified operating temperature range is −40°C to +105°C.

The AD4111, AD4112, AD4114 and AD4115 are low power, low noise, 24-bit, sigma delta (Σ-Δ) analog-to-digital converters (ADC) that integrate analog front ends (AFE) for fully differential or single-ended rail-to-rail, buffered bipolar, ±10 V voltage inputs, and 0 mA to 20 mA current inputs. They also integrate key analog and digital signal conditioning blocks to configure eight individual setups for each analog input channel in use. The AD4111 and AD4112 feature a maximum channel scan rate of 6.2 kSPS (161 μs) for fully settled data.

The AD4111 also has the unique feature of open wire detection on the voltage inputs (patent pending) for system level diagnostics using a single 5 V or 3.3 V power supply. It is housed in a 40-lead, 6 mm × 6 mm LFCSP package.

Applications

  • Process control : PLC/DCS modules
  • Temperature and pressure measurement
  • Medical and scientific multichannel instrumentation
  • Chromatography

Supported Devices

Evaluation Boards

Driver Description

The driver contains two parts:

  • The driver for the AD717X family, which may be used, without modifications, with any microcontroller.
  • The Generic Platform Driver, which implements the actual communications with the device.

Generic platform driver description

The Generic Platform Driver is where the specific communication functions for the desired type of processor and communication protocol have to be implemented. This driver implements the communication with the device and hides the actual details of the communication protocol to the specific device or family driver.

The Generic Platform Driver has a standard interface, so the device driver can be used exactly as it is provided. This standard interface includes the I2C and SPI communications, functions for managing GPIOs and a miliseconds delay function.

The milisecond delay functions is:

Function Description
void mdelay(uint32_t msecs)
Generate miliseconds delay.

I2C interface

The I2C interface has the following functions:

Function Description
int32_t i2c_init(struct i2c_desc **desc, const struct i2c_init_param *param)
Initialize the I2C communication peripheral.
int32_t i2c_remove(struct i2c_desc *desc)
Free the resources allocated by i2c_init().
int32_t i2c_write(struct i2c_desc *desc, uint8_t *data,
	uint8_t bytes_number, uint8_t stop_bit)
Write data to a slave device.
int32_t i2c_read(struct i2c_desc *desc, uint8_t *data,
	uint8_t bytes_number, uint8_t stop_bit)
Read data from a slave device.

The following structs and enums are used for the I2C interface:

typedef enum i2c_type {
	GENERIC_I2C
} i2c_type;
 
typedef struct i2c_init_param {
	enum i2c_type	type;
	uint32_t	id;
	uint32_t	max_speed_hz;
	uint8_t		slave_address;
} i2c_init_param;
 
typedef struct i2c_desc {
	enum i2c_type	type;
	uint32_t	id;
	uint32_t	max_speed_hz;
	uint8_t		slave_address;
} i2c_desc;

SPI interface

The SPI interface has the following functions:

Function Description
int32_t spi_init(struct spi_desc **desc, const struct spi_init_param *param)
Initialize the SPI communication peripheral.
int32_t spi_remove(struct spi_desc *desc)
Free the resources allocated by spi_init().
int32_t spi_write_and_read(struct spi_desc *desc, uint8_t *data,
	uint8_t bytes_number)
Write and read data to/from SPI.

The following structs and enums are used for the SPI interface:

typedef enum spi_type {
	GENERIC_SPI
} spi_type;
 
typedef enum spi_mode {
	SPI_MODE_0 = (0 | 0),
	SPI_MODE_1 = (0 | SPI_CPHA),
	SPI_MODE_2 = (SPI_CPOL | 0),
	SPI_MODE_3 = (SPI_CPOL | SPI_CPHA)
} spi_mode;
 
typedef struct spi_init_param {
	enum spi_type	type;
	uint32_t	id;
	uint32_t	max_speed_hz;
	enum spi_mode	mode;
	uint8_t		chip_select;
} spi_init_param;
 
typedef struct spi_desc {
	enum spi_type	type;
	uint32_t	id;
	uint32_t	max_speed_hz;
	enum spi_mode	mode;
	uint8_t		chip_select;
} spi_desc;

GPIO interface

The GPIO interface has the following functions:

Function Description
int32_t gpio_get(struct gpio_desc **desc, uint8_t gpio_number)
Obtain the GPIO decriptor.
int32_t gpio_remove(struct gpio_desc *desc)
Free the resources allocated by gpio_get().
int32_t gpio_direction_input(struct gpio_desc *desc)
Enable the input direction of the specified GPIO.
int32_t gpio_direction_output(struct gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
int32_t gpio_get_direction(struct gpio_desc *desc, uint8_t *direction)
Get the direction of the specified GPIO.
int32_t gpio_set_value(struct gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
int32_t gpio_get_value(struct gpio_desc *desc, uint8_t *value)
Get the value of the specified GPIO.

The following structs and enums are used for the GPIO interface:

typedef enum gpio_type {
	GENERIC_GPIO
} gpio_type;
 
typedef struct gpio_desc {
	enum gpio_type	type;
	uint32_t	id;
	uint8_t		number;
} gpio_desc;

04 Sep 2018 12:10 · Andrei Drimbarean

AD717X Family Driver Description

The AD717X driver contains the following:

  • AD717X.h - Header file of the driver. Contains the register map definitions, the driver function declarations, custom data types to be used by the driver and driver specific constants.
  • AD717X.c - Implementation file of the driver. Contains the implementations of the driver functions.

The driver works with any of the following headers by including them in your main project just as you include the ad717x.h header:

  • AD7172_2_regs.h
  • AD7172_4_regs.h
  • AD7173_8_regs.h
  • AD7175_2_regs.h
  • AD7175_8_regs.h
  • AD7176_2_regs.h
  • AD7177_2_regs.h
  • AD411x_regs.h

Each header declares an array of all register of the device that the header describes.

The following functions are implemented in this version of AD717X driver:

Function Description
ad717x_st_reg *AD717X_GetReg(ad717x_device *device, uint8_t reg_address)
Retrieves a pointer to the register that matches the given address.
int32_t AD717X_ReadRegister(ad717x_device *device, uint8_t addr)
Reads the value of the specified register.
int32_t AD717X_WriteRegister(ad717x_device *device, uint8_t addr)
Writes the value of the specified register.
int32_t AD717X_Reset(ad717x_dev *device)
Resets the device.
int32_t AD717X_WaitForReady(ad717x_dev *device, uint32_t timeout)
Waits until a new conversion result is available.
int32_t AD717X_ReadData(ad717x_dev *device, int32_t* pData)
Reads the conversion result from the device.
int32_t AD717X_ComputeDataregSize(ad717x_dev *device)
Computes data register read size to account for bit number and status read.
uint8_t AD717X_ComputeCRC8(uint8_t* pBuf, uint8_t bufSize)
Computes the CRC checksum for a data buffer.
uint8_t AD717X_ComputeXOR8(uint8_t * pBuf, uint8_t bufSize)
Computes the XOR checksum for a data buffer.
int32_t AD717X_UpdateCRCSetting(ad717x_dev *device)
Updates the CRC settings.
int32_t AD717X_Init(ad717x_dev **device, ad717x_init_param init_param)
Initializes the AD717x.
int32_t AD717X_remove(ad717x_dev *dev)
Free the resources allocated by AD717X_Init().

Downloads

Using the API

The driver can only work together with a structure that holds the state of a device, where state means all information about the device including a copy of all register values written to the device at a certain point. This structure will henceforth be referred as an instance of a driver.
All driver functions take a handler of a driver instance as the first argument. This allows the driver to be used with multiple devices simultaneously, without the need to replicate the .c and .h files.

Before using any API call an instance of the driver must first be created and then initialized using the AD717X_Init() which has the following parameters:

  • device: the reference of the new driver instance. A new instance can be obtained by simply declaring a pointer to one then using it to call AD717X_Init():
     ad717x_device *my_ad7176_2; 
  • init_param: the initialization structure. One must be declared and initial values must be added before calling AD717X_Init().
     ad717x_init_param ad7176_2_init_param; 

    ad717x_init_param has the following definition:

     typedef struct {
    	/* SPI */
    	spi_init_param		spi_init;
    	/* Device Settings */
    	ad717x_st_reg		*regs;
    	uint8_t			num_regs;
    } ad717x_init_param; 

    Where:

    • spi_init: is the initialization structure for the SPI API described in the Generic Platform Driver
    • regs: must point to a register array of the device. It will too be stored into the driver and used by the driver. The ad7176_2_regs array defined and initialized in ad7176_2_regs.h can be passed here as parameter provided that the following directives are added inside the file where the driver is being used:
       #include "ad7176_2_regs.h" 
       #define AD7176_2_INIT 

      Alternatively, a new register array can be defined by user which must be properly initialized before calling AD717X_Setup() function.

      ad717x_st_reg my_ad7176_2_regs[] = 
      {
          { AD717X_STATUS_REG, 0x00, 1 },
          { AD717X_ADCMODE_REG, 0x0000, 2 },
          ...
      }
    • num_regs: must provide the number of elements in regs.

A AD717X_Init() call will also reset the part then use all register values stored in the array pointed by the regs parameter to configure the part (the registers that are “Read-only” will not be written during this call).

The following code snipped provides an example of driver usage:

#include "ad7176_2_regs.h"
#define AD7176_2_INIT
 
/* Create a new driver instance */
ad717x_device *my_ad7176_2;
ad717x_init_param ad7176_2_init;
 
ad7176_2_init.spi_init.chip_select = 0x01;
ad7176_2_init.spi_init.id = 0;
ad7176_2_init.spi_init.max_speed_hz = 1000000;
ad7176_2_init.spi_init.mode = SPI_MODE_3;
ad7176_2_init.spi_init.type = GENERIC_SPI;
ad7176_2_init.regs = ad7176_2_regs;
ad7176_2_init.num_regs = sizeof(ad7176_2_regs) / sizeof(ad7176_2_regs[0]);
 
/* Other variables */
long timeout = 1000;
long ret;
long sample;
.
.
.
/* Initialize the driver instance and let's use the ad7176_2_regs array defined in ad7176_2_regs.h */
ret = AD717X_Init(&my_ad7176_2, ad7176_2_init);
if (ret < 0)
    /* Something went wrong, check the value of ret! */
 
/* Read data from the ADC */
ret = AD717X_WaitForReady(my_ad7176_2, timeout);
if (ret < 0)
    /* Something went wrong, check the value of ret! */
 
ret = AD717X_ReadData(my_ad7176_2, &sample);
if (ret < 0)
        /* Something went wrong, check the value of ret! */

More information

01 Jun 2012 12:17

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.lene-v.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'AD4112微控制器无操作系统驱动程序',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.lene-v.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);