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 ...
随机推荐
- windows 10上源码编译libjpeg-turbo和使用教程 | compile and use libjpeg-turbo on windows 10
本文首发于个人博客https://kezunlin.me/post/83828674/,欢迎阅读! compile and use libjpeg-turbo on windows 10 Series ...
- 基于loghub的消息消费延迟监控
我们可以把loghub当作一个消息中间件来使用.如果能知道当前的消费进度,自然好了,否则消费情况一无所知,总是有点慌! loghub消费分两种情况,一是普通消费,二是消费组消费: 消费组消费,logh ...
- Jeewx-Boot 1.1 版本发布,基于SpringBoot的开源微信管家系统
项目介绍 JeewxBoot是一款基于SpringBoot的开源微信管家系统,采用SpringBoot2.1.3 + Mybatis + Velocity 框架技术.支持微信公众号.微信第三方平台(扫 ...
- 对照谈-官方spring-boot-starter和自定义starter异同分析
在前面我讲用spring-boot-starter-mail发邮件的时候,我侧重看的是spring boot发邮件的便利性,今天,我们聊下另外一个方面,spring-boot-starter自身的结构 ...
- vue实例化过程
我们在用vue进行开发项目时,是否存在疑惑,new Vue(xxx)的过程中,究竟发生了什么?定义的数据,是如何绑定到视图上的?本篇主要介绍在实例化vue时,主要做了哪些事,文章比较长,主要篇幅内容为 ...
- php方法注释
注释格式 <?php /** * @method 发送邮件 * @url email/send?token=xxx * @http POST * @param token string [必填] ...
- 用墨卡托和GPS坐标计算距离时误差测试
iOS墨卡托和GPS坐标计算距离时误差测试,测试结果: 墨卡托和gps坐标来回转换没有误差. 墨卡托坐标计算出的距离比gps坐标计算出的距离大,100/92*100 = 108米,每100米多算出8米 ...
- Python如何爬取实时变化的WebSocket数据【华为云技术分享】
一.前言 作为一名爬虫工程师,在工作中常常会遇到爬取实时数据的需求,比如体育赛事实时数据.股市实时数据或币圈实时变化的数据.如下图: Web 领域中,用于实现数据'实时'更新的手段有轮询和 WebSo ...
- 【我的物联网成长记8】超速入门AT指令集【华为云技术分享】
[摘要] 在物联网中,AT命令集可用于控制&调测设备.通信模块入网等.本文为您介绍NB-IoT常用的AT命令集及其调测工具. 什么是AT指令集 AT命令,用来控制TE(Terminal Equ ...
- Python如何爬取实时变化的WebSocket数据
一.前言 作为一名爬虫工程师,在工作中常常会遇到爬取实时数据的需求,比如体育赛事实时数据.股市实时数据或币圈实时变化的数据.如下图: Web 领域中,用于实现数据'实时'更新的手段有轮询和 WebSo ...