¿ªÔÆÌåÓý

doTuning Code Question


 

In doTuning where the pot hits the low stop,

??? baseTune = baseTune - 10000l;

??? frequency = baseTune;

This makes sense, drop the center of the tuning range by 10KHz.


Where the pot hits the top stop,

??? baseTune = baseTune + 10000l;????????????? // ok

??? frequency = baseTune + 50000l;???????????? // Huh?

The extra 50KHz makes no sense.

James



 

baseTune is the frequency you get when the pot is rotated to the bottom of the linear tuning region. ?When the pot is rotated to the top of the linear tuning region, that frequency is 50khz above baseTune.


On Tue, Mar 14, 2017 at 11:35 am, <jmlynesjr@...> wrote:

Where the pot hits the top stop,

??? baseTune = baseTune + 10000l;????????????? // ok

??? frequency = baseTune + 50000l;???????????? // Huh?

The extra 50KHz makes no sense.

?


 

Hmm, this is indeed strange.
I also cannot see any rationale for the extra 50kHz, only when we are at
the high end of the pot.
Anybody?

I just tried and removed the 50kHz from my sketch and everything seems to
work normally.

73, Allard PE1NWL


 

Ah yes Jerry you're right. I was too quick.
When I remove the 50 kHz it seems to work ok while you are at the end of
the pot. But when your return back to the linear region then suddenly the
frequency jumps up by 50 kHz.
So yes, the extra 50 kHz is indeed necessary!

73, Allard PE1NWL

On Tue, March 14, 2017 19:43, Jerry Gaffke via Groups.Io wrote:
baseTune is the frequency you get when the pot is rotated to the bottom of
the linear tuning region. ??When the pot is rotated to the top of the
linear tuning region, that frequency is 50khz above baseTune.


 

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



 

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.

?


 

> ?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 also wouldn't work. ?If the knob is hard left or hard right, then we scan down or up by 10khz continuously once every 200ms, even if the knob stays put.