(FreqMeasure.available() timeout semaphore

Status
Not open for further replies.

Ivo

Member
Hello,

I am struggling with the FreqMeasure library.

My problem is that I need to detect a train of pulses.

With the FreqMeasure.available() I painfully realized that I am not able to use !FreqMeasure.available()

to signal an end of a pulse. The function toggles only once from FALSE

For example

if (FreqMeasure.available()) {
start clock;
}
if (!FreqMeasure.available()) {
stop clock;
}

My question is how to signal back that the incoming train stopped or how do I reset the (FreqMeasure.available()) ?

An ideal (wish list) would be to have FreqMeasure.timeout(t) that one can set the timeout period for the FreqMeasure.available() to toggle back to FALSE

Thank you
 
I'm confused. Part of your message talks of a group of pulses, but part talks of detecting the end of a pulse. Maybe you meant the last within a group?

First, you must understand FreqMeasure is designed to detect only rising edges. The numbers it returns represent the time between two successive rising edges. If you need to detect both begin and end of individual pulses, you'll need something other than FreqMeasure.

If you just need to detect the gap between groups of pulses, why not just examine the numbers FreqMeasure returns.

You asked for available() to somehow alert you to the end of something (exactly what is unclear to me). Again, please consider that FreqMeasure detects rising edges of the waveform. Each rising edge turns into available and read giving you one more piece of data. The available() function isn't for analysis. It's purpose is to work together with read() to deliver data to you.

Analysis of that data is up to you. If only rising edge events are enough, you should be able to do math with those numbers to find the timing of your waveform. FreqMeasure's purpose is only to measure the timing between those rising edges.
 
Last edited:
My apologies for not being clear as I did conflate two issues.
I have a need to do both. My application measures the time between each pulse in the train but also the time from the start of the first pulse To the last falling edge in that train.
It looks to me like the first read() returns the time since last falling edge to the first rising edge that triggers the available()
and all subsequent read() return the period from the falling edge to the next rising.
(I realize that this is academic as dutucycle past 50% reverses this)
I think that my problem is due to the fact that the function does not return a value after the last state change unless there is "one more" edge in order for me to do the math. Example pulse train of 5 x 10 mS pulses returns 5 values...
First one is the time since the last pulse and 4 with the period in between the pulses. Hence my dilemma on knowing the exact time from the rising edge of the first train pulse to the last falling edge of this train w/o having to wait for the next train pulse. I currently have a solution using millis() measuring the start and end of the loop but it is not very flexible with signals that have dutucycle spanning from 10-90%.
My apologies if I do not sound coherent as I stared at it the entire day I feel like my head is going to explode. ;-)
I quickly looked at the timer registers and there appears to be some guidance in setting the registers to accommodate the various rising/falling edge combinations and so I had hoped that someone may be familiar wit my issue.
 
My application measures the time between each pulse in the train but also the time from the start of the first pulse To the last falling edge in that train.

You're probably going to have to dig into the low-level details of using the timer hardware. Maybe the FreqMeasure code might give you a good starting point, but since it never responds to falling edges, it simply isn't going to give you everything you need.

You might also look at the PulsePosition code. It makes different pulse measurements (involving both edges), which also probably will not do everything you need, so expect the value to only be a head start on building your own.

It looks to me like the first read() returns the time since last falling edge to the first rising edge that triggers the available()
and all subsequent read() return the period from the falling edge to the next rising.

No. FreqMeasure never responds to falling edges.

Perhaps you might look at the "FreqCount vs FreqMeasure" section. It's here, just scroll down until you see the picture with the sine wave.

http://www.pjrc.com/teensy/td_libs_FreqMeasure.html

I just don't know how to explain more clearly that FreqMeasure only measures the rising edges.
 
Last edited:
Thank you very much. This is very helpful.
Things are for some reason much clearer in the morning ;-)
 
Status
Not open for further replies.
Back
Top