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:

#define MY_ADC ADCA
#define MY_ADC_CH ADC_CH0
 
static void adc_init(void)
{
struct adc_config adc_conf;
struct adc_channel_config adcch_conf;
 
adc_read_configuration(&MY_ADC, &adc_conf);
adcch_read_configuration(&MY_ADC, MY_ADC_CH, &adcch_conf);
 
adc_set_clock_rate(&adc_conf, 200000UL);
 
 
adc_write_configuration(&MY_ADC, &adc_conf);
adcch_write_configuration(&MY_ADC, MY_ADC_CH, &adcch_conf);
}

Add to main():

adc_init();

Workflow

  1. 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
  2. Create a function adc_init() to intialize the ADC:
    • static void adc_init(void)
      {
      // ...
      }
  3. Allocate configuration structs for the ADC and its channel:
  4. 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.
  5. Set conversion parameters to unsigned, 12-bit and internal 1V reference:
  6. Set conversion trigger to manual triggering:
    • 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.
  7. 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.
  8. Set pin 0 on the associated port as the single-ended input:
  9. Write the configurations to ADC and channel:
  10. Initialize the clock system:
    • Note
      The ADC driver requires the system clock driver to be initialized in order to compute the correct ADC clock rate in step 6.
  11. Call our ADC init function:
    • adc_init();

Usage steps

Example code

Add to, e.g., main-loop in application C-file:

uint16_t result;
 
adc_enable(&MY_ADC);
 
adc_start_conversion(&MY_ADC, MY_ADC_CH);
adc_wait_for_interrupt_flag(&MY_ADC, MY_ADC_CH);
 
result = adc_get_result(&MY_ADC, MY_ADC_CH);

Workflow

  1. Allocate a variable to contain the ADC result:

    • uint16_t result;
  2. Enable the configured ADC:
  3. Trigger a single conversion on the ADC channel:
  4. 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.
  5. Read out the result of the ADC channel:
  6. To do more conversions, go back to step 3.

quick start guide for XMEGA ADC的更多相关文章

  1. SlickUpload Quick Start Guide

    Quick Start Guide The SlickUpload quick start demonstrates how to install SlickUpload in a new or ex ...

  2. RF《Quick Start Guide》操作总结

    这篇文章之所以会给整理出来,是因为学了一个季度的RF后,再去看官网的这个文档,感触破多,最大的感触还是觉得自己走了不少弯路,还有些是学习方法上的弯路.在未查看这类官网文档之前,更多的是看其他各种人的博 ...

  3. QUICK START GUIDE

    QUICK START GUIDE This page is a guide aimed at helping anyone set up a cheap radio scanner based on ...

  4. Akka Stream文档翻译:Quick Start Guide: Reactive Tweets

    Quick Start Guide: Reactive Tweets 快速入门指南: Reactive Tweets (reactive tweets 大概可以理解为“响应式推文”,在此可以测试下GF ...

  5. RobotFramework 官方demo Quick Start Guide rst配置文件分析

    RobotFramework官方demo Quick Start Guide rst配置文件分析   by:授客 QQ:1033553122     博客:http://blog.sina.com.c ...

  6. RobotFramework RobotFramework官方demo Quick Start Guide浅析

    RobotFramework官方demo Quick Start Guide浅析   by:授客 QQ:1033553122     博客:http://blog.sina.com.cn/ishouk ...

  7. pax3 quick start guide

    pax3 quick start guide 外观图: 配置:1 * pax3 主机:2 * 吸嘴(一个平的,一个凸的):2 * 底盖(一个烟草的,一个烟膏的):3 * 过滤片:1 * USB充:1 ...

  8. [摘录]quarts:Quartz Quick Start Guide

    (Primarily authored by Dafydd James) Welcome to the QuickStart guide for Quartz. As you read this gu ...

  9. Quartz Quick Start Guide

    Welcome to the QuickStart guide for Quartz. As you read this guide, expect to see details of: Downlo ...

随机推荐

  1. Mybatis日志体系

    承接上一篇关于spring 5.x的日志体系,本篇看看Mybatis的日志体系及实现,Mybatis版本基于3.x. 关于mybatis的官方文档比较友好,分门别类,各有论述,如mybatis官方文档 ...

  2. Java核心技术第八章-泛型

    摘要 本文根据<Java核心技术 卷一>一书的第八章总结而成,部分文章摘抄书内,作为个人笔记. 文章不会过于深入,望读者参考便好. 为什么要使用泛型程序设计 泛型程序设计(Generic ...

  3. 微信浏览器跳转浏览器下载app解决方案

    新版本微信浏览器中,已禁用下载APP应用,只支持打开微信合作商APP下载,所以无法通过微信浏览器直接下载APP应用.列举微信浏览器下载APP的种解决方案: 方案:通过Url 跳转到手机默认浏览器,或者 ...

  4. Spring Boot2 系列教程(二十八)Spring Boot 整合 Session 共享

    这篇文章是松哥的原创,但是在第一次发布的时候,忘了标记原创,结果被好多号转发,导致我后来整理的时候自己没法标记原创了.写了几百篇原创技术干货了,有一两篇忘记标记原创进而造成的一点点小小损失也能接受,不 ...

  5. centos 7 MysSQL 5.7.23 源码安装

    MySQL 5.7.23 源码安装 CentOS 7 将默认数据库MySQL替换成了Mariadb. 这里会从系统的环境准备开始一步一步安装. 环境准备 系统版本 内核版本 IP地址 Centos 7 ...

  6. Objective-C (OC)

    1.OC  运行效率比较高,仅次于c.开发过程时,效率也比较高,不会次于java和C++: :表示继承 “{}”之间写字段或声明 }和@end之间写函数 import 相当于include 作用于和j ...

  7. Spring Cloud系列-Zuul网关集成JWT身份验证

    前言 这两三年项目中一直在使用比较流行的spring cloud框架,也算有一定积累,打算有时间就整理一些干货与大家分享. 本次分享zuul网关集成jwt身份验证 业务背景 项目开发少不了身份认证,j ...

  8. 谈谈.net对象生命周期

     不用程序员操心的堆 — 托管堆         程序在计算机上跑着,就难免会占用内存资源来存储在程序运行过程中的数据,我们按照内存资源的存取方式将内存划分为堆内存和栈内存.    栈内存,通常使用的 ...

  9. 整合多个maven工程时Spring配置加载JDBC问题

    问题叙述: 两个工程都通过JDBC访问mysql数据库,各自运行OK, 但合并成一个maven工程后,发现前一个工程访问数据库异常,貌似拿不到自己的DAO. 解决办法: 发现这两个工程的xml配置中, ...

  10. Apple Developer swift教程学习笔记

    https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson6. ...