デジタル電圧計
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2021/11/10 02:00 UTC 版)
ここでは汎用の16bit ADCを例にあげ解説する。IC内部には入力マルチプレクサ(MUX)、プログラマブルゲインアンプ(PGA)、アナログ-デジタル変換回路(ADC)とそれらを制御しマイコン(MCU)などとの通信をつかさどる制御通信部からなる。下記にMCUによる電圧値取得の例を書く。ピンの割り当てやリファレンス電圧、PGAの設定、サンプルレートなどを指定した後に電圧値を1秒ごとにコンピュータに送信するソフトウェアである。 SPI spi(p5, p6, p7); // mosi(out), miso(in), sclk(clock)DigitalOut cs(p8); // cs (the chip select signal)Serial pc(USBTX, USBRX); int main() { spi.format(8,1); //(bits, mode) (mode1 (CPOL=0, CPHA=1) spi.frequency(1000000); //1MHz wait_ms(20);//Delay for minimum of 16ms to allow power supplies to settle and power-on reset to complete. cs = 0;// Select the device by seting chip select low wait_ms(1);//Delay for minimum of tsccs(=10ns) spi.write(0x06);//reset wait_ms(1);//Delay for minimum of 0.6ms spi.write(0x16);//SDATAC: Stop read data continuous mode. wait_ms(1); //WREG: Write to register rrrr spi.write(0x40);//WREG, MUX0 spi.write(0x00);// spi.write(0x01);//AIN0 = + , AIN1 = - wait_ms(1); spi.write(0x42);//System Control Register0 spi.write(0x00);// spi.write(0x30);//Internal Reference is always on. & Internal Reference selected. wait_ms(1); spi.write(0x43);//System Control Register0 spi.write(0x00);// spi.write(0x12);//PGA=2, Data Output Rate = 20SPS wait_ms(1); spi.write(0x04);//SYNC: Synchronize ADC conversions. wait_ms(1); cs = 1; while(1) { cs = 0; spi.write(0x12);//RDATA: Read data once. wait_ms(1); unsigned char Volt_hex1 = spi.write(0xff); unsigned char Volt_hex2 = spi.write(0xff); unsigned short Volt_hex = (Volt_hex1 << 8) | Volt_hex2; float Volt = (float)Volt_hex / 0x7fff; //0 ~ 1.024V cs= 1; pc.printf("%f\r", Volt); wait(1); }} 表示部をLCDや7セグメントディスプレイに置き換えればデジタルパネルメータとして仕上げることも可能になる。
※この「デジタル電圧計」の解説は、「電圧計」の解説の一部です。
「デジタル電圧計」を含む「電圧計」の記事については、「電圧計」の概要を参照ください。
- デジタル電圧計のページへのリンク