Friday, 13 November 2020

Go QRP Portable SSB Rig

 


IF Amplifiers (1st and 2nd)







VFO, BFO Frequencies and AF Amplifier





LPF after RF PA


Receive-Transmit Switching



Microphone Amplifier





Arduino Code


#include <si5351.h>

static const uint32_t bandStart = 3500000;          // start of VFO range
static const uint32_t bandEnd =   3900000;          // end of VFO range
static const uint32_t bandInit =  3690000;          // where to initially set the frequency
volatile uint32_t freq = 3690000;                   // this is a variable (changes) - set it to the beginning of the band
volatile uint32_t LSB_BFO_freq = 10748550;          // High side injection thus SB inversion.
volatile uint32_t USB_BFO_freq = 10751450;          // High side injection thus SB inversion.
volatile uint32_t radix = 10;                       // How much to change the frequency by, clicking the Up Down switches
volatile uint32_t previousMillis = 0;
volatile uint32_t currentMillis = 0;
static const uint32_t Mode_Display_Delay = 2000;    // Mode display update period = 1.5secs
static const int ModeSw = 4;
static const int UpSw = 3;
static const int DownSw = 2;
static const int PTTInput = A0;
static const int led = 13;
volatile int Mode = 1;                              // 1=3690, 2=NI, 3=SI
volatile int LSB = 1;                               // 3690=LSB, NI=USB, SI=USB
volatile int TX = 0;                                // Current PTT status
volatile int oldTX = 0;                             // Old PTT status

// Instantiate the Objects
Si5351 si5351;

void setup()
{
  // Set up frequency and mode switches
  pinMode(ModeSw, INPUT);
  pinMode(UpSw, INPUT);
  pinMode(DownSw, INPUT);
  pinMode(PTTInput, INPUT);
  pinMode(led, OUTPUT);

  // set up pull-up resistors on inputs
  digitalWrite(ModeSw, HIGH);
  digitalWrite(UpSw, HIGH);
  digitalWrite(DownSw, HIGH);
  digitalWrite(PTTInput, LOW);
  digitalWrite(led, LOW);

  // Initialize the Si5351
  si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
  si5351.set_correction(9000, SI5351_PLL_INPUT_XO);      // Set to specific Si5351 calibration number
  si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
  si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA);
  si5351.drive_strength(SI5351_CLK2, SI5351_DRIVE_8MA);
  SendFrequency();
}

void loop()
{
  // Check PTT
  TX = digitalRead(PTTInput);
  if (TX != oldTX)
  {
    SendFrequency();
    oldTX = TX;
  }

  // Check Mode and Freq change switches
  if (digitalRead(ModeSw) == LOW)
  {
    delay(50);
    if (digitalRead(ModeSw) == LOW)
    {
      Mode = Mode + 1;                            // 1=3690, 2=NI, 3=SI
      if (Mode == 4)
      {
        Mode = 1;                                 // Go QRP freq
        freq = 3690000;                           // Reset freq to 3690kHz
        LSB = 1;                                  // LSB
      }
      if (Mode == 2)                              // North Island MRS freq
      {
        freq = 3345000;                           // Reset freq to 3345kHz
        LSB = 0;                                  // USB
      }
      if (Mode == 3)                              // South Island MRS freq
      {
        freq = 3261000;                           // Reset freq to 3261kHz
        LSB = 0;                                  // USB
      }

      SendFrequency();
      delay(200);
    }
  }

  if (digitalRead(UpSw) == LOW)
  {
    delay(50);                                              // Debounce
    if ((digitalRead(UpSw) == LOW) && (Mode == 1))          // Only allow changes to Go QRP freq
    {
      freq = constrain(freq + radix, bandStart, bandEnd);
      SendFrequency();
      delay(200);
    }
  }

  if (digitalRead(DownSw) == LOW)
  {
    delay(50);                                              // Debounce
    if ((digitalRead(DownSw) == LOW) && (Mode == 1))        // Only allow changes to Go QRP freq
    {
      freq = constrain(freq - radix, bandStart, bandEnd);
      SendFrequency();
      delay(200);
    }
  }

  // Check to see if it's time to flash the LED
  currentMillis = millis();
  if ((currentMillis - previousMillis) >= Mode_Display_Delay)
  {
    previousMillis = currentMillis;
    if (Mode == 1)
      if (freq == 3690000)
        Display3690();                // Only blink is freq = 3690kHz
    if (Mode == 2)
      DisplayNI();
    if (Mode == 3)
      DisplaySI();
  }
}

void Display3690()                    // One long flash
{
  digitalWrite(led, HIGH);
  delay(250);
  digitalWrite(led, LOW);
}

void DisplayNI()                      // Flash N in morse (-.)
{
  digitalWrite(led, HIGH);
  delay(250);
  digitalWrite(led, LOW);
  delay(100);
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led, LOW);
}

void DisplaySI()                      // Flash S in morse (...)
{
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led, LOW);
  delay(175);
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led, LOW);
  delay(175);
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led, LOW);
}

void SendFrequency()
{
  if (Mode == 1)                                                          // 3690kHz LSB
  {
    if (TX == 1)                                                          // Transmit
    {
      si5351.set_freq(((LSB_BFO_freq + freq) * 100ULL), SI5351_CLK2);     // VFO
      si5351.set_freq((LSB_BFO_freq * 100ULL), SI5351_CLK0);              // BFO
    }
    else                                                                  // Receive
    {
      si5351.set_freq(((LSB_BFO_freq + freq) * 100ULL), SI5351_CLK0);     // VFO
      si5351.set_freq((LSB_BFO_freq * 100ULL), SI5351_CLK2);              // BFO
    }
  }

  if ((Mode == 2) || (Mode == 3))                                         // NI or SI USB
  {
    if (TX == 1)                                                          // Transmit
    {
      si5351.set_freq(((USB_BFO_freq + freq) * 100ULL), SI5351_CLK2);     // VFO
      si5351.set_freq((USB_BFO_freq * 100ULL), SI5351_CLK0);              // BFO
    }
    else                                                                  // Receive
    {
      si5351.set_freq(((USB_BFO_freq + freq) * 100ULL), SI5351_CLK0);     // VFO
      si5351.set_freq((USB_BFO_freq * 100ULL), SI5351_CLK2);              // BFO
    }
  }
}











No comments:

Post a comment