Topics

W8TEE vft/tft questions


tom.mccobb@...
 

I completed  a build of Jack's board a few months ago, and it was working fine. I even made some mods to his code, adding a 4th button press destination from which I could set tuner increments to 50Hz, 100Hz, 1KHz.  (I never had much luck with the encoder speed routines)

All was fine until just recently.  Now when I rotate the encoder, It will pretty much stay in the the same 2KHz range.  If I spin it furiously, I can get it to move erratically up and down the band, but I have obviously broken something.

Which isn't a complete surprise given how many times I have dismantled the unit to change my front panel layout, swap in a SO-359 for the standard antenna jack, replaced the power connector on the W8TEE board to a screw terminal, etc.  I suspect I laid the VFO down on the metal case with some pins touching where they shouldn't have.

So the  question is where to look.  I have checked and verified voltages.  I backed out my modified sketch and reinstalled the original.  I have swapped in several different encoders (I got a bunch of them).  No joy.  The behavior is the same whether it is driven by the USB power connector when disconnected from the Bit40, or the Bit40 power.  (I am feeding it 12v, btw, as the schematic specifies, not the 7-9v in the assembly guide. Is that a problem?).  In all other respects it appears to work - I think - see below.  I have a spare Mega 2560, and as soon as can get headers on it I will swap that in.  

