電圧計&電流計アダプタ

自作を含め多数の電源装置を持っています。
しかし電圧計や電流計等のメータは、結構高価なので装置に取り付けてあるものは少ないです。
そこで電源装置の出力に接続可能な“電圧計&電流計アダプタ“なるものを製作してみました。

特に難しい動作ではありませんが、次のような点がポイントとなります。

  • A/D変換の精度を上げるために、2.5Vの基準電圧をTL431(プログラマブル・シャント・レギュレータ)を使用しました。
  • 測定可能な電圧は、0V~25V迄とする。<正確には、27.5V(2.5V×11)>
  • 測定可能な電流は、0mA~2A迄とする。<正確には、2.27A(2.5V÷11÷0.1Ω)>
  • 電流表示は、アナログ的にも分かりやすいようにバー表示もさせる。

<TL431>

viMeter.c
//********************************************************************** 
/*
  『電圧&電流計』 
*/
//********************************************************************** 
 
unsigned	int	measurement(unsigned short channel)
{
	unsigned	int		ad, cnt;
	//
	ad = 0;
	for (cnt = 0; cnt < 50; cnt++) {
		ad += Adc_Read(channel);
	}
	return (ad);
}
 
//********************************************************************** 
 
void main()
{
	static	unsigned	char	buf[8], cnt;
	static	unsigned	int		v1, v2, i1;
	static	double					ad, offset;
	//
	OSCCON = 0b01110000;		// クロックは8Mhz 
	CMCON  = 0b00000111;		// コンパレータは使用しない。
	// A/D変換を使用する。 
	ANSEL  = 0b00000110;
	ADCON1.VCFG1 = 1;
	ADCON1.VCFG0 = 0;
	// ポートを初期化する。 
	TRISA  = 0b00111110;
	TRISB  = 0b00001111;
	// LCDを初期化する。 
	Lcd_Custom_Config(&PORTB,4,5,6,7,&PORTA,0,7,6);
	Lcd_Custom_Cmd(LCD_CURSOR_OFF);
	Lcd_Custom_Cmd(LCD_CLEAR);
//	Lcd_Custom_Out(1, 1, "V&I Meter V1.0");
//	Delay_ms(500);
//	Lcd_Custom_Cmd(LCD_CLEAR);
	//
	offset = 0.0;
	//
	while (1) {
		// 電圧の測定 
		ad = 0.0;
		for (cnt = 0; cnt < 10; cnt++) {
			ad += measurement(1);
		}
		ad = (ad / 500.0) * 2.44140625 * 11.0;
		ad = ad - offset;
		v1 = (unsigned int)(ad);
		v2 = (unsigned int)(ad / 100.0);
		if ((v1 - (v2 * 100)) >= 50)
			v2++;
		// 電圧の表示 
		WordToStr(v2, buf);
		buf[6] = 0x00;
		buf[5] = buf[4];
		buf[4] = '.';
		Lcd_Custom_Out(1, 1, buf);
		Lcd_Custom_Out(1, 7, "V");
		// 電流の測定 
		ad = 0.0;
		for (cnt = 0; cnt < 10; cnt++) {
			ad += measurement(2);
		}
		ad = (ad / 500.0) * 2.44140625 / 11.0;
		offset = ad;
		i1 = (unsigned int)(ad * 10.0);
		// 電流の表示 
		WordToStr(i1, buf);
		Lcd_Custom_Out(1, 9, buf);
		Lcd_Custom_Out(1, 14, "mA");
		//
		buf[0] = 0xFF;
		buf[1] = 0x00;
		for (cnt = 1; cnt <= 16; cnt++) {
			if ((i1 / (62 * cnt)) == 0)
				break;
			Lcd_Custom_Out(2, cnt, buf);
		}
		for (; cnt <= 16; cnt++) {
			Lcd_Custom_Out(2, cnt, " ");
		}
	}
}
 
//**********************************************************************




著作権表示 copyright notice

このページは稲崎様の閉鎖したHPのコピーで、著作権は稲崎様にあります。詳細
This page is a copy of Mr. Inasaki's closed website, and the copyright is held by him.Details
  • elechobby/picdic/pic16f88/75.txt
  • 最終更新: 2025/10/17 14:29
  • by 127.0.0.1