Re: QRP SWR meter recommendation? #ubitx
toggle quoted messageShow quoted text
You can get a marginal speed improvement by moving the data definitions out of the loops. For example:
The macro ELEMENTS() allows you to determine the number of elements in an array automatically a compile time, thus eliminating the need to hard-code array sizes into the body of the program. That way, you can simply change the definition of the array in one place in the code, recompile, and the new size is automatically changed everywhere in the code. The really nice thing about the macro is that it's completely typeless...that it, it will work with any aggregate data type.
Moving the definition of a variable before and outside the loop saves the compiler the instructions necessary to adjust the stack pointer on each pass through the loop in the "in-scope, out-of-scope" aspect of a data definition within the loop. Quite honestly, on 8 iterations of the loop it will not likely be noticeable. Still, in other programs where SRAM is pretty tight, it could mean the difference between running and a stack crash.
On Tuesday, August 21, 2018, 1:02:39 AM EDT, Tom, wb6b <wb6b@...> wrote:
Here are some code snippets from a project I did. It calculates SWR from the voltages read from analog pins A6 and A7.
It does a number of other things, so here are the basic pieces of code for SWR extracted out into small snippets.
This first code segments captures selected analog pin voltages and applies an exponential smoothing filter to them.
This next slice of code captures the max voltage and applies a slow decay to the max value.
And here the SWR is calculated from the Max values.
You can see the full code here: