Showing posts with label Encoder. Show all posts
Showing posts with label Encoder. Show all posts

Monday, October 20, 2014

Minima - Jeff's ENCODER04

This is a proposed configuration to support Jeff's ENCODER04 routines within my Minima's Alternate Tuning Method. This is a fantastic addition for the Minima.



The following circuit should be added to the Minima to implement the ENCODER04 Rotary

Encoder and Multiple Push-Button Switches parallel to the original FN Switch. 

--------+
Arduino |
        |
   AVCC |
   pin20|--------+---1K---- +5V
        |        |
        |        = 100nF
        |        |
        |        G
        |
    PD5 |---------------- To Original Minima LowPass Filter
  pin11 |
        |
    PC0 |---------------- To Proposed Rf386 Power Amp Filter Selector
  pin23 |
        |
        |
    PD7 |                                    +--------+
  pin13 |------------------------+-----------|B      C|------------------------+
        |                        |     G-----|G  ENC  |                        |
    PD6 |--------------+---------)-----------|A      G|---+                    |
  pin12 |              |         |           +--------+   |                    |
        |              = 1nF*    = 1nF*                   G                    |
        |              |         |                                             |
        |              G         G                                             |
   AREF |                                                                      |
   pin21|----+-------+                       * = Optional but Suggested        |
        |    |       |                           for CPU's in RF Environments  |
        |    |       = 100nF                                                   |
        |    |       |                                                         |
        |    |       G                                                         |
        |   47K                                                                |
        |    |                                                                 |
        |    |                                                                 |
        |    |                                                                 |
    PC3 |    |                                                                 |
   pin26|----+-----+---4K7---+---4K7---+---4K7---+---4K7---+---4K7---+---4K7---+
        |    |     |         |         |         |         |         |         |
        |   FNS    = 1nF*    S         S         S         S         S         S
   AGND |    |     |         |         |         |         |         |         |
   pin22|----+-----+---------+---------+---------+---------+---------+---------+
        |    |
--------+    G

            "FN"           "Left"   "Right"   "SBand"     "Up"     "Down"     btn7
           (btn1)          (btn2)    (btn3)   (btn4)     (btn5)    (btn6)    (btn7)


Where:
  4K7 is a 4.7K ohm resistor
  47K is a 47K ohm resistor
  FNS is the original FN switch
    S is a new switch
    = is a capacitor
    G is a ground and AGND
  ENC is the Rotary Encoder (A/G/B) with Push Button (C/G).

NOte: The Encoder Push Button switch (pins C/G) is parallel with btn7, if desired,
      one or the other switches can be deleted of left in parallel.

Note: The Encoder pins A and B, can be exchanged to reverse the Encoders electrical rotation.


ENCODER04 is available as a User Option within the current Rev (ERB_IL) of Minima Alternate Tuning Method at:


--

Thursday, October 16, 2014

Minima - Encoder, Two Implementions

After several days of work, I think I now have a working set of Encoder Routines that are usable for the Minima. Testing has been done by several builders.

The first routine: Encoder01, uses a polling analog read (non interrupt) to detect the Encoder switch changes and is not listed below.

The second routine; Encoder02, is usable for the builders that have moved to an I2C LCD and therefore have two dedicated microprocessor pins to connect to the Encoder pins A and B.

The third routine; Encoder03, is usable for builders that continue to use the parallel LCD and therefore do NOT have dedicated pins to connect to the Encoder. The previous Analog Tuning Pin and the FN Pin are used as shown in the suggested multi-switch schematic.

Selecting which Encoder routines are used, is done via a Optional Configuration selection in the "A1Config.h" file, by un-commenting the selected Encoder.



//#define USE_POT_KNOB  1 // 2304b - Option to include POT support
//#define USE_ENCODER01 1 // 2220b - Option to include Simple Encoder01 support
//#define USE_ENCODER02 1 // 2610b - Option to include FULL Two Digital Pin ISR Encoder02 support
  #define USE_ENCODER03 1 // 2604b - Option to include ISR Encoder03 support On Tuning Pin


Now that the details are work out, the Encoder supporting routines are short and simple. Each containing the "tigger" debounce timers as suggested by the author of the PinChange Library. Yes, it is called "tigger", because everyone knows tiggers bounce, as in Winnie-the-Pooh.

Some unnecessary detail are left out of these listing, check the GitHub for the actual code.

For Encoder02, these routines are used:



#include "PinChangeInt.h"

volatile int knob;

// ###############################################################################
void encoderISR() {
    int pin = ENC_B_PIN;
    static unsigned long startTime = 0;
    unsigned long tigermillis;
    uint8_t oldSREG = SREG;

    cli();
    tigermillis = millis();
    SREG = oldSREG; 
    if (tigermillis-startTime <= ISR_DEBOUNCE_TIMEOUT) return;
    startTime=tigermillis;
    
    knob += digitalRead(ENC_B_PIN) ? -1 : +1;
}

