Hello,
I need help with a fast response rate of pick to pick time measurement. I need this to work at low frequencies of 1- 200 Hz.
Unfortunately I am not a programmer but I know the basics and I worked with Arduino for a few months now, I can control the wave to be sinus or square.
If so, you do not necessarily have to detect peaks, instead it's sufficient to trigger the time measurement for a transition across any point (voltage) of a wave of repetitive signal of constant amplitude. You can use the analog comparator, or even a digitial input pin may be sufficient to recognize such transitions.
A square wave signal can be connected immediately to an digital pin, provided only that it spans almost the entire range between high and low level (at least 0.3 to 0.7*Vcc). Then you can measure the time between transitions in the pin-change interrupt or one of the external interrupts handler.
Hello, does anybody solve this problem. I need to count low freq 0-200hz, accuracy about 1 Hz. square wave (logic 1,0) and I am desperate, please help, I am trying for over two monts but without any good results
Why I got this error?
// this example is public domain. enjoy!
// www.ladyada.net/learn/sensors/thermocouple
float timee;
float last_time=0;
float hz =0;
int i=0;
int input = 36;
int state;
int state_2=LOW;
int counter = 0;
void setup() {
Serial.begin(250000);
pinMode(input,INPUT);
Serial.println("test rpm");
delay(500);
}
void loop() {
state=digitalRead(input); //program read is pin HIGH or LOW on digital pin 36
if(state != state_2) //if state of pin is diffrent from last state it count one hz
{
counter ++;
state_2=state;
}
i++;
if(counter>50) //when counter reach 50 program prints freq on serial monitor
{
timee=millis();
hz=timee-last_time;
Serial.println(hz);
hz=50/hz;
hz=hz*1000;
last_time=timee;
counter = 0;
Serial.print("HZ=");
Serial.println(hz);
}
}
I know digitalread is not very fast, but it should work for this what I need, I need to count max 300 Hz
I'm the author of FreqMeasure. So far, nobody has figured out the proper timer defines to make it work on Due. Or at least nobody has done so and shared them. If anyone does get it working, I'd be happy to include the defs.
As you can see on the FreqMeasure library page, if you scroll down to "FreqCount vs FreqMeasure", there's 2 basic approaches to measuring digital frequencies. Counting cycles only works well for higher frequencies. For low frequencies, measuring cycle time is what you need.
A software-only approach, like the code in #13, can work for very low frequencies. But it will have small errors due to interrupts, and the limited resolution of the timing functions like millis(). It also can't properly measure while doing other things, like printing to Serial.
I designed FreqMeasure to solve all those problems. Timer input capture allows very precise measurement, with resolution limited only to the maximum clock speed of the hardware timer. It also allows each cycles to be measured and stored in a buffer while your sketch does other work, like printing to Serial, so you never lose any input. Especially for very low frequencies where you must wait for a long cycle to get another measurement, automatically capturing every cycle with hardware and interrupts lets your program be as responsive as possible.
Unfortunately all this great capability does require expert-level knowledge to create the timer defs. If you're not very experienced with the Due hardware timers (I am not... I know them well on AVR and Kinetis chips, but not SAM3), your best option for high accuracy would be to switch to a board that is well supported. Or find an expert and convince them to make these defs, and hopefully contribute them so everyone else can use them too.
Thank you,I didn't see that, but it doesent work. I upload sketch but on serial it doesent print anything
Based on response, I'd expect library can't make any difference.
I don't mind if someone implemented a code in another library, just don't know how to send to github.
There is some nuances, that have to be considered. Code partly rely on Atmel's ASF and I ca't see, that arduino IDE is included all hardware :
There is no issue with tc.h, but I remember, that I can't compile ssc.h Could someone confirm what hardware is in the list of arduino DUE board definition for compiler, and what is not? And if tc.h is in the list today, would it be there in next release of IDE?
[quote author=Paul Stoffregen link=msg=2571533 date=1453149088]
I'm the author of FreqMeasure. So far, nobody has figured out the proper timer defines to make it work on Due. Or at least nobody has done so and shared them. If anyone does get it working, I'd be happy to include the defs.
As you can see on the FreqMeasure library page, if you scroll down to "FreqCount vs FreqMeasure", there's 2 basic approaches to measuring digital frequencies. Counting cycles only works well for higher frequencies. For low frequencies, measuring cycle time is what you need.
A software-only approach, like the code in #13, can work for very low frequencies. But it will have small errors due to interrupts, and the limited resolution of the timing functions like millis(). It also can't properly measure while doing other things, like printing to Serial.
I designed FreqMeasure to solve all those problems. Timer input capture allows very precise measurement, with resolution limited only to the maximum clock speed of the hardware timer. It also allows each cycles to be measured and stored in a buffer while your sketch does other work, like printing to Serial, so you never lose any input. Especially for very low frequencies where you must wait for a long cycle to get another measurement, automatically capturing every cycle with hardware and interrupts lets your program be as responsive as possible.
Unfortunately all this great capability does require expert-level knowledge to create the timer defs. If you're not very experienced with the Due hardware timers (I am not... I know them well on AVR and Kinetis chips, but not SAM3), your best option for high accuracy would be to switch to a board that is well supported. Or find an expert and convince them to make these defs, and hopefully contribute them so everyone else can use them too.
[/quote]hello, as I can see your desing of freq measure is good exacly what I looking for. But problem is I cant compile any off your libary in arduino IDE, for me is no problem to use AVR board i have arduino nano 328u. Then I can send data true rx/tx port on due.
Thank you, your sketch is fast and acurrate. But it have one problem, when there is no signal is keep printing the last save signal. And can you modify it to count 2-3 signals
I have recently announced a library for using the TC modules (Timer Modules) channels of DUE's Atmel ATSAM3X8E micro-controller. You have the announce in this post:
The TC module channels available in the ATSAM3X8E working in capture mode can measure duty and period of digital signals directly on hardware. The capture objects available on tc_lib abstract the use of TC module channels in capture mode.
Using a tc_lib capture object is easy, just have a look to the capture_test.ino example that comes with the library. The example measures a PWM signal generated on pin 7 with analgoWrite(). I think the example is self-explaining but if there is any doubt just tell me.
I have check the library with plenty of signals so @Yossi I think you should not have any problem to get the frequency and duty of a digital signal in the interval of 1-200 Hz that you want. In its present version capture objects can measure signals of a maximum period of about 102 seconds.