quick start guide for XMEGA ADC
This is the quick start guide for the Analog to Digital Converter (ADC), with step-by-step instructions on how to configure and use the driver in a selection of use cases.
The use cases are described with "setup" and "usage" sections, which each have "example code" and "workflow" subsections. This documentation first presents code fragments and function definitions along with instructions on where they can be placed, e.g., into the application C-file or the main() function, then follows up with explanations for all the lines of code.
Use cases
In addition to the basic use case below, refer to the following use cases for demonstrations of the ADC's features:
We recommend reading all the use cases for the sake of all the notes on considerations, limitations and other helpful details.
Basic use case
In this basic use case, ADCA is configured for:
- sampling on a single channel (0)
- I/O pin as single-ended input (PA0)
- unsigned conversions
- 12-bit resolution
- internal 1V reference
- manual conversion triggering
- polled operation (no interrupts)
Completed conversions are detected by waiting for the relevant interrupt flag to get set. The ADC result is then stored in a local variable.
Setup steps
Example code
Add to application C-file:
Add to main():
Workflow
- Add macros for the ADC and its channel to use, so they are easy to change:
- #define MY_ADC ADCA#define MY_ADC_CH ADC_CH0
- Create a function
adc_init()to intialize the ADC:- static void adc_init(void){// ...}
- Allocate configuration structs for the ADC and its channel:
- struct adc_config adc_conf;struct adc_channel_config adcch_conf;
- Initialize the structs:
- adc_read_configuration(&MY_ADC, &adc_conf);adcch_read_configuration(&MY_ADC, MY_ADC_CH, &adcch_conf);
- Attention
- This step must not be skipped because uninitialized structs may contain invalid configurations, thus giving unpredictable behavior.
- Set conversion parameters to unsigned, 12-bit and internal 1V reference:
- Note
- Only single-ended input is possible with unsigned conversions.
- Set conversion trigger to manual triggering:
- adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);
- Note
- The number of channels to trigger (1) and base event channel (0) don't affect operation in this trigger mode, but sane values should still be supplied.
- Set ADC clock rate to 200 KHz or less:
- adc_set_clock_rate(&adc_conf, 200000UL);
- Note
- The driver attempts to set the ADC clock rate to the fastest possible without exceeding the specified limit. Refer to the applicable device datasheet and manual for details on maximum ADC clock rate.
- Set pin 0 on the associated port as the single-ended input:
- Note
- For single-ended input, the negative input must be none and the gain must be unity (1x).
- Write the configurations to ADC and channel:
- adc_write_configuration(&MY_ADC, &adc_conf);adcch_write_configuration(&MY_ADC, MY_ADC_CH, &adcch_conf);
- Initialize the clock system:
- sysclk_init();
- Note
- The ADC driver requires the system clock driver to be initialized in order to compute the correct ADC clock rate in step 6.
- Call our ADC init function:
- adc_init();
Usage steps
Example code
Add to, e.g., main-loop in application C-file:
Workflow
- Allocate a variable to contain the ADC result:
- uint16_t result;
- Enable the configured ADC:
- adc_enable(&MY_ADC);
- Trigger a single conversion on the ADC channel:
- adc_start_conversion(&MY_ADC, MY_ADC_CH);
- Wait for the channel's interrupt flag to get set, indicating a completed conversion:
- adc_wait_for_interrupt_flag(&MY_ADC, MY_ADC_CH);
- Note
- The interrupt flags are set even if the interrupts are disabled. Further, this function will clear the interrupt flag after it has been set, so we do not need to clear it manually.
- Read out the result of the ADC channel:
- result = adc_get_result(&MY_ADC, MY_ADC_CH);
- To do more conversions, go back to step 3.
quick start guide for XMEGA ADC的更多相关文章
- SlickUpload Quick Start Guide
Quick Start Guide The SlickUpload quick start demonstrates how to install SlickUpload in a new or ex ...
- RF《Quick Start Guide》操作总结
这篇文章之所以会给整理出来,是因为学了一个季度的RF后,再去看官网的这个文档,感触破多,最大的感触还是觉得自己走了不少弯路,还有些是学习方法上的弯路.在未查看这类官网文档之前,更多的是看其他各种人的博 ...
- QUICK START GUIDE
QUICK START GUIDE This page is a guide aimed at helping anyone set up a cheap radio scanner based on ...
- Akka Stream文档翻译:Quick Start Guide: Reactive Tweets
Quick Start Guide: Reactive Tweets 快速入门指南: Reactive Tweets (reactive tweets 大概可以理解为“响应式推文”,在此可以测试下GF ...
- RobotFramework 官方demo Quick Start Guide rst配置文件分析
RobotFramework官方demo Quick Start Guide rst配置文件分析 by:授客 QQ:1033553122 博客:http://blog.sina.com.c ...
- RobotFramework RobotFramework官方demo Quick Start Guide浅析
RobotFramework官方demo Quick Start Guide浅析 by:授客 QQ:1033553122 博客:http://blog.sina.com.cn/ishouk ...
- pax3 quick start guide
pax3 quick start guide 外观图: 配置:1 * pax3 主机:2 * 吸嘴(一个平的,一个凸的):2 * 底盖(一个烟草的,一个烟膏的):3 * 过滤片:1 * USB充:1 ...
- [摘录]quarts:Quartz Quick Start Guide
(Primarily authored by Dafydd James) Welcome to the QuickStart guide for Quartz. As you read this gu ...
- Quartz Quick Start Guide
Welcome to the QuickStart guide for Quartz. As you read this guide, expect to see details of: Downlo ...
随机推荐
- Centos下的MySQL安装及配置
里使用的是VMware虚拟机和Centos7系统 虚拟机安装这里不多讲,网上教程很多了,这里就介绍下虚拟机的网络配置. 虚拟机网络配置 Centos网络连接模式这里设置为桥接模式,不用勾选复制物理网络 ...
- 使用图数据库 Nebula Graph 数据导入快速体验知识图谱 OwnThink
前言 本文由 Nebula Graph 实习生@王杰贡献. 最近 @Yener 开源了史上最大规模的中文知识图谱--OwnThink(链接:https://github.com/ownthink/Kn ...
- day 18 random模块 时间模块 sys模块 os模块
import random 利用random模块可以进行从一个列表或者数字范围之间随机取出一个数字 # 取随机小数 : 数学计算 print(random.random()) # 取0-1之间的小数 ...
- Java基础-Java基本语法
注释: 1:多行 /* */ 2:单行 // 3:文档 /** */ 基本数据类型: 1:整形 byte(1) short(2) int(4) long(8)(一般申明lo ...
- Head First设计模式——模板方法模式
前言:本篇我们讲解模板方法模式,我们以咖啡和茶的冲泡来学习模板方法.关于咖啡另一个设计模式例子也以咖啡来讲解,可以看下:Head First设计模式——装饰者模式 废话不多说,开始进入模板方法模式. ...
- Error : Program type already present: android.support.design.widget.CoordinatorLayout$
背景 因为公司一个app项目需要扩展,因为功能较多且较完整的流程与业务,而且和以前的业务关系不大,所以我整合到了 另外一个分包中(代号:newFunc,请注意是代号)进行依赖. 当我写完这部分业务开始 ...
- Vue组件通信之非父子组件传值
前言: 如果想要了解非父子关系的组件传值,最好是在了解父传子和子传父的基础上在来了解非父子传值可能会有更透彻的思路. 因为非父子传值是通过定义事件总线来代理实现父传子+子传父从而实现的传值方式. 这是 ...
- css之文本两端对齐的两种解决方法
说起文本对齐,大家都知道text-align,最常用的有left.right.center,今天我们说一下justify,也就是文本两端 对齐.说起来简单,但是有些小坑大家还是要注意的. 现在我们有这 ...
- 小白的springboot之路(五)、集成druid
0-前言 Druid阿里巴巴开源的一个java数据库连接池,是Java语言中最好的数据库连接池,Druid能够提供强大的监控和扩展功能:集成它能够方便我们对数据库连接进行监控和分析,下面我们来集成它: ...
- Layui下拉3级联动
这里我就不给大家详细说明了直接附图: js代码: layui.use(['layer', 'form','xform','layer'], function () { var element = la ...