0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

fireflyAIO-3288C主板ADC接口介紹

firefly ? 來源:firefly ? 作者:firefly ? 2019-12-16 15:27 ? 次閱讀
ADC 使用
前言

AIO-3288C 開發(fā)板上的 AD 接口分為:高速 ADC 流接口 (High-speed ADC Stream Interface)、溫度傳感器 (Temperature Sensor)、逐次逼近ADC (Successive Approximation Register)。本文主要介紹 ADC 的基本配置方法。 內(nèi)核采用工業(yè) I/O 子系統(tǒng)來控制 ADC,該子系統(tǒng)主要為 AD 轉(zhuǎn)換或者 DA 轉(zhuǎn)換的傳感器設(shè)計(jì)。 其相關(guān)數(shù)據(jù)結(jié)構(gòu)以及配置方法如下:

數(shù)據(jù)結(jié)構(gòu)
iio_channel 結(jié)構(gòu)體
struct iio_channel { struct iio_dev *indio_dev;//工業(yè) I/O設(shè)備 const struct iio_chan_spec *channel;//I/O通道 void *data; };
iio_dev 結(jié)構(gòu)體

該結(jié)構(gòu)體主要用于描述 IO 口所屬的設(shè)備,其具體定義如下:

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結(jié)構(gòu)體

該結(jié)構(gòu)體主要用于描述單個(gè)通道的屬性,具體定義如下:

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節(jié)點(diǎn)

AIO-3288C ADC的 DTS 節(jié)點(diǎn)在 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-aio-3288c.dts 文件中添加通道定義,并將其 status 改為 “okay” 即可:

&adc { status = "okay"; adc_test{ compatible = "rockchip,adc_test"; io-channels = ; }; };
在驅(qū)動文件中匹配 DTS 節(jié)點(diǎn)

在驅(qū)動文件中定義 of_device_id 結(jié)構(gòu)體數(shù)組:

static const struct of_device_id of_XXX_match[] = { { .compatible = "rockchip,adc_test" }, { /* Sentinel */ } };

將該結(jié)構(gòu)體數(shù)組填充到要使用 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 通道結(jié)構(gòu)體 chan = iio_channel_get(&pdev->dev, NULL); //獲取 IIO 通道結(jié)構(gòu)體

注:iio_channel_get 通過 probe 函數(shù)傳進(jìn)來的參數(shù) pdev 獲取 IIO 通道結(jié)構(gòu)體,probe 函數(shù)如下:

static int XXX_probe(struct platform_device *pdev);
讀取 AD 采集到的原始數(shù)據(jù)
int val,ret; ret = iio_read_channel_raw(chan, &val);

調(diào)用 iio_read_channel_raw 函數(shù)讀取 AD 采集的原始數(shù)據(jù)并存入 val 中。

計(jì)算采集到的電壓

使用標(biāo)準(zhǔn)電壓將 AD 轉(zhuǎn)換的值轉(zhuǎn)換為用戶所需要的電壓值。其計(jì)算公式如下:

Vref / (2^n-1) = Vresult / raw

注:

  • Vref 為標(biāo)準(zhǔn)電壓
  • n 為 AD 轉(zhuǎn)換的位數(shù)
  • Vresult 為用戶所需要的采集電壓
  • raw 為 AD 采集的原始數(shù)據(jù)

例如,標(biāo)準(zhǔn)電壓為 1.8V,AD 采集位數(shù)為 10 位,AD 采集到的原始數(shù)據(jù)為 568,則:

Vresult = (1800mv * 568) / 1023;
ADC 常用函數(shù)接口
struct iio_channel *iio_channel_get(struct device *dev, const char *consumer_channel);
  • 功能:獲取 iio 通道描述
  • 參數(shù):
    • dev: 使用該通道的設(shè)備描述指針
    • consumer_channel: 該設(shè)備所使用的 IIO 通道描述指針
void iio_channel_release(struct iio_channel *chan);
  • 功能:釋放 iio_channel_get 函數(shù)獲取到的通道
  • 參數(shù):
    • chan:要被釋放的通道描述指針
int iio_read_channel_raw(struct iio_channel *chan, int *val);
  • 功能:讀取 chan 通道 AD 采集的原始數(shù)據(jù)。
  • 參數(shù):
    • chan:要讀取的采集通道指針
    • val:存放讀取結(jié)果的指針

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • 嵌入式主板
    +關(guān)注

    關(guān)注

    7

    文章

    6081

    瀏覽量

    34936
  • Firefly
    +關(guān)注

    關(guān)注

    2

    文章

    538

    瀏覽量

    6929
收藏 人收藏

    評論

