ADC 挑戦

とりあえず、VOUTの3.3VをAnalogIn の20ピンに接続して、この電圧を測ってみる。
計測した電圧は、シリアル通信でパソコンに送る。

VOUT を P20 に接続する。
/media/uploads/yamato/006.png

include the mbed library with this snippet

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx
AnalogIn ain(p20);

int main()
{
    float v;
    while (1) {
        v = ain.read() * 3.3;
        pc.printf("v=%4.1f \r\n" ,v);
        wait(1.0f);
    }
}


表示結果
/media/uploads/yamato/007.png

mbedのADコンバータはアナログ入力0~3.3Vを、0~1.0に変換するそうです。

このままでは、面白くないので、AnalogOut で出力した電圧を測ってみる。
18ピンと20ピンを繋げる。

include the mbed library with this snippet

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx
AnalogIn AD(p20);
AnalogOut DA(p18);

int main()
{
    for (float i=0.0; i<1.0; i+=0.1) {
        DA = i;
        wait(0.5);
        pc.printf("AD out %0.1fV \r\n", AD.read()*3.3);
    }
}


/media/uploads/yamato/008.png


Please log in to post comments.