Frequency Counter Troubleshooting

Hi guys,

I am aware that there are a ton load of posts relating to using the frequency counter but none seem to have to same issue that I am.

I uploaded the attached code and corresponding library to my Arduino Uno and used a frequency generator (as I am trying to replicate a sensor signal) to provide me with a signal.

Whilst calibrating, using 5V square wave frequencies of 1kHz, 10Hz, 100kHz and 1MHz I noticed that on the serial monitor that all the frequencies were a decade below the desired frequencies and it required adjustment of the voltage amplitude to achieve any resemblance to the frequency being inputted.

My background is not electronics so I am no anywhere near fluent in the Arduino language but if someone would shed some light on this for me it would be great?

Thanks

Chris

Freq_Counter.ino (519 Bytes)

void loop() {

 FreqCounter::f_comp= 12;             // Set compensation to 8
 FreqCounter::start(100);            // Start counting with gatetime of 100ms
 while (FreqCounter::f_ready == 0)         // wait until counter ready
 
 frq=FreqCounter::f_freq;

Compensation 8 - value set to 12 - either comment or code is wrong

the while loop is missing a ";". Unless you meant to read the value constantly - and then not read the last (presumably correct) value.

I'm not familiar with the FreqCounter library and I don't know what the f_comp parameter is, but magic numbers like that seem suspicious to me. The only configuration I'd expect to see would be relating to the duration of the measurements and associated averaging/smoothing - the name 'f_comp' suggests something to do with frequency(?) compensation and the reason for doing anything like that is not clear.

chrismecheng:
it required adjustment of the voltage amplitude

Why does voltage amplitude relate to frequency measurement at all? Your input signal uses TTL voltages and I can't see how you'd change the amplitude or why you would want to.