FreqMeasure - Sampling time

Status
Not open for further replies.

Bignige

Member
Hi, I have successfully used FreqMeasure.h with an arduino UNO however the speed of obtaining a reading seems quite slow. about 1 second. This was obtained by using a photodiode based IR light detector receiving a beam pulsed at 100Hz. I have an led indicator that shows when a beam has been received. but the LCD readout take about a second to show the correct frequency.

Is this because of the clock speed of the arduino? would the Teensy be quicker?

Or can it be speeded up by changing the number of counts in the sample? I want to measure from 100hz to 300Hz I dont need the accuracy to be exact.



Regards
Nigel
 
even the slowest micrcontroller can measure that.. just take a shorter time to measure, but since the frequency is so low you can not go under several times 1/100 of a second, but thats allready much faster than a second..
Show your code, then we can tweak it.
 
I'm just using the example code now for testing:

/* FreqMeasure - Example with LCD output
* http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
*
* This example code is in the public domain.
*/
#include <FreqMeasure.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
Serial.begin(57600);
lcd.begin(8, 2);
lcd.print("Freq:");
FreqMeasure.begin();
}

double sum=0;
int count=0;

void loop() {
if (FreqMeasure.available()) {
// average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
double frequency = F_CPU / (sum / count);
lcd.setCursor(0, 1);
lcd.print(frequency);
lcd.print(" ");
sum = 0;
count = 0;
}
}
}


I assume its the 'count' value?
 
You wait for 30 measurements with this line:
if (count > 30) {

You can take 3 or 4 measurements, or even 1 measuremente, as the % error is very low with this low freuencies, I dpends on the amount of noise in the signal you want to even out..

if (count > 1) { //take 1 measurement
 
Is this because of the clock speed of the arduino? would the Teensy be quicker?
There is something bigger to tackle first. The measurement function looks at the time it takes for one complete cycle which is 10 milliseconds for 100 Hz. It probably looks for edge transitions in the signal. If you do that measurement 30 times there's 300 msec at least. But then depending on the inner working of the function you might to wait again for another leading edge before you can take the next measurement, which means burning one additional complete cycle, every time. That would be a total of 600 msec. It doesn't look like the processor speed is very close to being your limiting factor.


Or can it be speeded up by changing the number of counts in the sample? I want to measure from 100hz to 300Hz I dont need the accuracy to be exact.
This is your low-hanging fruit. Since you don't have a requirement for high accuracy then one reading should suffice. You should be able to speed things up to the point where the LCD refresh time and/or visual perception aspect will be the limiting factors.
 
Last edited:
You're wrong, if you wait for 1 measurement, it will automatically wait for the period to finish, whatever period that is. The variable "count" counts just your number of measurements.


I've used these functions a lot, however: waiting for at least 2 measurements is good praktice.

There is something bigger to tackle first. The measurement function looks at the time it takes for one complete cycle which is 10 milliseconds for 100 Hz. It probably looks for edge transitions in the signal. If you do that measurement 30 times there's 300 msec at least. But then depending on the inner working of the function you might to wait again for another leading edge before you can take the next measurement, which means burning one additional complete cycle, every time. That would be a total of 600 msec. It doesn't look like the processor speed is very close to being your limiting factor.



This is your low-hanging fruit. Since you don't have a requirement for high accuracy then one reading should suffice. You should be able to speed things up to the point where the LCD refresh time and/or visual perception aspect will be the limiting factors.
 
if (FreqMeasure.available())
this checks if a period has passed, and a result is known, so it automatically adapts to whatever frequency is involved, thats the way input capture works
 
Status
Not open for further replies.
Back
Top