Difference between revisions of "Matrix - Analog to Digital Converter/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(Replaced content with "English")
Line 1: Line 1:
 
[[Matrix - Analog to Digital Converter|English]]
 
[[Matrix - Analog to Digital Converter|English]]
 +
 +
==介绍==
 +
[[File:ADC.png|thumb|Analog to Digital Converter]]
 +
我们把一颗SOIC-16封装的PFC8591T芯片放到一块小PCB上,并通过2.54mm排针引出了必要的信号。PFC8591T是NXP的一款I2C接口的8位A/D和D/A转换器,包含4路A/D通道和1路D/A通道。我们引出了PFC8591T的电源、地、I2C,4路A/D通道和1路D/A通道的相应引脚。I2C地址被配置为1001000x,参考电压跟电源电压一样,即采集范围是地到电源。PFC8591T电源输入范围是2.5V-6.0V。2.54mm排针中的5V是电源输入脚,但是如果您需要采集0-3.3V的模拟信号,而又不想降低采集精度,可以把电源输入改为3.3V。
 +
 +
==特性==
 +
* 宽电源电压输入,2.5V-6.0V
 +
* I2C接口,3.3V/5V
 +
* 8-bit A/D x4
 +
* 8-bit D/A x1
 +
* 体积小巧, 带固定孔,方便嵌入到外壳
 +
* 2.54mm排针接口,接线方便,通用性强
 +
 +
==使用方法==
 +
===连接===
 +
*连接到Tiny4412 SDK (1506)
 +
::VCC接5V,G接地
 +
::SDA接I2C SDA
 +
::SCL接I2C SCL
 +
 +
===Linux下的C示例===
 +
<syntaxhighlight lang="c">
 +
#include <stdio.h>
 +
#include <sys/types.h>
 +
#include <sys/stat.h>
 +
#include <fcntl.h>
 +
#include <unistd.h>
 +
#include "libfahw.h"
 +
 +
int main(int argc, char ** argv)
 +
{
 +
    int devFD;
 +
    int data, channel, mode;
 +
 +
    if ((devFD = pcf8591Init()) == -1) {
 +
        printf("Fail to init pcf8591\n");
 +
        return -1;
 +
    }
 +
 +
    if (pcf8591SetCtrl(devFD, PCF8591_INIT_AD_CONTROL) == -1) {
 +
        printf("Fail to Set pcf8591 control AD\n");
 +
        pcf8591DeInit(devFD);
 +
        return -1;
 +
    }
 +
    mode = 0;
 +
    printf("pcf8591 working as AD in mode%d\n",mode);
 +
    for(channel = PCF8591_AIN_CHANNEL0;channel <= PCF8591_AIN_CHANNEL3; channel++) {
 +
        data = pcf8591Read(devFD, mode, channel);
 +
        printf("Channel%d's value: %d\n",channel,data);
 +
    }
 +
    pcf8591DeInit(devFD);
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
 +
===编译并运行示例===
 +
<syntaxhighlight lang="bash">
 +
git clone http://github.com/friendlyarm/fa-hardware.git
 +
cd fa-hardware
 +
cd demo/matrix-analog_to_digital_converter
 +
make
 +
</syntaxhighlight>
 +
将编译生成的pcf8591通过ftp上传到开发板上运行即可测试。
 +
 +
==相关资料==

Revision as of 08:59, 5 August 2015

English

1 介绍

Analog to Digital Converter

我们把一颗SOIC-16封装的PFC8591T芯片放到一块小PCB上,并通过2.54mm排针引出了必要的信号。PFC8591T是NXP的一款I2C接口的8位A/D和D/A转换器,包含4路A/D通道和1路D/A通道。我们引出了PFC8591T的电源、地、I2C,4路A/D通道和1路D/A通道的相应引脚。I2C地址被配置为1001000x,参考电压跟电源电压一样,即采集范围是地到电源。PFC8591T电源输入范围是2.5V-6.0V。2.54mm排针中的5V是电源输入脚,但是如果您需要采集0-3.3V的模拟信号,而又不想降低采集精度,可以把电源输入改为3.3V。

2 特性

  • 宽电源电压输入,2.5V-6.0V
  • I2C接口,3.3V/5V
  • 8-bit A/D x4
  • 8-bit D/A x1
  • 体积小巧, 带固定孔,方便嵌入到外壳
  • 2.54mm排针接口,接线方便,通用性强

3 使用方法

3.1 连接

  • 连接到Tiny4412 SDK (1506)
VCC接5V,G接地
SDA接I2C SDA
SCL接I2C SCL

3.2 Linux下的C示例

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "libfahw.h"
 
int main(int argc, char ** argv)
{
    int devFD;
    int data, channel, mode;
 
    if ((devFD = pcf8591Init()) == -1) {
        printf("Fail to init pcf8591\n");
        return -1;
    }
 
    if (pcf8591SetCtrl(devFD, PCF8591_INIT_AD_CONTROL) == -1) {
        printf("Fail to Set pcf8591 control AD\n");
        pcf8591DeInit(devFD);
        return -1;
    }
    mode = 0;
    printf("pcf8591 working as AD in mode%d\n",mode);
    for(channel = PCF8591_AIN_CHANNEL0;channel <= PCF8591_AIN_CHANNEL3; channel++) {
        data = pcf8591Read(devFD, mode, channel);
        printf("Channel%d's value: %d\n",channel,data);
    }
    pcf8591DeInit(devFD);
    return 0;
}

3.3 编译并运行示例

git clone http://github.com/friendlyarm/fa-hardware.git
cd fa-hardware
cd demo/matrix-analog_to_digital_converter
make

将编译生成的pcf8591通过ftp上传到开发板上运行即可测试。

4 相关资料