¿ªÔÆÌåÓý

Re: doTuning Code Question


 

There's plenty of changes that need to be made to the Raduino sketch. ?But those are not changes I'd find compelling:


Tuning position within the current 50khz range at power up may as well be wherever the pot happens to be set.

Having ? ?knob!=old_knob ? ?on first pass is good, the Si5351 gets an initial frequency loaded?

Having ? If (knob!=old_knob) ? as an outside conditional would avoid executing some code, but that doesn't buy more than a few microseconds. ?

It would be better programming practice to initialize dir_knob to either 1 or 0, but in this case it would make no noticeable difference to the user.


Here's a thread you might check out if you are interested in taking an axe to doTuning(): ? ?/g/BITX20/message/23362?

Also read this blog post: ?

And Jack's programming style kibitzing: ? ?/g/BITX20/message/22358


Jerry, KE7ER


On Wed, Mar 15, 2017 at 03:29 pm, <jmlynesjr@...> wrote:

At POR the pot could be in any position therefore knob can be anything from 0-1000 counts. Odds are the pot wasn't centered therefore the tuneup range will not be equal to the tunedown range. If you want the ranges to be equal, a routine could be added to setup() to center the pot at POR. The knob position at POR is initially equated to baseTune = 7100000L; //7100 KHz.



First, old_knob is defined as zero - int old_knob = 0;
??? This will force knob != old_knob on the first pass. I'm not sure this is what's wanted.
??? In setup(), I think this should be added to initialize old_knob to the POR position of the pot(it hasn't moved yet):
??? old_knob = analogRead(ANALOG_TUNING) - 10; // Initialize old_knob to POR position of the pot
??? Then doTuning won't trigger until the pot actually moves.

Second, you don't need to do most of doTuning if the pot hasn't changed and further if the pot
??? hasn't changed by more than the deadband. I'd make the else if(knob != old_knob) the
??? outermost loop and change it to something like if(abs(old_knob - knob) > DEADBAND) { ... }

Third, static char dir_knob; doesn't initialize dir_knob(unless the compiler sets it to zero
??? which would set it defacto to tunedown). Does this make any sense? At this point you
??? have no idea if you are tuning up or down. I would expect to see a little tuning glitch
??? at POR until these variables sync up.

?

Join [email protected] to automatically receive all group messages.