// ###############################################################################
void initEncoder() {
    int pin = ENC_A_PIN;
     
    pinMode(ENC_A_PIN, INPUT_PULLUP);
    pinMode(ENC_B_PIN, INPUT_PULLUP);
    
    PCintPort::attachInterrupt(pin, &encoderISR, FALLING);
}

// ###############################################################################
int getEncoderDir() {
    char tmp = knob;
      
    if (tmp>0) {uint8_t oldSREG = SREG; cli(); knob--; SREG = oldSREG; return +1;}      
    if (tmp<0) {uint8_t oldSREG = SREG; cli(); knob++; SREG = oldSREG; return -1;}
    return 0;
}


For Encoder03, these routines are used:



#include "PinChangeInt.h"

volatile char knob;

// ###############################################################################
void encoderISR() {
    int pin = ENC_B_PIN;

    static unsigned long startTime = 0;
    unsigned long tigermillis;  
    uint8_t oldSREG = SREG;

    cli();
    tigermillis = millis();
    SREG = oldSREG;   
    if (tigermillis-startTime <= ISR_DEBOUNCE_TIMEOUT) return;
    startTime=tigermillis;
        
    knob += analogRead(pin) < 440 ? -1 : +1;
}

// ###############################################################################
void initEncoder() {
    int pin = ENC_A_PIN;
      
    pinMode(ENC_A_PIN, INPUT_PULLUP);

    PCintPort::attachInterrupt(pin, &encoderISR, FALLING);
}

// ###############################################################################
int getEncoderDir() {
    char tmp = knob;

    if (tmp>0) {uint8_t oldSREG = SREG; cli(); knob--; SREG = oldSREG; return +1;}
    if (tmp<0) {uint8_t oldSREG = SREG; cli(); knob++; SREG = oldSREG; return -1;}
    return 0;
}


Notice: Only a few lines are different between the two implementations.


-- Home Page: https://WA0UWH.blogspot.com

Saturday, September 27, 2014

Minima - Proposed Rotary Encoder Circuit

This is just a proposal, the final suggested circuit maybe somewhat different, this is a excerpt, with additions, from a previous post.

My current experimental Encoder software works very smooth with this circuit. Whit a little more testing, it will be published on GitHub soon.

My goal is to be as compatible with the Original Minima as possible.


The following circuit should be added to the Minima to implement a Rotary Encoder and
Multiple Push-Button Switches parallel to the original FN Switch. The original
Tuning POT has been removed to accommodate the Encoder.

--------+
Arduino |
        |
   AVCC |
   pin20|--------+---1K---- +5V
        |        |                       +--------4K7-----+
        |        = 100nF                 |                |
        |        |                       |   +--------+   |
        |        G                       +---|B      C|---+--------------------+
 Tune A2|                              G-----|G  ENC  |                        |
   pin25|--------+---------------------------|A      G|---+                    |
        |        |                           +--------+   |                    |
        |        = 1nF                                    G                    |
        |        |                                                             |
        |        G                                                             |
   AREF |                                                                      |
   pin21|----+-------+                                                         |
        |    |       |                                                         |
        |    |       = 100nF                                                   |
        |    |       |                                                         |
        |    |       G                                                         |
        |   47K                                                                |
        |    |                                                                 |
        |    |                                                                 |
        |    |                                                                 |
    PC3 |    |                                                                 |
   pin26|----+-----+---4K7---+---4K7---+---4K7---+---4K7---+---4K7---+---4K7---+
        |    |     |         |         |         |         |         |         |
        |   FNS    = 1nF     S         S         S         S         S         S
   AGND |    |     |         |         |         |         |         |         |
   pin22|----+-----+---------+---------+---------+---------+---------+---------+
        |    |
--------+    G

            "FN"           "Left"   "Right"   "SBand"     "Up"     "Down"     btn7
           (btn1)          (btn2)    (btn3)   (btn4)     (btn5)    (btn6)    (btn7)


Where:
  4K7 is a 4.7K ohm resistor
  47K is a 47K ohm resistor
  FNS is the original FN switch
    S is a new switch
    = is a capacitor
    G is a ground and AGND
  ENC is the Rotary Encoder with Push Button

Note: The Encoder pins A and B, can be exchanged to reverse the Encoders electrical rotation.

-


More info to follow.

--

Encoder Internals

Just for fun, here are some Rotary Encoder internal details.

Switch Slider and Detent Ball Rotary Switch Mechanism Switch Contacts
Slight Detents can be seen in the edge of the white plastic insulator next to the Detent Ball. The ball is held against the plastic via a spring clip.


-- Home Page: https://WA0UWH.blogspot.com

Friday, September 26, 2014

Minima - With An Encoder

UPDATED: Sep 27, 2014 15:06


An Encoder for the Minima

For the last few days I have been experimenting with three or four implementations to replace the Tuning POT with a Quadrature Encoder (Encoder for short) on the Minima. The implementations range from "Proper" to "Economical". Where "Proper" requires circuit modification and "Most Economical" is 100% compatible with Farhan's original circuit as published. I have experimented and tested each of these solutions, with better than expected results.

