Wednesday, 21 January 2015

Finessing Rotary Encoder Code

My interrupt-driven code for the rotary encoder certainly has made a worthwhile improvement to the "feel" of my rigs - particularly the "Parallel IF" rig. But I've noticed one little wrinkle in the otherwise silky-smooth operation...

Just occasionally, when adjusting one of the digits, there's an unexpected change to the next lower digit, as shown in this (mocked-up) image.



You see from the block cursor position in the image above that I'm intending the Rotary Encoder should adjust the kiloHertz digit - which it usually does - beautifully. However, just occasionally, there's an irritating jump of 500Hz.

Similarly, if I'm adjusting in 100 Hz steps, there could be a 50 Hz "jump". Etc., etc..

Infuriating!

I traced the issue to the declaration of the variable "Turns" (as described in this post) as a double...

    double Turns;

and fixed it simply by declaring it as an integer...

    int Turns;

Now there are none of these "half-steps".

This minor niggle has been fixed in the sketches Double_DDS_VFO_0v2.ino and Si5351_VFO_0v2.ino, which can be found at this GitHub repository.

If you've used the code, I recommend that you update by making this simple change.

It really is worthwhile!

...-.- de m0xpd

2 comments:

  1. Dear Paul, I enjoyed reading this post and the articles in Sprat.
    It's great to find the problem and the solution, after noticing such a tiny but infuriating problem.
    73, Bert

    ReplyDelete
  2. Hi Paul,
    int Turns; // works great here!
    So obvious once someone points it out!
    Thanks for sharing.
    Fred LaPlante, WA1DLZ

    ReplyDelete