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 ...
随机推荐
- opencv 4 图像处理(2 形态学滤波:腐蚀与膨胀,开运算、闭运算、形态学梯度、顶帽、黑帽)
腐蚀与膨胀 膨胀(求局部最大值)(dilate函数) #include <opencv2/core/core.hpp> #include <opencv2/highgui/highg ...
- 学习记录:《C++设计模式——李建忠主讲》3.“组件协作”模式
“组件协作”模式:现代软件专业分工之后的第一个结果是“框架与应用程序的划分”,“组件协作”模式通过晚期绑定,来实现框架与应用程序之间的松耦合,是二者之间协作时常用的模式.典型模式:Template M ...
- 微调(Fine-tune)原理
在自己的数据集上训练一个新的深度学习模型时,一般采取在预训练好的模型上进行微调的方法.什么是微调?这里已VGG16为例进行讲解,下面贴出VGGNet结构示意图. 上面圈出来的是VGG16示意图,也可以 ...
- Ubuntu网络network eth0配置 | ubuntu network configuration
本文首发于个人博客https://kezunlin.me/post/5076bc45/,欢迎阅读! ubuntu network configuration Guide network proxy S ...
- scrapy知识补充--scrapy shell 及Spider
什么是scrapy shell? Scrapy终端是一个交互终端,我们可以在未启动spider的情况下尝试及调试代码,也可以用来测试xpath或css表达是,来查看他们的工作方式,方便爬取页面中的数据 ...
- Java File类常用方法及实例
创建:createNewFile()在指定位置创建一个空文件,成功就返回true,如果已存在就不创建,然后返回false. createTempFile(String prefix, String s ...
- Android最大方法数和解决方案
转载请标明出处:http://blog.csdn.net/shensky711/article/details/52329035 本文出自: [HansChen的博客] 什么是64K限制和Linear ...
- Java 大黑话讲解设计模式 -- UML类图
目录 1.啥是UML类图? 2.UML类图有啥用? 3.正式理解UML类图 4.使用idea画第一个UML类图 5.类之间的关系图[必须牢记] 6.类之间的关系 6.1.依赖 6.2.泛化 6.3.实 ...
- 浅析scrapy与scrapy-redis的区别
首先,要了解两者的区别,就要清楚scrapy-redis是如何产生的,有需求才会有发展,社会在日新月异的飞速发展,大量相似网页框架的飞速产生,人们已经不满足于当前爬取网页的速度,因此有了分布式爬虫,让 ...
- centos7忘记root密码的重置方法-超简单
忘记root密码,重置root密码8步. 1.在开机界面按e进入grub编辑模式 2.找到 ro修改为rw /sysroot/bin/sh 3.Ctrl + x 启动 4.chroot /sysroo ...