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. MySQL 5.7 - 通过 BINLOG 恢复数据

    日常开发,运维中,经常会出现误删数据的情况.误删数据的类型大致可分为以下几类: 使用 delete 误删行 使用 drop table 或 truncate table 误删表 使用 drop dat ...

  2. Running serveral https server on a single IP address

    Nginx 在一个IP上配置多个https server时,默认只会发送默认server name的证书.这是由ssl 协议本身行为导致的:先建立ssl connection,后发送http请求.即n ...

  3. 从无到有实现搭建vue+ElementUI+less+ES6的开发环境并进行简单的开发的项目

    项目简介:该项目是基于日常计算宿舍水电煤气费的需求写的,旨在从无到有实现搭建vue+ElementUI+less+ES6的开发环境并进行简单的开发,使用webpack进行代码的编译.压缩和打包,并疏通 ...

  4. 安卓Android碎片fragment实现静态加载

    静态加载好后的界面如下,两个碎片分别位于一个活动的左边和右边: 左边和右边分别为一个碎片,这两个碎片正好将一整个活动布满.一个活动当中可以拥有多个碎片,碎片的含义就是可以在同一个UI界面下,将这个界面 ...

  5. Few-shot Object Detection via Feature Reweighting (ICCV2019)

    论文:https://arxiv.org/abs/1812.01866 代码:https://github.com/bingykang/Fewshot_Detection 1.研究背景 深度卷积神经网 ...

  6. 2019-9-20:渗透测试,基础学习,笔记,metasploit的基础使用

    使用kali下metasploit生成木马,控制windows系统 kali基于debin的数字取证系统,上面集成了很多渗透测试工具,前身为bt r3(BrackTrack) Metasploit,是 ...

  7. 【Luogu P1714】切蛋糕(面向对象编程首次尝试?)

    Luogu P1714 题目的大意就是给定一个长度为n的序列,求出这个序列中长度不超过m的子串的最大和 很容易想出的一个解法就是枚举起点终点,直接暴力扫一遍得出答案. 当然也很容易发现这种做法肯定会T ...

  8. C#Windows Forms 计算器--xdd

    一.计算器 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data ...

  9. (四十五)golang--反射

    反射基本介绍: (1)反射可以在运行时动态获取变量的各种信息,比如变量的类型.类别: (2)如果是结构体变量,还可以获取结构体本身的信息(包括结构体字段.方法): (3)通过反射,可以修改变量的值,可 ...

  10. Spring Boot整合Mybatis报错InstantiationException: tk.mybatis.mapper.provider.base.BaseSelectProvider

    Spring Boot整合Mybatis时一直报错 后来发现原来主配置类上的MapperScan导错了包 由于我使用了通用Mapper,所以应该导入通用mapper这个包