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 ...
随机推荐
- 深入ObjC GCD中的dispatch group工作原理。
本文是基于GCD的支持库libdispatch的源代码分析的结果或是用于作为源代码阅读的参考,尽量不帖代码,力求用UML图来说明工作流. 本文参考的源代码版本为v501.20.1,如有兴趣请自行到苹果 ...
- MachO文件详解--逆向开发
今天是逆向开发的第5天内容--MachO文件(Mac 和 iOS 平台可执行的文件),在逆向开发中是比较重要的,下面我们着重讲解一下MachO文件的基本内容和使用. 一.MachO概述 1. 概述 M ...
- 使用class关键字创建类组件、props参数
import React,{Component} from 'react' import {render} from 'react-dom' // 使用class创建组件 class Movie ex ...
- Linux菜鸟——搭建虚拟机环境
最近在学习Linux搭建服务器,但本人对于Linux一无所知,所以花了两天时间把安装,命令,控制,搭建环境等一系列操作都囫囵吞枣了一遍,但又怕自己记不住太多,所以记录下以前搭建的所有步骤,希望能提醒自 ...
- selenium常用命令之页面元素定位
WebDriver driver= new ChromeDriver(); <input type="text" id="phone" name=&q ...
- Spring(Bean)5
spel <bean id="address" class="com.atguigu.spring.beans.spel.Address"> < ...
- 程序员的算法课(19)-常用的图算法:最短路径(Shortest Path)
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/m0_37609579/article/de ...
- if判断语句的总结
1.表达式:关系表达式或逻辑表达式: 2.表达式的运算结果应该是“真”或者“假”: 真:执行该语句: 假:跳过该语句,执行下一条语句: 3.“语句”可以是单语句也可以是复合语句: ...
- java switch语句 要点注意
1.格式 switch(表达式){ case 常量1:语句1:break: case 常量2:语句2:break: case 常量3:语句3:break: .... case 常量n:语句n:brea ...
- Mac配置Gradle环境
下载Gradle 下载地址:https://gradle.org/install 下载最新版本:gradle-3.3 (当前最新版2017年2月8日) 配置Gradle环境 我的本机Gradle存放路 ...