¿ªÔÆÌåÓý

Re: Flutter Fix


 

John Smith,

Did you see this note in my follow-up email the next morning:

> ?Remove the extraneous final 3 lines about the tone and replace them with a closing "}".?

Sounds like you might be missing the final "}".

You said: ? ?"And I was just inserting the new lines between original lines of code."

You are not "just inserting" . ?You are removing some old code and replacing it with new code. Replace the lines of code I have included in the mail history here with the following lines (this time I managed to include that final "}" in my copy-and-paste). ?If you still get errors, make sure that for every "{" there is a matching "}" further down in the code. ?If you put the cursor on one of those within the Arduino development environment, it will probably highlight the matching other curly brace for you.

  // the tuning knob is at neither extremities, tune the signals as usual
  else if (knob != old_knob){
    static char dir_knob;
    if ( (knob>old_knob) && ((dir_knob==1) || ((knob-old_knob) >5)) ||
         (knob<old_knob) && ((dir_knob==0) || ((old_knob-knob) >5)) )   {
       if (knob>old_knob) {
            dir_knob=1;
            frequency = baseTune + (50l * (knob-5));
       } else {
            dir_knob=0;
            frequency = baseTune + (50l * knob);
       }
       old_knob = knob;
       setFrequency(frequency);
       updateDisplay();
    }
  }

?

Jerry


On Tue, Feb 21, 2017 at 06:48 am, Jerry Gaffke wrote:

The new code from my previous post does away with the constant flicker between adjacent frequencies due to noise in the ADC when the knob is not being rotated, but otherwise leaves functionality and feel exactly as Ashhar had coded it. ?Works on my Nano, I monitored the frequency value through the Arduino serial port. ?Remove the extraneous final 3 lines about the tone and replace them with a closing "}". ?(It was getting late.) ? The new code replaces this part of Ashhar's original code:

  // the tuning knob is at neither extremities, tune the signals as usual
  else if (knob != old_knob){
     frequency = baseTune + (50l * knob);
     old_knob = knob;
     setFrequency(frequency);
     updateDisplay();
  }

It works by inhibiting a reverse in direction of the tuning pot until that reversal has traveled through what would normally be 5 steps in frequency of 50hz each. ?For example, assume we have been tuning up in frequency and stop the knob at 7200.000 khz. ?A bit of noise comes in from the ADC, and the frequency pops up to 7200.050 khz. ?Another bit of noise comes in that would normally bring it back down to 7200.000 khz, but this is ignored because it does not reach the 5 tick threshold. ?A light touch on the knob might bring it a bit further up to 7200.100 khz. ?Reversing the direction of the knob, it travels through 5 steps before any change in frequency occurs, on the 6'th step the frequency goes back down to 7200.050 khz. ?If we leave the knob in that position, a bit of ADC noise might lower it further to 7200.000 khz, but noise will not raise the frequency. ?

I recommend operating with the original code at first until the noise at the pot has been evaluated and minimized with bypass caps and perhaps short shielded wiring. ?Then enable this new code by recompiling the sketch.

The frequency will still move a little bit after taking your hand off the knob, but can only move in one direction. ?If that is unacceptable but you otherwise like the current method of tuning, then perhaps reduce the tuning rate by a factor of two by replacing this line:

? ? ??frequency = baseTune + (50l * knob);

with this

frequency = baseTune + (50l * (knob>>1));


Me, I'll likely go to Don Cantrell's shuttle tuning scheme as described at?
But use an encoder instead of a pot so I can feel a click when it moves between positions.

Jerry, KE7ER

?

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