Monday, January 20, 2020

Small update to the Step Attenuator

When I first built the step attenuator,  I wanted it to check  linearity of amplifier stages.  I only needed a relative change in the insertion loss of the attenuator.  Recntly I was able to use my NanoVNA to measure the actual insertion loss across the total frequency range I am interested in.  I also received some questions about showing the actual insertion loss instead of the relative value,

Because of this I made a change to the code to switch the display value from relative to actual by a long press of the encoder knob.


       
 First I added some definitions and variables

float InsertionLoss = 2.6;  //insertion loss of attenuator at 0 dB 
int InLossMode  = 0;       // actual insertion loss or relative
#define ActualLoss  0   // display  value selected actual +                                  //insertion loss 
#define RelLoss     1   // display just value                                                //selected without insertion loss

The code to read the button push was modified to also check for a long press if you want to change display mode to show the actual insertion loss.
  // check button for display mode and step size
  read_btn();
  if (button) {
    if (button == SHORT_PRESS ) { //  toggle step size
      if (AttenStep == 1) AttenStep = 10;
      else AttenStep = 1;
      button = 0;
    }
    else {         // toggle insertion loss display type
      if (InLossMode == ActualLoss) InLossMode = RelLoss ;
      else InLossMode = ActualLoss;
      button = 0;
    }
  }

The display routine was modified to show th display value depnding on the InLossMode variable,

  if (InLossMode == ActualLoss) {    // show actual insertion loss
    display.setTextSize(1);
    display.setCursor(20, 15);
    display.print("Actual  ");       // indicate type 
    display.setTextSize(3);
    display.setCursor(10, 30);       // clear last value
    display.print("       ");
    // update display
    display.setCursor(10, 30);
    display.print( (AttenValue + InsertionLoss), 1) ; 
  }
  else {
    display.setTextSize(1);        // show relative value
    display.setCursor(20, 15);
    display.print("Relative ");    // indicate type 
    display.setTextSize(3);
    display.setCursor(10, 30);
    display.print("       ");      // clear last value
    // update display
    display.setCursor(10, 30);
    display.print( AttenValue, 1);
  }
  // display "dB." 
  display.print( " ");
  display.setTextSize(2);
  display.setCursor(80, 38);
  display.print( " dB.");
  display.display();


Updated code is available at 
https://www.dropbox.com/sh/lwy52lqi0g0ms7g/AAChK1tqW8M4hmUUf_dutwP2a?dl=0


        

2 comments:

  1. Thanks for the update Duwayne. Good idea for including the option for relative values.

    73, Peter

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete