nobcha23の日記

PICマイコンやArduinoを使う電子回路遊びを紹介します

LCメーターのARDUINO移植するには周波数カウンタ機能が必要

ARDUINOを久しぶりに触ったので、何か達成感のある試作に取り組むこととにしました。 I would like to try a cirtain trial to be used Arduino.

 

以前LCメーターをPICで作りましたが、これをARDUINOに移植しようかと考えています。 There is just idea to make up LC meter which I tried ever.

LCメーターのポイントは
1.フランクリン発振器でLC回路の発振をさせる。周波数を観測する。

2.基準コンデンサによるキャリブレーションの後、被測定LあるいはCをタンク回路に追加し発振させ、周波数を観測する。リレーによるLC切り替えが必要。

3. 基準回路発振周波数と被測定L/C追加後の発振周波数を基準Cの3つの数値からLあるいはCの値を求める連立方程式を解く。

I shall list up the LC meter principle which I made up along with the franclin oscilator method.

1. To make up the Franclin oscilator circuit. To check the frequency for it.

2. At first, caliblation oscillation by standard capacitor and secondly putting the test part on to measure the frequency.

3. To resolve the corelational equations from the two frequencies and the standard capacitor value.

 


以上のような原理からARDUINO移植にはまずは周波数カウンタが必要となります。

そこで、Arudinoで周波数カウンターを作れないかと考えググってみましたら、ありました。

To make the LC meter up in the Arduino world, I should utilize the frequency counter on it. There are many examples in the Arduion world.

Arudinoらしくライブラリがいくつか存在しています。感謝感謝!そのうち取り扱いが易しそうな次のライブラリーを引用します。

I adopted the easy one as below.

サンプルコード(FreqCount_2017-0207-001-ok)

日本ではこちらの方で先輩が引用されています。
Arudinoで周波数カウンター① Arudino
実験 2017/02/0720:02 - -


また、LCメーターでは表示にi2c液晶を使おうと思っています。i2c液晶関数ではprintf機能がないので、標準関数sprintf()でバイナリーを文字列変換しました。

 

それで次のようなスケッチで動きました。

The sketch is as below.

>|| はてなダイアリーのつもりではてな記法で書いてしまいました。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
// 2020.06.25 次のライブラリーを参照しました。ご協力感謝します。
// サンプルコード(FreqCount_2017-0207-001-ok)
// "http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-frequency-counter-library/"

#include <FreqCounter.h>
#include <Wire.h>
#include <skI2CLCDlib.h>

int pinLed = 3; // Gate点滅LEDのポート
int LED_Stat = 1; // Gate点滅LEDの状態

//lcd instance
skI2CLCDlib LCD(0x3E, 16); // LCDのi2cアドレス、画面カラム数16文字

void setup() {
Serial.begin(9600); // connect to the serial port
Serial.println("Frequency Counter");
pinMode(pinLed, OUTPUT);
// LCDモジュールの初期化処理
// ICON OFF,コントラスト(0-63),VDD=5Vで使う
LCD.Init(LCD_NOT_ICON,32,LCD_VDD5V) ; //5Vへ変更20200612
// 書き込む
LCD.SetCursor(0,0) ; // 表示位置を1行目1列[00H]に設定
LCD.Puts("FrequencyCounter") ; // [00H]から書込まれる(表示する)
LCD.SetCursor(0,1) ; // 表示位置を2行目1列[40H]に設定
LCD.Puts(" i2cLCDv1.0 ") ; // [40H]から書込まれる(表示する)

}

long int freq;
unsigned char charbuf[10]; // sprintf関数変換時に使う文字配列

void loop() {
FreqCounter::f_comp = 8; // Set compensation to 12
FreqCounter::start(1000); // Start counting with gatetime of 100ms
while (FreqCounter::f_ready == 0); // wait until counter ready
freq = FreqCounter::f_freq; // read result
Serial.print("Freq: "); // print result
Serial.print(freq); // print result
Serial.println("Hz"); // print result

// Print the proper amount of spaces to make it look pretty
LCD.SetCursor(0,1);
if (freq < 100)
LCD.Puts(" ");
else if (freq < 10000)
LCD.Puts(" ");
else if (freq < 1000000)
LCD.Puts(" ");
else
LCD.Puts(" ");

// As there is no service of print at i2cLCD lib, so
// we shall use sprintf function
sprintf(charbuf, "%ld", freq);
LCD.Puts(charbuf);
LCD.Puts(" Hz ");


delay(20);
LED_Stat=!LED_Stat;
digitalWrite(pinLed, LED_Stat); // blink Led
}

||<

 

 

まずはコンパイルして黙ってそのまま動かすと60Hzでました。電源ノイズ拾って表示してくれています。 To catch the power line noise, it shows as 60 helz.

(後で気が付いてpinmodeでINPUT_PULLUPにしたら、電源ノイズ拾わなくなりました。)Lately I set pinmode of INPUT_PULLUP, I can reject the power line noise.

 

f:id:nobcha23:20200625172009j:plain

ハムノイズ拾って60Hzカウント表示

何か信号源無いかと探したら、DSO068デジタルオシロテスト信号出力を思いつきました。これを利用しました。

To test the more higher frequency, I used DSO068 for test signal oscillator.

次のように動きました。ARDUINOカウンタでは100kHz出力が2%ぐらい低くなります。これはARDUINOカウンタの問題か、DSO068出力なのかを別のTXCO基準カウンタで今度調べてみることにします。 

f:id:nobcha23:20200625172147j:plain

DSO068のテスト信号を拾ってみる

 

ここまでくると、次はフランクリン発振回路部分の配線が必要となりました。74HCU04で行くか、LM311で行くかちょっと検討してから試作します。

At this time I'm wondering to use 74HCU04 or LM311 for the franclin oscillator.

 

---------------LCメーターの試作 2021年10月現在----
1. PICマイコンを使用 PIC16F88,PIC16F648A,PIC16F1827などを使用。LM311、74HCU04、PIC内蔵コンパレータでフランクリン発振器を構成。
http://chitose6thplant.web.fc2.com/pic16f/648_lcm2.htm

http://chitose6thplant.web.fc2.com/pic16f/88_lcm.htm

2. Arduinoを使用。74HCU04でフランクリン発振器を構成。
nobcha23.hatenablog.com

 

---------------LCメーター基板作成 2021年12月現在----

nobcha23.hatenablog.com

I'm introducing my LC meter on YOUTUBE.

www.youtube.com