100PPR encoder – mods to KD8CEC code to make it work better

Using a 100PPR encoder with the KD8CEC firmware may cause some issues as the firmware can’t keep up with the pulse train from the encoder.

Sascha Bonnet suggests some simple code modifications make a big difference. He replaced two commands (“millis” to “micros”) in the KD8CEC’s source code and my encoder worked.   Here’s his code for you to use as a template for editing the KD8CEC arduino sketch:

  1. int enc_read(void) {
  2.   int result = 0;
  3.   byte newState;
  4.   int enc_speed = 0;
  5.   unsigned long start_at = millis();
  6.   while (millis()  start_at < 50) { // check if the previous state was stable
  7.     newState = enc_state(); // Get current state  
  8.     if (newState != enc_prev_state)
  9.       delayMicroseconds(1);
  10.     if (enc_state() != newState || newState == enc_prev_state)
  11.       continue;
  12.     //these transitions point to the encoder being rotated anti-clockwise
  13.     if ((enc_prev_state == 0 && newState == 2) ||
  14.       (enc_prev_state == 2 && newState == 3) ||
  15.       (enc_prev_state == 3 && newState == 1) ||
  16.       (enc_prev_state == 1 && newState == 0)){
  17.         result–;
  18.       }
  19.     //these transitions point o the enccoder being rotated clockwise
  20.     if ((enc_prev_state == 0 && newState == 1) ||
  21.       (enc_prev_state == 1 && newState == 3) ||
  22.       (enc_prev_state == 3 && newState == 2) ||
  23.       (enc_prev_state == 2 && newState == 0)){
  24.         result++;
  25.       }
  26.     enc_prev_state = newState; // Record state for next pulse interpretation
  27.     enc_speed++;
  28.     delayMicroseconds(1);
  29.   }
Reference

An interesting i2c encoder board for managing multiple encoders

John Scherer came across an interesting, i2c addressable rotary encoder board that allows you to connect encoders in just about any configuration.

The board has pins for digital or ADC I/O, has 256 bytes of eeprom, pads for setting each encoders i2c address, and works from 3.3 – 5V DC.   For something like the µBitx, this could be an easy way to add additional physical I/O (i.e. knobs).

There is also a video that gives a pretty good overview of how they work.

John VK2ETA suggests that on a read of the manual it appears the 256 registers are at one I2C address, and are divided between control registers and EEPROM addresses (two banks of 128 bytes).

The current implementation has the current modes for the encoder:

A. Relative, where the counter keeps the number of steps since last read. Reading it resets the counter to zero. Useful for frequency tuning in our case.

B. Absolute
B1. Without limits.
B2. With user defined limits
B2.1. No wrap around, like a potentiometer, hard stops at the limits.
B2.2 With wrap around, goes back to low limit if high limit is exceeded and vice-versa.

The encoder push button events are:
– button down
– button up
– double-press with user selectable double-press interval.

Current consumption is listed at less than 2mA plus LED current if used.

The board mounted PIC controller’s program is open source so it can be customized as well.

Tom, WB6B believes they keep a counter in the PIC chip that is on each board, so each time you check the status of an encoder board it will tell you how many encoder pulses took place since the last time you polled the data. This should greatly relax any timing issues.

Reference

Removing the detent in a 100PPR optical encoder

This optical encoder (widely available on eBay or Aliexpress in black or silver) has been used by some constructors as a replacement to the standard mechanical encoder supplied with the µBITx kit.   It is a 100ppr encoder (whereas the one supplied with the µBITx is 24PPR) so may not work perfectly with either the default firmware supplied by HF Signals or Ian Lee KD8CEC firmware (i.e. you may need to experiment with the code for generating the VFO).

With the detent mechanism removed to allow free turning the encoder gives a very smooth tuning action.   With the encoder able to spin freely the protruding crank handle will always come to rest in the down position so it too has to be removed.

The main complaint with these encoders is the detent feature.  To remove the detent, here are the instructions from Robert GM4CID:

Remove the knob handle, then, using a heat gun or hair dryer heat the silver knob insert to soften the adhesive and carefully pry off that silver insert to reveal retaining screws that can be removed. The mechanism will now come apart and you can remove the detent. Replace everything but not the handle.

Reference

Using a 100 PPR encoder with the uBITx

Allison KB1GMX gives details on how to wire up the commonly available 100prr-6 encoder.  These have a nice vernier style dial and cover 100 pulses per 360 degree rotation.  The calibration points line up with these pulses.  They come with either 4 or 6 wire terminals on the back.

The A and B terminals have transistor outputs to ground and are used in connecting to the raduino:

  • Ground is ground (0V) terminal
  • Black and brown to the A and B terminals (reverse if the rotation direction is backward)
  • 5V from raduino 5V reg to the internal LEDs used in the optical encoder  (Vcc terminal)

Allison uses the V4.3 code in her µBITx with here own mods and this encoder worked well. Some firmware for the Raduino will not be sufficiently fast to keep up with the signals being sent from the encoder if you rotate the encoder quickly.

The uBITx.net editor likes the black version better.  These are a classy unit.

Reference

Debouncing a Rotary Encoder

N5IB reports, “ALPS, a maker of rotary encoders, recommends 10K pullup to Vcc, then 10K in series with 0.01 uF to ground. The internal pullup in the ATMega is loosely specified – somewhere in the tens of K, max 50K.

Jim Sheldon W0EB responded with, “This settled the really cheap and modified (to take the detents out) encoder on the test set right down. Tuning is extremely smooth and I don’t notice ANY digits showing up and then backing up again as it did before.

“I can highly recommend adding a 10K external pullup to both the encoder A and B inputs as well as an additional 10K in series with .1uF capacitor to ground on both the A and B inputs to the Raduino card.

“It was a nice surprise addition and I won’t leave them out again.”

Hans G0UPL responds, “Debouncing and pullups are also possible in the firmware. This is the method I use in the QRP Labs kits like QCX http://qrp-labs.com/qcx – look at the schematic: no pull-ups, no RC-debounce. Saves 6 components (4 resistors, 2 capacitors). It’s not important in a one-off build or modification but in a kit where you are trying to optimise cost, every resistor helps! The firmware method also gives you more control over how you do your debounce. I prefer the state-machine approach to rotary encoder handling, it implicitly debounces without involving any time constants.”

Reference