Hi,
Thank you, I am using divider so frequency range is no a problem. Code is simple:
while (FreqCounter::f_ready == 0) { // wait until counter ready
frq = FreqCounter::f_freq; // read result
}
frq = frq - (frq * 0.00034);
frq = frq * 100 * 80;
if (frq > 0) {
buff = frq;
}
frq = buff;
}
this is what basically reads input from digital pin 5.
The main problem is that I am also displaying it on display and when input occurs during that time, it is not able to catch it. I need something what enables me to priorly read input from pin 5 immediately when it occurs so I will catch all pulses.
U8GLIB_PCD8544 u8g(4, 3, A4, 2, A5); // CLK=4, DIN=3, CE=A4, DC=2, RST=A5
float logarithm, output, frq, a, b, battery, buff, buffa, buffb;
unsigned int select;
String string, jednotky, fwd, bwd;
void setup() {
pinMode(9, OUTPUT);
//pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
digitalWrite(9, HIGH);
delay(500);
pinMode(9, INPUT);
analogWrite(6, 5);
Serial.begin(57600);
}
void loop() {
select = digitalRead(9);
//battery = analogRead(A1);
//battery = battery / 100;
a = analogRead(A2);
a = a / 200;
b = analogRead(A3);
b = b / 200;
if (a > 0) {
buffa = a;
}
a = buffa;
if (b > 0) {
buffb = b;
}
b = buffb;
fwd = "FWD: " + String(float(a), 3) + " V";
bwd = "BWD: " + String(float(b), 3) + " V";
if (digitalRead(5) == HIGH) {
FreqCounter::f_comp = 1; // Set compensation to 12
FreqCounter::start(10);
while (FreqCounter::f_ready == 0) { // wait until counter ready
frq = FreqCounter::f_freq; // read result
}
frq = frq - (frq * 0.00034);
frq = frq * 100 * 80;
if (frq > 0) {
buff = frq;
}
frq = buff;
}
delay(10); // Start counting with gatetime of 100ms/10/100/1000
logarithm = log10(frq);
if (logarithm < 3) {
jednotky = " Hz";
output = frq;
} else if ( logarithm < 6 && logarithm >= 3) {
jednotky = " KHz";
output = frq / 1000;
} else if ( logarithm < 9 && logarithm >= 6) {
jednotky = " MHz";
output = frq / 1000000;
} else if ( logarithm < 12 && logarithm >= 9) {
jednotky = " GHz";
output = frq / 1000000000;
} else if ( logarithm < 15 && logarithm >= 12) {
jednotky = " THz";
output = frq / 1000000000000;
}
string = "F: " + String(float(output), 3) + jednotky;
u8g.firstPage();
do {
draw();
} while ( u8g.nextPage() );
}
void draw() {
u8g.setFont(u8g_font_profont12); // select font
u8g.setPrintPos(0, 24); // put string of display at position X, Y;
u8g.print(string);
u8g.setFont(u8g_font_profont11);
u8g.setPrintPos(0, 40);
u8g.print(fwd);
u8g.setPrintPos(0, 48);
u8g.print(bwd);
// u8g.setPrintPos(45, 8);
// u8g.print(String(battery));
}