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. su root

    1. 命令行方式 ansible zabbix_agents --become --become-method=su -K -m shell -a 'whoami' 2. 变量方式 [zabbix_a ...

  2. sqlalchemy 源码分析之create_engine引擎的创建

    引擎是sqlalchemy的核心,不管是 sql core 还是orm的使用都需要依赖引擎的创建,为此我们研究下,引擎是如何创建的. from sqlalchemy import create_eng ...

  3. Openlayers Projection导致经纬度颠倒问题

    问题: openlayers3调用TileWMS接口,实现Openlayers加载Geoserver转发的ArcGIS切片时,web墨卡托(wkid3857)没有问题,但是WGS84(wkid4326 ...

  4. 详解 PHP 中的三大经典模式

    单例模式 单例模式的含义: 作为对象的创建模式,单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统全局地提供这个实例.它不会创建实例副本,而是会向单例类内部存储的实例返回一个引用. 单例模式 ...

  5. python3 之 内置函数range()

    一.语法: range(stop) range(start,stop,step) start:计数从start开始,默认是从0开始.eg:range(5)等价于range(0,5) stop:计数到s ...

  6. webapi接口安全验证

    其实跟大多数网上的方法一样,在前端请求头里加token,后台通过拦截器处理token数据,然后两边对比,如果一样就能通过,不一样就返回无权限. 前端测试代码如下: @{ ViewBag.Title = ...

  7. C#学习笔记03--循环和一维数组

    一.循环(重点) 什么时候用循环? 想让一段代码执行多次, 这段代码可能不一样但是一定有一个规律. 1.while 循环 格式:  while(循环条件) { 循环执行的代码; } 循环的机制:  当 ...

  8. CNCF官方大使张磊:什么是云原生?

    作者|张磊 阿里云容器平台高级技术专家,CNCF 官方大使 编者说: 从 2015 年 Google 牵头成立 CNCF 以来,云原生技术开始进入公众的视线并取得快速的发展,到 2018 年包括 Go ...

  9. 纵论WebAssembly,JS在性能逆境下召唤强援

    webassembly的作用 webassembly是一种底层的二进制数据格式和一套可以操作这种数据的JS接口的统称.我们可以认为webassembly的范畴里包含两部分 wasm: 一种体积小.加载 ...

  10. 最小路径算法(Dijkstra算法和Floyd算法)

    1.单源点的最短路径问题:给定带权有向图G和源点v,求从v到G中其余各顶点的最短路径. 我们用一个例子来具体说明迪杰斯特拉算法的流程. 定义源点为 0,dist[i]为源点 0 到顶点 i 的最短路径 ...