31
Listeroid Engines / Re: Listeroid Governor Control
« on: July 19, 2016, 02:27:27 AM »
You can decrease the time between "updates" and still keep the averaging of the frequency by using a simple trick. Each time you get a frequency sample, you add it to the prior sum and subtract out the oldest sample (you have to keep track of all samples). That way, you have an average of the frequency at every sample. You have to get the first (n-1) samples before you can start, but after that you can update more often.
You can also eliminate the "divide by n" (for n samples) by multiplying your target by n up front. So if you average 5 samples, you simple add them up and compare to 250 (for 50 Hz).
If you're measuring time between samples to get frequency, you can eliminate the reciprocals and just work in "period" as well. For 50 Hz, the period is 20 milli-seconds, or for 5 samples 100 MS.
You can also eliminate the "divide by n" (for n samples) by multiplying your target by n up front. So if you average 5 samples, you simple add them up and compare to 250 (for 50 Hz).
If you're measuring time between samples to get frequency, you can eliminate the reciprocals and just work in "period" as well. For 50 Hz, the period is 20 milli-seconds, or for 5 samples 100 MS.