Chinaunix首页 | 论坛 | 博客
  • 博客访问: 78366
  • 博文数量: 63
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 14
  • 用 户 组: 普通用户
  • 注册时间: 2018-09-15 14:26
文章分类

全部博文(63)

文章存档

2018年(63)

我的朋友

分类: 嵌入式

2018-09-15 14:31:34

原文地址:Cortex_A9----ADC 作者:小米拍客光

ADC实验
一、看原理图,找到电位器接AD的通道3
二、看芯片手册
   ADCCON
   RES  [16]: 1 = 12bit A/D conversion
   ECFLG[15]: 0 = A/D conversion in process
   1 = End of A/D conversion
   PRSCEN  [14]: 1 = Enable
   PRSCVL  [13:6]:0xff
   STANDBY  [2]: 0 = Normal operation mode
   READ_START [1]: A/D conversion start by read
   0 = Disables start by read operation
   1 = Enables start by read operation  
   ENABLE_ST ART [0] : 0 = No operation
   1 = A/D conversion starts and this bit is automatically clearedafter the start-up.

    ADCDAT
    DATA [11:0]: ADC conversion data value Data value: 0x0 ~ 0xFFF
 
    ADCMUX
    SEL_MUX  [3:0]: 0011 = AIN 3





  1. #include "exynos_4412.h"

  2. void adc_init()
  3. {
  4.         printf("\n************ ADC Converter Value ************\n");
  5.         /***通道选择:3****/
  6.         ADCMUX = ADCMUX & (~(0xF << 0)) | (0x3 << 0);
  7.         /**
  8.         * 寄存器配置方式1
  9.         * ADCCON = (0x1 << 16) | (0x1 << 14) | (0xff << 6);
  10.         */
  11.         /***12位转换精度***/
  12.         ADCCON = ADCCON & (~(0x1 << 16)) | (0x1 << 16);
  13.         /***使能预分频***/
  14.         ADCCON = ADCCON & (~(0x1 << 14)) | (0x1 << 14);
  15.         /*** AD是时钟频率100M/(19+1) = 5M ***/
  16.         ADCCON = ADCCON & (~(0xFF << 6)) | (0x13 << 6);
  17.         /***正常模式 关闭待机****/
  18.         ADCCON = ADCCON & (~(0x1 << 2));

  19.         /**
  20.         * 寄存器配置方式2
  21.         */
  22.         //    ADCCON = (0x1<<16) | (0x1<<14) | (0xff<<6) | 0x1<<1;
  23.         //    必须先读一次寄存器的值,才能激活AD
  24.         //    temp_adc = ADCDAT & 0xFFF;
  25.         return ;
  26. }

  27. void adc_Converter_Value ()
  28. {
  29.         unsigned int temp_adc = 0;
  30.         unsigned int temp_mv = 0;
  31.         while (1)
  32.         {
  33.                 /***打开AD开始转换***/
  34.                 ADCCON = ADCCON & (~(0x1 << 0)) | (0x1 << 0);
  35.                 delay_ms(10);
  36.                 /***等待转换完成***/
  37.                 while (!(ADCCON & (1 << 15)))
  38.                 ;
  39.                 /***读取转换结果***/
  40.                 temp_adc = ADCDAT & 0xFFF;

  41.                 /***将读出来的数据进行格式转换 ***/
  42.                 /*(精度是12位,所以是4096,单位mV,提高准确性)*/
  43.                 temp_mv = 1800 * temp_adc / 4096;

  44.                 printf("adc value: %d mv\n", temp_mv);
  45.                 delay_ms(1000);
  46.         }
  47. }








阅读(748) | 评论(0) | 转发(0) |
0

上一篇:Cortex_A9----PWM

下一篇:Cortex_A9----UART

给主人留下些什么吧!~~