    相關(guān)推薦

    fireflyAIO-3288C主板安裝指導(dǎo)

    AIO-3288C 的標(biāo)準(zhǔn)套裝包含以下配件
    的頭像 發(fā)表于 11-05 15:58 ?1316次閱讀
    <b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>安裝指導(dǎo)

    fireflyAIO-3399C主板ADC介紹

    AIO-3399C 開發(fā)板上的 AD 接口有兩種,分別為:溫度傳感器 (Temperature Sensor)、逐次逼近ADC (Successive Approximation Register)。
    的頭像 發(fā)表于 12-13 10:14 ?1338次閱讀

    fireflyAIO-3288C主板接口簡介

    firefly
    的頭像 發(fā)表于 12-16 13:48 ?1686次閱讀
    <b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b><b class='flag-5'>接口</b>簡介

    fireflyAIO-3288C主板SPI接口簡介

    SPI是一種高速的,全雙工,同步串行通信接口,用于連接微控制器、傳感器、存儲設(shè)備等,本文以指紋識別模塊為例簡單介紹SPI使用。
    的頭像 發(fā)表于 12-16 14:11 ?1160次閱讀
    <b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>SPI<b class='flag-5'>接口</b>簡介

    fireflyAIO-3288C PWM 輸出介紹

    AIO-3288C 開發(fā)板上有 4 路 PWM 輸出,分別為 PWM0 ~ PWM3, 本章主要描述如何配置 PWM。
    的頭像 發(fā)表于 12-16 15:22 ?1281次閱讀

    fireflyAIO-3288C主板MIPI CSI攝像頭接口簡介

    AIO-3288C開發(fā)板有雙 MIPI 攝像頭接口,攝像頭圖像處理能力達(dá)到 4416x3312 像素,支持 4K 視頻錄制。此外,開發(fā)板還支持 USB 攝像頭。
    的頭像 發(fā)表于 12-16 14:16 ?5850次閱讀
    <b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>MIPI CSI攝像頭<b class='flag-5'>接口</b>簡介

    fireflyAIO-3288C主板IR 簡介

    AIO-3288C 開發(fā)板上可以接紅外收發(fā)傳感器 IR 實(shí)現(xiàn)遙控功能。
    的頭像 發(fā)表于 12-16 14:22 ?1393次閱讀
    <b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>IR 簡介

    fireflyAIO-3288C主板I2C簡介

    AIO-3288C 開發(fā)板上有 6 個(gè)片上 I2C 控制器。
    的頭像 發(fā)表于 12-16 14:23 ?1266次閱讀

    fireflyAIO-3288C主板ADB調(diào)試工具介紹

    adb,全稱 Android Debug Bridge,是 Android 的命令行調(diào)試工具,可以完成多種功能,如跟蹤系統(tǒng)日志,上傳下載文件,安裝應(yīng)用等。
    的頭像 發(fā)表于 12-16 14:58 ?1658次閱讀
    <b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>ADB調(diào)試工具<b class='flag-5'>介紹</b>

    fireflyAIO-3288C主板編譯Buildroot固件簡介

    本章介紹 Buildroot 固件的編譯使用。
    的頭像 發(fā)表于 12-16 14:55 ?1404次閱讀

    fireflyAIO-3288C主板啟動模式簡介

    AIO-3288C 有靈活的啟動方式。
    的頭像 發(fā)表于 12-16 15:43 ?1316次閱讀
    <b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>啟動模式簡介

    fireflyAIO-3288J主板LED介紹

    AIO-3288J 開發(fā)板上有 2 個(gè) LED 燈,
    的頭像 發(fā)表于 12-20 09:48 ?1914次閱讀

    fireflyAIO-3288J主板IR使用介紹

    IR 使用 紅外遙控配置 AIO-3288J 開發(fā)板上可以接紅外收發(fā)傳感器 IR 實(shí)現(xiàn)遙控功能。
    的頭像 發(fā)表于 12-20 10:02 ?1744次閱讀
    <b class='flag-5'>fireflyAIO-3288</b>J<b class='flag-5'>主板</b>IR使用<b class='flag-5'>介紹</b>

    fireflyAIO-3288J主板I2C簡介

    AIO-3288J 開發(fā)板上有 6 個(gè)片上 I2C 控制器。
    的頭像 發(fā)表于 12-20 10:05 ?1237次閱讀

    fireflyAIO-3288J主板ADC使用簡介

    AIO-3288J 開發(fā)板上的 AD 接口分為:高速 ADC接口 (High-speed ADC Stream Interface)、溫
    的頭像 發(fā)表于 12-26 14:34 ?1666次閱讀