Today, I tackled interrupts. I’m not so sure I tackled interrupts, so much as i worked on determining the dynamic tuning step timing.

I needed a routine to wait for an encoder pulse, and then determine how long since the last pulse.  This isn’t too bad, but the previous attempt was sampling loop timing more than pulse timing.  There’s still some pulse timing limitations – but it’s a lot better.

//PIN's definition
#define encoder0PinA 2
#define encoder0PinB 3

volatile int encoder0Pos = 0;
volatile int oldPos = 0;
volatile boolean PastA = 0;
volatile boolean PastB = 0;

// millis() returns an unsigned long.
unsigned long previousMillis=0;
unsigned long currentMillis;

void setup()
    Serial.print("Hello World");

    pinMode(encoder0PinA, INPUT);
    pinMode(encoder0PinB, INPUT);

    //initial value of channel A;
    PastA = (boolean)digitalRead(encoder0PinA);
    //and channel B
    PastB = (boolean)digitalRead(encoder0PinB);

    // enc A chan on interrupt 0 (Ard pin 2)
    attachInterrupt(0, doEncoderA, RISING);
    // enc B chan pin on interrupt 1 (Ard pin 3)
    attachInterrupt(1, doEncoderB, CHANGE);

void loop()
    if(encoder0Pos != oldPos)

void changed()
    Serial.print(" - ");
    previousMillis = currentMillis;
    oldPos = encoder0Pos;

void doEncoderA()
    //If PastB then --, else ++
    PastB ? encoder0Pos--: encoder0Pos++;
    currentMillis = micros(); // grab current time

void doEncoderB()
    PastB = !PastB;

As is obvious, this was originally written around sampling at the millisecond level, but I changed it to microseconds, to give better resolution.

as of now, it looks like my times are (note:  times updated after mounting the encoder in a proper enclosure, and actually attaching the weighted FT1000 knob):

Slow (1 Hz):  Time >80,000
Medium (10 Hz):  10,000< Time < 80,000
Fast (100 Hz):  Time < 10,000

and I’ll ditch tuning faster than 100 Hz with this project – if you want to get to the band edge that quickly, do it manually, or with the radio knob!