Firefly-RK328开发板ADC接口介绍

adc 使用 前言 firefly-rk3288 开发板上的 ad 接口分为:高速 adc 流接口 (high-speed adc stream interface)、温度传感器 (temperature sensor)、 逐次逼近adc (successive approximation register)。本文主要介绍 adc 的基本配置方法。内核采用工业 i/o 子系统来控制 adc, 该子系统主要为 ad 转换或者 da 转换的传感器设计。其相关数据结构以及配置方法如下:
数据结构 iio_channel 结构体 struct iio_channel { struct iio_dev *indio_dev;//工业 i/o设备 const struct iio_chan_spec *channel;//i/o通道 void *data; };
iio_dev 结构体 该结构体主要用于描述 io 口所属的设备,其具体定义如下: struct iio_dev { int id; int modes; int currentmode; struct device dev; struct iio_event_interface *event_interface; struct iio_buffer *buffer; struct list_head buffer_list; int scan_bytes; struct mutex mlock; const unsigned long *available_scan_masks; unsigned masklength; const unsigned long *active_scan_mask; bool scan_timestamp; unsigned scan_index_timestamp; struct iio_trigger *trig; struct iio_poll_func *pollfunc; struct iio_chan_spec const *channels; int num_channels; struct list_head channel_attr_list; struct attribute_group chan_attr_group; const char *name; const struct iio_info *info; struct mutex info_exist_lock; const struct iio_buffer_setup_ops *setup_ops; struct cdev chrdev; #define iio_max_groups 6 const struct attribute_group *groups[iio_max_groups + 1]; int groupcounter; unsigned long flags; #if defined(config_debug_fs) struct dentry *debugfs_dentry; unsigned cached_reg_addr; #endif };
iio_chan_spec结构体 struct iio_chan_spec { enum iio_chan_type type; //描述通道类型 int channel; //通道号 int channel2; //通道号 unsigned long address; //通道地址 int scan_index; struct { char sign; u8 realbits; u8 storagebits; u8 shift; enum iio_endian endianness; } scan_type; long info_mask; long info_mask_separate; long info_mask_shared_by_type; long event_mask; const struct iio_chan_spec_ext_info *ext_info; const char *extend_name; const char *datasheet_name; unsigned modified:1; unsigned indexed:1; unsigned output:1; unsigned differential:1; };
配置步骤 配置dts节点 firefly adc的 dts 节点在 kernel/arch/arm/boot/dts/rk3288.dtsi 文件中定义,如下所示:
adc: adc@ff100000 { compatible = rockchip,saradc; reg = ; interrupts = ; #io-channel-cells = ; io-channel-ranges;rockchip,adc-vref = ; clock-frequency = ; clocks = , ; clock-names = saradc, pclk_saradc; status = disabled; };
用户只需在 firefly-rk3288.dts 文件中添加通道定义,并将其 status 改为 “okay” 即可:
&adc { status = okay; adc_test{ compatible = rockchip,adc_test; io-channels = ; }; };
在驱动文件中匹配 dts 节点 在驱动文件中定义 of_device_id 结构体数组:
static const struct of_device_id of_xxx_match[] = { { .compatible = rockchip,adc_test }, { /* sentinel */ } };
将该结构体数组填充到要使用 adc 的 platform_driver 中。
static struct platform_driver xxx_driver = { .probe = ..., .remove = ..., .driver = { .name = .., .owner = this_module, #ifdef config_of .of_match_table = of_xxx_match, #endif }, };
获取 ad 通道 struct iio_channel *chan; //定义 iio 通道结构体 chan = iio_channel_get(&pdev->dev, null); //获取 iio 通道结构体
注:iio_channel_get 通过 probe 函数传进来的参数 pdev 获取 iio 通道结构体,probe 函数如下:
static int xxx_probe(struct platform_device *pdev);
读取 ad 采集到的原始数据 int val,ret; ret = iio_read_channel_raw(chan, &val);
调用 iio_read_channel_raw 函数读取 ad 采集的原始数据并存入 val 中。
计算采集到的电压 使用标准电压将 ad 转换的值转换为用户所需要的电压值。其计算公式如下:
vref / (2^n-1) = vresult / raw
注: vref 为标准电压 n 为 ad 转换的位数 vresult 为用户所需要的采集电压 raw 为 ad 采集的原始数据 例如,标准电压为 1.8v,ad 采集位数为 10 位,ad 采集到的原始数据为 568,则:
vresult = (1800mv * 568) / 1023;
adc 常用函数接口 struct iio_channel *iio_channel_get(struct device *dev, const char *consumer_channel);
功能:获取 iio 通道描述 参数: dev: 使用该通道的设备描述指针 consumer_channel: 该设备所使用的 iio 通道描述指针 void iio_channel_release(struct iio_channel *chan);
功能:释放 iio_channel_get 函数获取到的通道 参数: chan:要被释放的通道描述指针 int iio_read_channel_raw(struct iio_channel *chan, int *val);
功能:读取 chan 通道 ad 采集的原始数据 参数: chan:要读取的采集通道指针 val:存放读取结果的指针

Rail Splitter, from Abraham Li
Type-C将成为行业趋势,未来Type-C将会统一手机界
预计到2025-2027年消费者购买A00电动车就可以比燃油车更划算
什么是亲密ITM加密货币
中国移动上半年业绩成本增加107亿,证明5G基站耗电量惊人
Firefly-RK328开发板ADC接口介绍
相敏检波器实验
碳化硅电源的设计注意事项
Gartner发布2024年十大战略技术趋势
法大大入选DSSC认证企业名单
柜机出现小e6故障到底怎么回事?
工业以太网交换机有哪些选购标准?
锂电池还不够小不够好,借助3D打印技术来解决
无线传输技术将决定未来VR的市场走向
多家跨国企业选择亚马逊云科技,加速生成式AI落地与本地化创新
盘点几种深度学习库
边界扫描测试技术的原理解析
MPS FAE谢建宇:汽车DCDC芯片EMC设计三要素和抑制措施
中国电信:突破关键核心技术,勇当科技创新主力军
金升阳推出HO5系列负离子发生器,家电界的强力装备