Thanks, I went back and forth on what I measured and when I converted measurements into the values that would be averaged. I inadvertently skipped over the idea of exponentially averaging the period inside the ISR. However I also struggled over the idea of averaging based on time vs averaging based on transitions of the input signal. For example, your method will converge more quickly at higher frequencies since it will converge to 63% after 128 transitions of the input signal. I don't think I can wait for convergence of 128 transitions if the signal goes down to 10hz. I decided that for my purposes, I would average inside the ISR only enough to reduce noise and then I would average the signal power outside the ISR based on time instead of the number of transitions. The system I am monitoring should change as quickly at low hz as it will at high hz. While timed sampling of the input signal favored averaging down to tenths of a second, transition sampling of the input signal may favor little or no averaging of the input signal.
I will have to decide to use your example exponential method inside the ISR at a lower shift value of 2 or 4 or mine that counts all the high and low microseconds until the next periodic average will take place. Yours may be better since it favors the most recent signal value. Then I will average the power level at a periodic time somewhere around 20 or 30 times a second in order to be comfortably faster than tenths of a second.
I have a question about your version of the exponential average. I am not quite sure I understand your use of the decShift variable. Is it only to boost the value above the decimal point? Also I do not start my exponential average with a left shift of the old average. I believe that truncates the right bits contained in the Shifted_avg_high accumulator. Am I doing it wrong?
Shifted_avg_high += (period << decShift) - avg;
avg_high = Shifted_avg_high >> weightShift;
The ISR in my example is completing in 12 or 16 microseconds. Do I need to experiment with your timing example if my input signal will never reach into kilohertz?
Your suggestion to suppress interrupts causes me to think I should keep all my immediate calculations inside the ISR instead of exiting the ISR with only the time stamp and a flag and then performing those immediate calculations inside the foreground loop. Then I should suppress interrupts when I do the periodic averaging.
Also I should incorporate volatile for a few variables.