• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SARADC概述
2
3## 简介
4
5- 逐次逼近寄存器型模数转换器(Successive-Approximation Analog to Digital Converter),是一种常用的A/D转换结构,其较低的功耗表现,还不错的转换速率,在有低功耗要求(可穿戴设备、物联网)的数据采集场景下广泛应用。
6
7## 接口说明
8
9### 包含头文件:
10
11```c
12#include "lz_hardware.h
13```
14
15#### 1. SARADC设备初始化接口
16
17```c
18int LzSaradcInit(void);
191) 参数说明:
20212) 返回值:
22   成功返回LZ_HARDWARE_SUCCESS, 出错返回错误码
23```
24
25#### 2. SARADC设备释放接口
26
27```c
28int LzSaradcDeinit(void);
291) 参数说明:
30312) 返回值:
32   成功返回LZ_HARDWARE_SUCCESS, 出错返回错误码
33```
34
35#### 3. SARADC设备读取接口:
36
37```c
38int LzSaradcReadValue(unsigned int chn, unsigned int *val);
391) 参数说明:
40   chn:  ADC通道id
41   val:  读取值
422) 返回值:
43   成功返回LZ_HARDWARE_SUCCESS, 出错返回错误码
44```
45
46## 使用实例
47
48```c
49#include "lz_hardware.h"
50
51#define ADC_CHNN 5
52
53DevIo g_adckey = {
54    .isr =   {.gpio = INVALID_GPIO},
55    .rst =   {.gpio = INVALID_GPIO},
56    .ctrl1 = {.gpio = GPIO0_PC5, .func = MUX_FUNC1, .type = PULL_NONE, .drv = DRIVE_KEEP, .dir = GPIO_DIR_IN, .val = LZGPIO_LEVEL_KEEP},
57    .ctrl2 = {.gpio = INVALID_GPIO},
58};
59
60unsigned int adc_sample()
61{
62    unsigned int ret = LZ_HARDWARE_SUCCESS;
63    uint32_t keyValue;
64
65    //初始化adc
66    if (DevIoInit(g_adckey) != LZ_HARDWARE_SUCCESS)
67        return LZ_HARDWARE_FAILURE;
68    if (LzSaradcInit() != LZ_HARDWARE_SUCCESS)
69        return LZ_HARDWARE_FAILURE;
70
71    if (LzSaradcReadValue(ADC_CHNN, &keyValue) != LZ_HARDWARE_SUCCESS){
72        return LZ_HARDWARE_FAILURE;
73    }
74
75    if (LzSaradcDeinit() != LZ_HARDWARE_SUCCESS)
76        return LZ_HARDWARE_FAILURE;
77
78    return LZ_HARDWARE_SUCCESS;
79}
80```
81