nobcha23の日記

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

Arduino C meter 2 2/3 2.2MΩ 充電時間計測のCメータ to measure charging time( time constant ) by using the internal resister of Arduino 2/3

2.2MΩ利用の充電時間計測のCメータで手持ちフィルムコンや電解コンを測ります。ところが、またや伏兵。電解コンで大容量になると2.2MΩでは何十秒もかかります。I checked my keeping film capacitors and aluminum capacitors. I found that the large aluminum capacitors ask much time to charge with 2.2mega ohm.

10μF

以上をとりあえず、YOUTUBEで。Please watch my YOUTUBE.
youtu.be


やっぱり内部プルアップ抵抗を使う方をやり直すことにします。

スケッチもつけます。The sketch is below.

                            • 2.2MΩ resister option--------

// Measure time when C is charging up to 63.2% of 5V
// A2 port shall switch capacitor voltage
// Created by nobcha
// 2023.09.05
#include

#define ANALOG_READ_PIN A1
#define DIGITAL_WRITE_PIN A2
#define GND_PIN A3

// Capacitance between ANALOG_READ_PIN and Ground
// DIGITAL_WRITE_PIN will charge and discharge
float capacitance;
//Pleae connect pullup resistance of 2.2Mohm.
//const double E = 5.00; // GPIO電圧実測値
//const double V = E * 0.632;

#define MAX_ADC_VALUE 1023
float R = 2200000;
const int TAU = 0.632 * MAX_ADC_VALUE;

int KEY;
//LCD Keypad Shield is used A0 for key
#include
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7);
#define KEYPAD_PIN A0

unsigned long charge_time, start_time;

void setup(){
pinMode(DIGITAL_WRITE_PIN, OUTPUT);
digitalWrite(DIGITAL_WRITE_PIN, LOW); // discharge
pinMode(GND_PIN, OUTPUT);
digitalWrite(GND_PIN, LOW); // Ground

Serial.begin(9600);
Serial.println("C meter 2 V1.0") ;
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("C meter 2 V1.0  ") ;
delay(1000);
}

void loop() {
lcd.setCursor(0,0);
lcd.print("Set C & SELECT " );
Serial.print("Set C ") ;
delay(1000);

while( analogRead( KEYPAD_PIN)>100); // SELECT key turns A0 to 0
Serial.println(" Wait") ;
lcd.setCursor(0,1);
lcd.print("Wait ") ;

capacitance = get_C();

Serial.print("C=") ;
Serial.print(capacitance, 6) ;
Serial.println("uF");

lcd.setCursor(0,1);
lcd.print("C = ");
if(capacitance>0.01){
lcd.print(capacitance , 3);
lcd.print(" uF ");
}
else{
lcd.print(capacitance*1000000, 3);
lcd.print(" pF ");
}
}

float get_C(void){
//Capacitor under test between OUT_PIN and IN_PIN
//Rising high edge on OUT_PIN
pinMode(ANALOG_READ_PIN, OUTPUT);
digitalWrite(ANALOG_READ_PIN, LOW);
delay(100);
pinMode(ANALOG_READ_PIN, INPUT);
start_time = micros();
digitalWrite(DIGITAL_WRITE_PIN, HIGH);
while( analogRead(ANALOG_READ_PIN) < TAU); // wait time constant
charge_time = micros() - start_time ;
digitalWrite(DIGITAL_WRITE_PIN, LOW);
delay(100);
return (charge_time / R);
}