While troubleshooting, I put the outputs on a scope.  The buffered output looks to be about 2.5-3v , and is a nice clean sine wave at about 60 Hz - and it does not change when the encoder is rotated.  The un-buffered output is about the same frequency, but voltage is several orders of magnitude smaller.  And the square wave output is just noise, or at best a very noisy triangle wave.  Does this indicate a problem with the A9850?  (Yes, it could indicate that I don't know what I am doing with the scope, a Tek 2235).

Any pointers?  It is kind of fun troubleshooting, but I would like to get it working again before the end of the decade.

Thanks.


Jack, W8TEE
 

Tom:

If we are talking about the VFO/TFT board, look for the place where we read the encoder. If this is the BITX code, look for the symbolic constant ENCODERTUNING around line 1720. At line 1729, you should see some scaffolding code:

#ifdef DEBUG          
Serial.print("Examine Fast Tune: Start = ");        // May be useful for setting Fast Tune rate
Serial.print(fasttuneStart);
Serial.print("   end = ");
Serial.print(fasttuneEnd);
Serial.print("  diff = ");
Serial.println(fasttuneEnd - fasttuneStart);
#endif   
      

If DEBUG is defined (see line 36) it will print the info out. (If it's commented out with "//", remove those.) This should tell you if the encoder is working and if the Fasttune parts are working.

Jack, W8TEE

On Monday, May 21, 2018, 5:09:08 PM EDT, tom.mccobb@... <tom.mccobb@...> wrote:


I completed  a build of Jack's board a few months ago, and it was working fine. I even made some mods to his code, adding a 4th button press destination from which I could set tuner increments to 50Hz, 100Hz, 1KHz.  (I never had much luck with the encoder speed routines)

All was fine until just recently.  Now when I rotate the encoder, It will pretty much stay in the the same 2KHz range.  If I spin it furiously, I can get it to move erratically up and down the band, but I have obviously broken something.

Which isn't a complete surprise given how many times I have dismantled the unit to change my front panel layout, swap in a SO-359 for the standard antenna jack, replaced the power connector on the W8TEE board to a screw terminal, etc.  I suspect I laid the VFO down on the metal case with some pins touching where they shouldn't have.

So the  question is where to look.  I have checked and verified voltages.  I backed out my modified sketch and reinstalled the original.  I have swapped in several different encoders (I got a bunch of them).  No joy.  The behavior is the same whether it is driven by the USB power connector when disconnected from the Bit40, or the Bit40 power.  (I am feeding it 12v, btw, as the schematic specifies, not the 7-9v in the assembly guide. Is that a problem?).  In all other respects it appears to work - I think - see below.  I have a spare Mega 2560, and as soon as can get headers on it I will swap that in.  

While troubleshooting, I put the outputs on a scope.  The buffered output looks to be about 2.5-3v , and is a nice clean sine wave at about 60 Hz - and it does not change when the encoder is rotated.  The un-buffered output is about the same frequency, but voltage is several orders of magnitude smaller.  And the square wave output is just noise, or at best a very noisy triangle wave.  Does this indicate a problem with the A9850?  (Yes, it could indicate that I don't know what I am doing with the scope, a Tek 2235).

Any pointers?  It is kind of fun troubleshooting, but I would like to get it working again before the end of the decade.

Thanks.


tom.mccobb@...
 

Hi Jack, thanks for answering.

I have been watching the debug code you mentioned, and the output has changed since things went south.

I added some Serial.print statements of my own.  After watching the debug output for a while, I wanted to know what was going on in SetEncoderDirection:

void SetEncoderDirection() {
  encoderDirection = 0;
  newPosition = rotary.read();
 if (newPosition != oldPosition) {
     Serial.print("Old: " );
  Serial.println(oldPosition);
   Serial.print("New: " );
  Serial.println(newPosition);
 }
  if (newPosition != oldPosition) {
    if (newPosition > oldPosition)
      encoderDirection = 1;
    else
      encoderDirection = -1;
    oldPosition = newPosition;
  }
}

...and also here, at the top of your debug block:

#ifdef DEBUG 
 Serial.print("Direction: " );
  Serial.println(encoderDirection);         
Serial.print("Examine Fast Tune: Start = ");        // May be useful for setting Fast Tune rate
Serial.print(fasttuneStart);
Serial.print("   end = ");
Serial.print(fasttuneEnd);
Serial.print("  diff = ");
Serial.println(fasttuneEnd - fasttuneStart);
#endif 

With this in place, I turned the encoder one detent stop, and you see that SetEncoderDirection was called three times.  I kept doing this, slowly, and you can see from the serial monitor output below that even though I am turning the encoder int he same direction, the encoderDirection is variously 1 and -1.  Every 3rd turn the frequency is just not updated at all, but with the vacillating encoderDirection, the freq. goes up 100Hz and down 100Hz.  I thought maybe a bad solder connection was causing a kind of "echo" in the circuit, so I re-flowed the solder to pins 18, 19 and 20.  I have tried a couple of encoders with the debounce caps installed (but who knows, maybe I have a drawer full of bad ones).  I was reading your followup article on encoders and when I got to the end where you suggest always to look for the last thing you think might be wrong, I even changed the connection wires.  Last thing  that I can think of is to swap out the Arduino mini, which I will get to in a day or so (ugh, all those header pins to solder).  If you can suggest anything else, let me know.  Serial output follows:

First turn here:
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 3324   end = 11398  diff = 8074
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 11539   end = 31281  diff = 19742
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 31422   end = 40482  diff = 9060
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 40623   end = 48869  diff = 8246
Old: -1
New: 0


Jack, W8TEE
 

It appears that your encoder sends out 4 pulses on each detent. I'm not where I can test the code, but try something like this:

void SetEncoderDirection() {
    int count = 0;

    encoderDirection = 0;
    
    newPosition = rotary.read();
    if (newPosition == 0)
        return;

   while (count < 4) {        // Ignore 3 readings

      newPosition = rotary.read();
      if (newPosition != oldPosition) {
         if (newPosition > oldPosition)
           encoderDirection = 1;
         else
          encoderDirection = -1;
        oldPosition = newPosition;
     }
    count++;
}

The idea is to throw away all but the last direction read. Like I said, you'll need to play with it. Also, it will be easier to read your debug code if you don't put things on a new line. Use something like:

#ifdef DEBUG
 if (newPosition != oldPosition) {
     Serial.print("In SetEncoderDirection old = " );
     Serial.print(oldPosition);                                        // No newline here
     Serial.print("   new = " );
     Serial.println(newPosition);
 }                                                        // Move this one from here....
#endif

If DEBUG is #defined at the top of the file, the debug statements are compiled into the sketch. Comment the #define DEBUG line, and they are no long in the executable, but still can be turned on again if need be.

Jack, W8TEE

On Wednesday, May 23, 2018, 6:13:07 PM EDT, tom.mccobb@... <tom.mccobb@...> wrote:


Hi Jack, thanks for answering.

I have been watching the debug code you mentioned, and the output has changed since things went south.

I added some Serial.print statements of my own.  After watching the debug output for a while, I wanted to know what was going on in SetEncoderDirection:

void SetEncoderDirection() {
  encoderDirection = 0;
  newPosition = rotary.read();
 if (newPosition != oldPosition) {
     Serial.print("Old: " );
  Serial.println(oldPosition);
   Serial.print("New: " );
  Serial.println(newPosition);
 }                                                        // Move this one from here....
  if (newPosition != oldPosition) {
    if (newPosition > oldPosition)
      encoderDirection = 1;
    else
      encoderDirection = -1;
    oldPosition = newPosition;
  }
}

...and also here, at the top of your debug block:

#ifdef DEBUG 
 Serial.print("Direction: " );
  Serial.println(encoderDirection);         
Serial.print("Examine Fast Tune: Start = ");        // May be useful for setting Fast Tune rate
Serial.print(fasttuneStart);
Serial.print("   end = ");
Serial.print(fasttuneEnd);
Serial.print("  diff = ");
Serial.println(fasttuneEnd - fasttuneStart);
#endif 

With this in place, I turned the encoder one detent stop, and you see that SetEncoderDirection was called three times.  I kept doing this, slowly, and you can see from the serial monitor output below that even though I am turning the encoder int he same direction, the encoderDirection is variously 1 and -1.  Every 3rd turn the frequency is just not updated at all, but with the vacillating encoderDirection, the freq. goes up 100Hz and down 100Hz.  I thought maybe a bad solder connection was causing a kind of "echo" in the circuit, so I re-flowed the solder to pins 18, 19 and 20.  I have tried a couple of encoders with the debounce caps installed (but who knows, maybe I have a drawer full of bad ones).  I was reading your followup article on encoders and when I got to the end where you suggest always to look for the last thing you think might be wrong, I even changed the connection wires.  Last thing  that I can think of is to swap out the Arduino mini, which I will get to in a day or so (ugh, all those header pins to solder).  If you can suggest anything else, let me know.  Serial output follows:

First turn here:
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 3324   end = 11398  diff = 8074
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 11539   end = 31281  diff = 19742
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 31422   end = 40482  diff = 9060
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 40623   end = 48869  diff = 8246
Old: -1
New: 0


Arv Evans
 

There are some encoders that do put out 4 pulses (two sets of A & B pulses) per detent. 
This has been discussed before.  The fix was to make the code swallow two pulses and
use the other 2 pulses. 

Arv
_._


On Wed, May 23, 2018 at 9:00 PM, Jack Purdum via Groups.Io <jjpurdum@...> wrote:
It appears that your encoder sends out 4 pulses on each detent. I'm not where I can test the code, but try something like this:

void SetEncoderDirection() {
    int count = 0;

    encoderDirection = 0;
    
    newPosition = rotary.read();
    if (newPosition == 0)
        return;

   while (count < 4) {        // Ignore 3 readings

      newPosition = rotary.read();
      if (newPosition != oldPosition) {
         if (newPosition > oldPosition)
           encoderDirection = 1;
         else
          encoderDirection = -1;
        oldPosition = newPosition;
     }
    count++;
}

The idea is to throw away all but the last direction read. Like I said, you'll need to play with it. Also, it will be easier to read your debug code if you don't put things on a new line. Use something like:

#ifdef DEBUG
 if (newPosition != oldPosition) {
     Serial.print("In SetEncoderDirection old = " );
     Serial.print(oldPosition);                                        // No newline here
     Serial.print("   new = " );
     Serial.println(newPosition);
 }                                                        // Move this one from here....
#endif

If DEBUG is #defined at the top of the file, the debug statements are compiled into the sketch. Comment the #define DEBUG line, and they are no long in the executable, but still can be turned on again if need be.

Jack, W8TEE

On Wednesday, May 23, 2018, 6:13:07 PM EDT, tom.mccobb@... <tom.mccobb@...> wrote:


Hi Jack, thanks for answering.

I have been watching the debug code you mentioned, and the output has changed since things went south.

I added some Serial.print statements of my own.  After watching the debug output for a while, I wanted to know what was going on in SetEncoderDirection:

void SetEncoderDirection() {
  encoderDirection = 0;
  newPosition = rotary.read();
 if (newPosition != oldPosition) {
     Serial.print("Old: " );
  Serial.println(oldPosition);
   Serial.print("New: " );
  Serial.println(newPosition);
 }                                                        // Move this one from here....
  if (newPosition != oldPosition) {
    if (newPosition > oldPosition)
      encoderDirection = 1;
    else
      encoderDirection = -1;
    oldPosition = newPosition;
  }
}

...and also here, at the top of your debug block:

#ifdef DEBUG 
 Serial.print("Direction: " );
  Serial.println(encoderDirection);         
Serial.print("Examine Fast Tune: Start = ");        // May be useful for setting Fast Tune rate
Serial.print(fasttuneStart);
Serial.print("   end = ");
Serial.print(fasttuneEnd);
Serial.print("  diff = ");
Serial.println(fasttuneEnd - fasttuneStart);
#endif 

With this in place, I turned the encoder one detent stop, and you see that SetEncoderDirection was called three times.  I kept doing this, slowly, and you can see from the serial monitor output below that even though I am turning the encoder int he same direction, the encoderDirection is variously 1 and -1.  Every 3rd turn the frequency is just not updated at all, but with the vacillating encoderDirection, the freq. goes up 100Hz and down 100Hz.  I thought maybe a bad solder connection was causing a kind of "echo" in the circuit, so I re-flowed the solder to pins 18, 19 and 20.  I have tried a couple of encoders with the debounce caps installed (but who knows, maybe I have a drawer full of bad ones).  I was reading your followup article on encoders and when I got to the end where you suggest always to look for the last thing you think might be wrong, I even changed the connection wires.  Last thing  that I can think of is to swap out the Arduino mini, which I will get to in a day or so (ugh, all those header pins to solder).  If you can suggest anything else, let me know.  Serial output follows:

First turn here:
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 3324   end = 11398  diff = 8074
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 11539   end = 31281  diff = 19742
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 31422   end = 40482  diff = 9060
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 40623   end = 48869  diff = 8246
Old: -1
New: 0



Jack, W8TEE
 

I think there is a library that accounts for this, but I don't remember which on it is. A little Google time on the Arduino programming Forum might pay dividends.

Jack, W8TEE

On Thursday, May 24, 2018, 1:11:15 AM EDT, Arv Evans <arvid.evans@...> wrote:


There are some encoders that do put out 4 pulses (two sets of A & B pulses) per detent. 
This has been discussed before.  The fix was to make the code swallow two pulses and
use the other 2 pulses. 

Arv
_._


On Wed, May 23, 2018 at 9:00 PM, Jack Purdum via Groups.Io <jjpurdum@...> wrote:
It appears that your encoder sends out 4 pulses on each detent. I'm not where I can test the code, but try something like this:

void SetEncoderDirection() {
    int count = 0;

    encoderDirection = 0;
    
    newPosition = rotary.read();
    if (newPosition == 0)
        return;

   while (count < 4) {        // Ignore 3 readings

      newPosition = rotary.read();
      if (newPosition != oldPosition) {
         if (newPosition > oldPosition)
           encoderDirection = 1;
         else
          encoderDirection = -1;
        oldPosition = newPosition;
     }
    count++;
}

The idea is to throw away all but the last direction read. Like I said, you'll need to play with it. Also, it will be easier to read your debug code if you don't put things on a new line. Use something like:

#ifdef DEBUG
 if (newPosition != oldPosition) {
     Serial.print("In SetEncoderDirection old = " );
     Serial.print(oldPosition);                                          // No newline here
     Serial.print("   new = " );
     Serial.println(newPosition);
 }                                                         // Move this one from here....
#endif

If DEBUG is #defined at the top of the file, the debug statements are compiled into the sketch. Comment the #define DEBUG line, and they are no long in the executable, but still can be turned on again if need be.

Jack, W8TEE

On Wednesday, May 23, 2018, 6:13:07 PM EDT, tom.mccobb@... <tom.mccobb@...> wrote:


Hi Jack, thanks for answering.

I have been watching the debug code you mentioned, and the output has changed since things went south.

I added some Serial.print statements of my own.  After watching the debug output for a while, I wanted to know what was going on in SetEncoderDirection:

void SetEncoderDirection() {
  encoderDirection = 0;
  newPosition = rotary.read();
 if (newPosition != oldPosition) {
     Serial.print("Old: " );
  Serial.println(oldPosition);
   Serial.print("New: " );
  Serial.println(newPosition);
 }                                                         // Move this one from here....
  if (newPosition != oldPosition) {
    if (newPosition > oldPosition)
      encoderDirection = 1;
    else
      encoderDirection = -1;
    oldPosition = newPosition;
  }
}

...and also here, at the top of your debug block:

#ifdef DEBUG 
 Serial.print("Direction: " );
  Serial.println( encoderDirection);         
Serial.print("Examine Fast Tune: Start = ");        // May be useful for setting Fast Tune rate
Serial.print(fasttuneStart);
Serial.print("   end = ");
Serial.print(fasttuneEnd);
Serial.print("  diff = ");
Serial.println(fasttuneEnd - fasttuneStart);
#endif 

With this in place, I turned the encoder one detent stop, and you see that SetEncoderDirection was called three times.  I kept doing this, slowly, and you can see from the serial monitor output below that even though I am turning the encoder int he same direction, the encoderDirection is variously 1 and -1.  Every 3rd turn the frequency is just not updated at all, but with the vacillating encoderDirection, the freq. goes up 100Hz and down 100Hz.  I thought maybe a bad solder connection was causing a kind of "echo" in the circuit, so I re-flowed the solder to pins 18, 19 and 20.  I have tried a couple of encoders with the debounce caps installed (but who knows, maybe I have a drawer full of bad ones).  I was reading your followup article on encoders and when I got to the end where you suggest always to look for the last thing you think might be wrong, I even changed the connection wires.  Last thing  that I can think of is to swap out the Arduino mini, which I will get to in a day or so (ugh, all those header pins to solder).  If you can suggest anything else, let me know.  Serial output follows:

First turn here:
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 3324   end = 11398  diff = 8074
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 11539   end = 31281  diff = 19742
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 31422   end = 40482  diff = 9060
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 40623   end = 48869  diff = 8246
Old: -1
New: 0



tom.mccobb@...
 

Turned out to be a combination of the encoder sending out 4 pulses, AND a bad 2560.  As soon as I swapped out the Arduino, all was well, and the code change made tuning behave better than ever.

Thanks for everyone's input.

Jack:  I have (and continue to) enjoyed Arduino Projects for Ham Radio.


John P
 

If I remember correctly, the rotary library I use in my projects has a symbol that allows you to only recognize pulses for each detent or to also recognise intermediate pulses. Not at the computer now, but if you look at my code for the antenna analyzer that will point you to the specific library. 
--
John - WA2FZW


Jack, W8TEE
 

Thanks!!

Jack, W8TEE

On Sunday, May 27, 2018, 8:21:11 PM EDT, <tom.mccobb@...> wrote:


Turned out to be a combination of the encoder sending out 4 pulses, AND a bad 2560.  As soon as I swapped out the Arduino, all was well, and the code change made tuning behave better than ever.

Thanks for everyone's input.

Jack:  I have (and continue to) enjoyed Arduino Projects for Ham Radio.


John P
 

To follow up on my post from last night, the "Rotary" library I've been using is from "// https://github.com/brianlow/Rotary"; I think this is the same one Jack used in his antenna analyzer code.

In the "Rotary.h" file for that library, you will find:

    // Enable this to emit codes twice per step.
    // #define HALF_STEP

or, I suppose you can define the symbol in your own code. When "HALF_STEP" is defined, the encoder will generate an interrupt at each detent and halfway in between. If the symbol is not defined, the encoder will only generate interrupts on the detents.

--
John - WA2FZW


tom.mccobb@...
 

Thanks for this.  I downloaded the code and will take a look.