I have a frequency counter code using pulseIn command. It's measuring a sweeping frequency, so 20 pulses at 1hz 20 at 2 hz to 20 at 6 hz. These all have a 10% duty cycle
I'm using Ltime to measure the low time and Htime to measure the high time.
The problem I have is for the 1hz and 2 hz the Ltime is measuring 0.0 , the high time measures correctly . The low time for the other frequencies measures fine.
the consiquence of this is the 1hz is displayed as 10hz and the 2hz displayed as 20 hz.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
unsigned long Htime;
float Ltime;
float Ttime;
float frequency;
float hightime;
void setup() {
// put your setup code here, to run once:
pinMode(8,INPUT);
lcd.begin(16,2);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Frquency ");
Htime=pulseIn(8,HIGH);
Ltime=pulseIn(8,LOW),
Ttime=Htime+Ltime;
frequency=(1000000)/Ttime;
lcd.setCursor(2,2);
lcd.print(frequency);
lcd.print(" Hz");
delay(2000);
}