This is a promoted post written by 43oh member, Fmilburn. You may find detailed information in his thread “Rotary Encoder with Coarse / Fine Adustment“.
MSP-EXP430FR6989 running the Encoder Library, changing frequency on an AD9850.

MSP-EXP430FR6989 running the Encoder Library, changing frequency on an AD9850.

This is an Energia sketch designed to be used with a rotary encoder with push button.  The difference is that input can be made coarser or finer by pushing the button.

The need came about because I wanted to be able to adjust a frequency generator between 1 and 40 MHz with fine adjustment on the order of 1 Hz with a simple interface on the board.  A potentiometer would not work due to low resolution and jitter.  Buttons or a simple encoder might work but it would take a lot of button pushing or knob turning to get from 10 Hz to 10 MHz.  I thought about a solution where the rate of turning the knob would determine the incremental increase or decrease but that seemed fiddly.  I could use multiple buttons but I liked the idea of a knob and in the end I only had one rotary encoder on hand.

So my solution was to use the encoder push button to provide for coarse to fine adjustment.   For example, the encoder can be set to increase or decrease the value by 100 with a twist.  By pushing the button it can be made to improve fine control by say 1 value per click.  This allows the user to rapidly change values or achieve fine  control as desired.
A couple on additional points:

  • Capacitors were used for hardware debouncing.  You may wish to modify the sketch or use a different encoder scheme with software debouncing.
  • Interrupts were used for both encoder pins and the switch.  You may need to change the pins to a port with interrupt capability with different LaunchPads.
  • The sketch allows the minimum and maximum values to be set, as well as the change rate for coarseness.

It seems to work pretty well although it is a cheap encoder and with a minimal effort I can now rapidly change the frequency on my AD9850 and see the results on the FR6989 LCD.

The sketch can be found on github.