The range of solutions each have their pro's and con's.

With exception of adding a simple resistor chain and push-button switches, my overall goals has been to stay compatible (as much as possible) with Farhan's original Minima.

Background
Rotary Encoders

The advantage of a Encoder vs a POT for tuning is that the Encoder does not have "stops" at the extremes, and therefore it is easier to use as re-centering is not necessary.

A typical Encoder internally consists of two switches that turn ON and OFF in sequence when rotated, the sequence can be detected and therefore used to determine the direction of user knob twist.

The switches are connected to Pins Labelled "A" and "B", a third pin "G" is a common to both (normally connect to ground). The switches are normally "open" when the knob is in the detent rest position. Most Encoder also contain a push-button switch labelled "C", which can be used by software to effect mode changes.

Inexpensive ($2 to $5) Encoder are available on Ebay and Electronic Supply houses (Mouser). These inexpensive encoders typically have 16 to 24 detents per knob revolution. Expensive Encoders (>$60) are typically optical and have >200 detents (or pulses) per knob revolution. For the Minima, I suggest the inexpensive Encoders.

I have used Rotary Encoders in several of my previous projects.

Note: for all Encoders, pins "A" and "B" can be connected in reverse to correct direction of rotation.

Now for some proposed implementation details

A Proper Implementation

A "Proper" Encoder circuit requires two (or three, if push-button is used) dedicated I/O line from the microprocessor. At least one of the two lines should be connected to an I/O pin that is configured for Interrupts. When the Encoder is turned, the direction and magnitude can be determined. Software can be written to use this information to change Frequencies, or select Menus, or etc, etc.

Because the original Minima does NOT have extra I/O pin available, modification of the original circuit is necessary to use a "Proper" encoder implementation. To free up some I/O pins, a typical modification include moving the LCD Display to I2C via an inexpensive "BackPack". But this has it own problems, as the Minima currently uses the I2C pins to control the Si570 VFO. The Si570 is a 3.3volt device and the BackPacks are typically a 5.0volt device. The voltage disparity can be alleviated via the addition of a resistor network and/or an I2C Expander (details are not included).

To used this "Proper" configuration, Interrupt Software and Encoder Libraries need to be downloaded and included to be compiled into the Minima Sketch. This included software and libraries uses precious space that could be used for other functionality.

The major advantage is responsiveness of the Encoder and with little or no adverse reaction on other hardware elements. The accumulated magnitude of the interrupts can be used to implement a type of inertia feel, found with normal radio dials.

A Modified Proper Implementation

A modified version of "Proper" implementation is the same as above, except the Interrupt and Encoder Libraries are not used. Software Polling of the Encoder I/O lines is used to get the rotation valuses. On the surface, this may seem unacceptable, but in practice the Sketch's Idle Display Loop is quick enough to display changing digits faster than the eye can see and therefore polling fast enough to be usable.

The disadvantage of this implementation is that Polling is necessary and any stupid delays within the Idle Loop will adversely effect over all performance. Programmed Idle loop delays should be avoided. With polling, magnitude accumulation is slower and therefore it is more difficult to implement an inertia dial feel.

Special code that runs outside of the normal Idle Display Loop has to accommodate Encoder polling. My implementation of Beacons come to mind.

An Economical Implementation

A modified Minima that uses my suggested Resistive Chain Push-button switches can be easily augmented to use an Encoder.

The POT is removed. The "A" pin of the Encoder is connected to the POT's abandoned processor connection (pin A2).  The Encoder's pin "C" (the push-button) is connected across (or replace) button 7.  The Encoder's pin "B" is connected to Encoder pin "C" with a 4.7K ohm resistor.

Note: a better description and diagram will be published later.

This may seem to be a strange configuration, but when the Encoder is being turned, the "FN" button is not typically being used. And, when the "FN" button (or any button) is be pressed the Encoder is not being twisted. Software can detect this and do the right thing.

Experiments, and in practice, has shown that this works very well.

This will probably be my first published implementation. To avoid Interrupt Software and Encoder Libraries, polling software (with its small code space requirement) will be used to detect the Encoder rotation.

The goal will be to eventually publish all implementation with conditional compile flags that the user can select.


The Most Economical Implementation

Farhan's original Minima circuit can be made to work with an Encoder with only slight modification. Similar to above, the POT is removed. The "A" pin of the Encoder is connected to the POT's abandoned processor connection.   The Encoder's pin "C" (the push-button) is connected across the "FN" button.  The Encoder pin "B" pin is connected to Encoder pin "C" with a 4.7K ohm resistor.

This may seem to be a strange configuration, but as stated above, it works.

Software changes are necessary to decode and use this configuration, but the results will be the same as original. Or better yet , the software can be improved to not require re-centering of the dial before reverse tuning can be effected.

Theoretically, an original Minima could be built with only a Display and an Encoder Knob on the face plate, this is because the FN button is contained within the Encoder.

As time permits, and if desired, I may publish this software implementation.

Stay Tuned

More information will follow.


-- Home Page: https://WA0UWH.blogspot.com