Thank you for your comments. I'm still getting my head around exactly how doTuning works.
As I don't yet have a functioning Raduino, the following is based on desk checking the code. I may be able to simulate it on a chipKIT UNO that I do have working. Here we go...
The pot wiper varies from 0-5 vdc. The internal representation of the pot, "knob", varies approximately 0-1000 counts. At 50 Hz per count, this makes the tuning range about 50 KHz.
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.
Ok, back to the listing...
James
KE4MIQ