Skip to content

Commit

Permalink
Big steps tuning (resolves #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
camilstaps committed Apr 11, 2017
1 parent 3460cfd commit 4de8adf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 43 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ On startup, the band will be shown (e.g. `bn.20`). After a 1s delay, the rig
will turn on.

### Tuning
Use the rotary encoder to tune. The default step is 50Hz. By pressing the
rotary encoder, the step can be changed to 200Hz. Pressing again goes back to
50Hz. These steps can be changed in `settings.h`.
Use the rotary encoder to tune. Tuning can be done in steps of 50Hz, 200Hz,
1kHz and 10kHz. Rotate through these steps by pressing the rotary encoder. For
all steps except 50Hz, the corresponding digit on the display will blink.

### RIT
Pressing the RIT button turns RIT on. The display will show the RIT offset.
Expand Down Expand Up @@ -94,9 +94,6 @@ There are several compile-time settings in `settings.h`. Change them before
uploading the code to the chip.

- `WPM_DEFAULT`: the default key speed in WPM (20).
- `TUNE_STEP_DEFAULT`: the default tune step (50Hz) in mHz.
- `TUNE_STEP_ALT`: the alternative tune step (200Hz), enabled by pressing the
rotary encoder.
- `KEY_MIN_SPEED`: the minimum key speed in WPM (5). Lower speeds than 5 may
damage the rig, because the on-time for dashes will be rather long.
- `KEY_MAX_SPEED`: the maximum key speed in WPM (30). Higher speeds than 30 are
Expand Down Expand Up @@ -157,6 +154,7 @@ Some images of the connections:
- Fixed a bug with entering memory
- Minor changes to the display
- Made several things settings (see `settings.h`)
- Big steps tuning (issue [#3](issues/3))
- 2017-04-04:
- Added bands up to 10m and enabled run-time band switching
- Fixed rotary encoder issues
Expand Down
4 changes: 4 additions & 0 deletions SODA_POP/SODA_POP.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct soda_pop {
unsigned long rit_tx_freq;

unsigned char rit:1;
unsigned char tuning_step:2;

struct display display;
struct inputs inputs;
Expand All @@ -47,6 +48,9 @@ static unsigned long tcount;

static char buffer[MEMORY_LENGTH];

const long tuning_steps[] = {5000, 20000, 100000, 1000000};
const byte tuning_blinks[] = {BLINK_NONE, BLINK_0, BLINK_1, BLINK_2};

#define TX_FREQ(state) (state.rit ? state.rit_tx_freq : state.op_freq)

#define SIDETONE_ENABLE() {tone(A2, SIDETONE_FREQ);}
Expand Down
45 changes: 15 additions & 30 deletions SODA_POP/SODA_POP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,6 @@ Si5351 si5351;
#define SLED2 11
#define SLED1 12

const byte LED_DIGITS[] =
{ LED_N_0, LED_N_1, LED_N_2, LED_N_3, LED_N_4
, LED_N_5, LED_N_6, LED_N_7, LED_N_8, LED_N_9};

//flag definitions

#define CSflag B00000001
#define SK_EN 0x10
#define MEM_EN 0x80
#define MEM_EN_CL 0x7f
#define UPflag 0x01
#define DWNflag 0x02

#define R_sw 6
#define K_sw 7
#define E_sw 2
#define SK_FG 4

#define SI5351_CLK_RX SI5351_CLK0
#define SI5351_CLK_TX SI5351_CLK1

Expand All @@ -81,6 +63,10 @@ const byte LED_DIGITS[] =

#define IF_DEFAULT 491480000

const byte LED_DIGITS[] =
{ LED_N_0, LED_N_1, LED_N_2, LED_N_3, LED_N_4
, LED_N_5, LED_N_6, LED_N_7, LED_N_8, LED_N_9};

// register names
byte memory_pointer;

Expand All @@ -89,10 +75,6 @@ const int TXEN = 13; // production A0
const int DASHin = A0;
const int DOTin = A1;

//frequency tuning
int stepSize; // tuning rate pointer
long int stepK; // temp storage of freq tuning step

unsigned long IFfreq;
long cal_value = 15000;

Expand Down Expand Up @@ -144,8 +126,7 @@ void setup()

cal_data(); //load calibration data
si5351.set_correction(cal_value); //correct the clock chip error
stepK = TUNE_STEP_DEFAULT;
stepSize = 0;
state.tuning_step = 0;
setup_band();
invalidate_display();
delay(1000);
Expand All @@ -156,6 +137,8 @@ void setup()

if (digitalRead(DASHin) == LOW)
state.key.mode = KEY_STRAIGHT;

state.display.blinking = BLINK_1;
}

void loop()
Expand Down Expand Up @@ -188,9 +171,9 @@ void loop_default()
state.state = S_KEYING;
// Tuning with the rotary encoder
} else if (rotated_up()) {
freq_adjust(stepK);
freq_adjust(tuning_steps[state.tuning_step]);
} else if (rotated_down()) {
freq_adjust(-((int) stepK));
freq_adjust(-tuning_steps[state.tuning_step]);
} else if (state.inputs.encoder_button) {
nextFstep();
debounce_encoder_button();
Expand Down Expand Up @@ -304,6 +287,7 @@ void loop_mem_enter_wait()
if (state.inputs.keyer || state.key.mode != KEY_IAMBIC) {
state.state = S_DEFAULT;
invalidate_display();
morse(MX);
debounce_keyer();
} else if (key_active()) {
state.state = S_MEM_ENTER;
Expand Down Expand Up @@ -443,7 +427,7 @@ void loop_calibration_peak_rx()
}

// adjust the operating frequency
void freq_adjust(int step)
void freq_adjust(long step)
{
state.op_freq += step;
if (state.op_freq > BAND_LIMITS_HIGH[state.band])
Expand All @@ -457,9 +441,10 @@ void freq_adjust(int step)
//toggle tuning step rate
void nextFstep()
{
stepSize = (stepSize + 1) % 2;
stepK = stepSize ? TUNE_STEP_ALT : TUNE_STEP_DEFAULT;
toggle_digit(0);
state.tuning_step++;
if (state.tuning_step >= sizeof(tuning_steps))
state.tuning_step = 0;
invalidate_display();
}

/*
Expand Down
7 changes: 7 additions & 0 deletions SODA_POP/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
#include "SODA_POP.h"
#include "segments.h"

#define BLINK_NONE 0
#define BLINK_0 1
#define BLINK_1 2
#define BLINK_2 3
#define BLINK_3 4

struct display {
byte digits[4];
byte dots:4;
byte blinking:3;
};

void display_isr(void);
Expand Down
20 changes: 16 additions & 4 deletions SODA_POP/display.ino
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
#include "display.h"

volatile byte digit_counter = 0;

#define BLINKED_ON ((((byte) tcount) >> 7) & 0x01)

void display_isr()
{
digit_counter = (digit_counter + 1) % 4;

PORTD = 0x00;

switch(digit_counter) {
case 0:
PORTD = state.display.digits[0];
if (state.display.blinking != BLINK_0 || BLINKED_ON)
PORTD = state.display.digits[0];
digitalWrite(SLED1, LOW);
break;

case 1:
PORTD = state.display.digits[1];
if (state.display.blinking != BLINK_1 || BLINKED_ON)
PORTD = state.display.digits[1];
digitalWrite(SLED2, LOW);
break;

case 2:
PORTD = state.display.digits[2];
if (state.display.blinking != BLINK_2 || BLINKED_ON)
PORTD = state.display.digits[2];
digitalWrite(SLED3, LOW);
break;

case 3:
if (state.display.digits[3] == LED_N_0)
state.display.digits[3] = 0x00; //blank MSD if 0
PORTD = state.display.digits[3];
if (state.display.blinking != BLINK_3 || BLINKED_ON)
PORTD = state.display.digits[3];
digitalWrite(SLED4, LOW);
break;
}
Expand All @@ -43,6 +52,7 @@ void disable_display()

void invalidate_display()
{
state.display.blinking = BLINK_NONE;
switch (state.state) {
case S_DEFAULT:
case S_KEYING:
Expand Down Expand Up @@ -167,6 +177,7 @@ void display_rit()
state.display.digits[0] = LED_DIGITS[(offset % 1000) / 100];

state.display.dots = 0x2;
state.display.blinking = tuning_blinks[state.tuning_step];
}

void display_freq()
Expand All @@ -179,6 +190,7 @@ void display_freq()
state.display.digits[1] = LED_DIGITS[(frequency % 10000) / 1000];
state.display.digits[0] = LED_DIGITS[(frequency % 1000) / 100];
state.display.dots = 0x2;
state.display.blinking = tuning_blinks[state.tuning_step];
}

void display_band()
Expand Down
3 changes: 0 additions & 3 deletions SODA_POP/settings.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#define WPM_DEFAULT 20 // Initial paddle speed in WPM

#define TUNE_STEP_DEFAULT 5000 // Initial tune step in centi-Hz (5000 = 50Hz)
#define TUNE_STEP_ALT 20000 // Alternative tune step

#define KEY_MIN_SPEED 5 // Minimal speed in WPM
#define KEY_MAX_SPEED 30 // Maximal speed in WPM

Expand Down

0 comments on commit 4de8adf

Please sign in to comment.