I am measuring the max rate that a stepper motor is driven at. Because steppers require acceleration and deceleration for best performance, the train of pulses does not have a fixed period. It was getting tedious to find the shortest period using a logic analyzer. Thought to write a program to do this with a teensy 4.0. Kind of a specialized need and I was resigned to having to figure out 1062 timers but to my joy found FreqMeasure and realized it could do what I want with a very simple change. shoulders of giants and all that...
In order to measure the highest rate (ie, shortest period), I modified FreqMeasure to record the minimum pulse length and added a new method readMin() to the class. It works fine for me. I am looking at how I can change it to help analyze pulse jitter. Not quite as simple, though.
Literally, it required 7 lines of code in total. I don't think it changes any performance as it only adds this to the FTM_ISR in FreqMeasure.cpp
I didn't change the other ISR but it makes sense for non-ARM users, I suppose.
Other changes:
plus declaration of min_capture;
In begin():
and in FreqMeasure.h:
If there is any interest to merge into the github repository, I will be happy to do a pull request (though may need some help with that - I find github pulls confusing).
In order to measure the highest rate (ie, shortest period), I modified FreqMeasure to record the minimum pulse length and added a new method readMin() to the class. It works fine for me. I am looking at how I can change it to help analyze pulse jitter. Not quite as simple, though.
Literally, it required 7 lines of code in total. I don't think it changes any performance as it only adds this to the FTM_ISR in FreqMeasure.cpp
Code:
if(period < min_capture) min_capture = period;
I didn't change the other ISR but it makes sense for non-ARM users, I suppose.
Other changes:
Code:
uint32_t FreqMeasureClass::readMin(void) {
return min_capture;
}
plus declaration of min_capture;
Code:
static uint32_t min_capture;
In begin():
Code:
min_capture = 0xFFFFFFFF;
and in FreqMeasure.h:
Code:
static uint32_t readMin(void);
If there is any interest to merge into the github repository, I will be happy to do a pull request (though may need some help with that - I find github pulls confusing).