From 43724186c90fa18fba27ec641c4e0071120b2519 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 1 Jan 2019 20:34:02 +0100 Subject: [PATCH] Moved to 20MHz clock, 2400 baud implemented --- Makefile | 4 ++-- device.h | 6 +----- hardware/AFSK.c | 7 +++---- hardware/AFSK.h | 50 +++++++++++++++++++++++++++++++++---------------- main.c | 4 ++-- protocol/KISS.c | 12 ++++++------ util/time.h | 1 - 7 files changed, 48 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index bba5319..6c016ec 100755 --- a/Makefile +++ b/Makefile @@ -276,10 +276,10 @@ program: $(TARGET).hex $(TARGET).eep @$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ %.eep: %.elf -# @echo + @echo # @echo $(MSG_EEPROM) $@ # @echo Not generating any EEPROM images - @-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ +# @-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ # Create extended listing file from ELF output file. %.lss: %.elf diff --git a/device.h b/device.h index 5af98e2..bd5d29b 100755 --- a/device.h +++ b/device.h @@ -5,17 +5,13 @@ // CPU settings #define TARGET_CPU m1284p -#define F_CPU 16000000UL +#define F_CPU 20000000UL #define FREQUENCY_CORRECTION 0 // ADC settings #define OPEN_SQUELCH true #define ADC_REFERENCE REF_3V3 -// Sampling & timer setup -#define CONFIG_SAMPLERATE 19200UL -//#define CONFIG_SAMPLERATE 9600UL - // Serial settings #define BAUD 115200 #define SERIAL_DEBUG false diff --git a/hardware/AFSK.c b/hardware/AFSK.c index 01bf84f..a45afb3 100755 --- a/hardware/AFSK.c +++ b/hardware/AFSK.c @@ -2,10 +2,11 @@ #include "AFSK.h" #include "util/time.h" -// TODO: Remove testing vars +// TODO: Remove testing vars //// #define SAMPLES_TO_CAPTURE 128 ticks_t capturedsamples = 0; uint8_t samplebuf[SAMPLES_TO_CAPTURE]; +///////////////////////////////// extern volatile ticks_t _clock; extern unsigned long custom_preamble; @@ -58,7 +59,7 @@ void AFSK_hw_init(void) { _BV(ADIE) | // ADC Interrupt Enable _BV(ADPS0)| _BV(ADPS2); // Set ADC prescaler bits to 0b101 = 32 - // At 16MHz, this gives an ADC clock of 500 KHz + // At 20MHz, this gives an ADC clock of 625 KHz // Run DAC initialisation AFSK_DAC_INIT(); @@ -388,7 +389,6 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) { #endif #elif CONFIG_SAMPLERATE == 19200 - #if FILTER_CUTOFF == 150 #define IIR_GAIN 2 // Really 2.172813446e #define IIR_POLE 2 // Really Y[0] * 0.9079534415 @@ -571,7 +571,6 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) { } - ISR(ADC_vect) { TIFR1 = _BV(ICF1); diff --git a/hardware/AFSK.h b/hardware/AFSK.h index 312e701..df9a081 100755 --- a/hardware/AFSK.h +++ b/hardware/AFSK.h @@ -7,7 +7,6 @@ #include #include #include "util/FIFO.h" -#include "util/time.h" #include "protocol/HDLC.h" #define SIN_LEN 512 @@ -43,18 +42,29 @@ inline static uint8_t sinSample(uint16_t i) { #define CONFIG_AFSK_TX_BUFLEN CONFIG_SAMPLERATE/150 #define CONFIG_AFSK_RXTIMEOUT 0 #define CONFIG_AFSK_TXWAIT 0UL -#define CONFIG_AFSK_PREAMBLE_LEN 450UL -#define CONFIG_AFSK_TRAILER_LEN 10UL +#define CONFIG_AFSK_PREAMBLE_LEN 150UL +#define CONFIG_AFSK_TRAILER_LEN 25UL #define BIT_STUFF_LEN 5 -#define BITRATE 1200 +#define BITRATE 2400 + +#if BITRATE == 1200 + #define CONFIG_SAMPLERATE 9600UL +#elif BITRATE == 2400 + #define CONFIG_SAMPLERATE 19200UL +#endif + #define SAMPLESPERBIT (CONFIG_SAMPLERATE / BITRATE) #define TICKS_BETWEEN_SAMPLES ((((CPU_FREQ+FREQUENCY_CORRECTION)) / CONFIG_SAMPLERATE) - 1) // TODO: Maybe revert to only looking at two samples #if BITRATE == 1200 - #define SIGNAL_TRANSITIONED(bits) QUAD_XOR((bits), (bits) >> 4) + #if CONFIG_SAMPLERATE == 19200 + #define SIGNAL_TRANSITIONED(bits) QUAD_XOR((bits), (bits) >> 4) + #elif CONFIG_SAMPLERATE == 9600 + #define SIGNAL_TRANSITIONED(bits) DUAL_XOR((bits), (bits) >> 2) + #endif #elif BITRATE == 2400 #define SIGNAL_TRANSITIONED(bits) DUAL_XOR((bits), (bits) >> 2) #endif @@ -68,10 +78,13 @@ inline static uint8_t sinSample(uint16_t i) { // TODO: Test which target is best in real world // For 1200, this seems a little better #if BITRATE == 1200 - #define PHASE_THRESHOLD (PHASE_MAX / 2)+3*PHASE_BITS // Target transition point of our phase window - //#define PHASE_THRESHOLD (PHASE_MAX / 2) // 64 // Target transition point of our phase window + #if CONFIG_SAMPLERATE == 19200 + #define PHASE_THRESHOLD (PHASE_MAX / 2)+3*PHASE_BITS // Target transition point of our phase window + #elif CONFIG_SAMPLERATE == 9600 + #define PHASE_THRESHOLD (PHASE_MAX / 2) // 64 // Target transition point of our phase window + #endif #elif BITRATE == 2400 - #define PHASE_THRESHOLD (PHASE_MAX / 2)+14 // Target transition point of our phase window + #define PHASE_THRESHOLD (PHASE_MAX / 2) // Target transition point of our phase window #endif @@ -80,15 +93,17 @@ inline static uint8_t sinSample(uint16_t i) { // TODO: Revamp filtering #if BITRATE == 1200 - #define FILTER_CUTOFF 600 + #define FILTER_CUTOFF 500 #define MARK_FREQ 1200 #define SPACE_FREQ 2200 #elif BITRATE == 2400 - #define FILTER_CUTOFF 772 - // #define MARK_FREQ 2165 - // #define SPACE_FREQ 3970 - #define MARK_FREQ 2200 - #define SPACE_FREQ 4000 + // TODO: Determine best filter cutoff + // #define FILTER_CUTOFF 772 + #define FILTER_CUTOFF 1000 + #define MARK_FREQ 2165 + #define SPACE_FREQ 3970 + //#define MARK_FREQ 2200 + //#define SPACE_FREQ 4000 #elif BITRATE == 300 #define FILTER_CUTOFF 600 #define MARK_FREQ 1600 @@ -139,8 +154,11 @@ typedef struct Afsk // Demodulation values FIFOBuffer delayFifo; // Delayed FIFO for frequency discrimination #if BITRATE == 1200 - int8_t delayBuf[SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO - //int8_t delayBuf[3 + 1]; // Actual data storage for said FIFO + #if CONFIG_SAMPLERATE == 19200 + int8_t delayBuf[SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO + #elif CONFIG_SAMPLERATE == 9600 + int8_t delayBuf[SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO + #endif #elif BITRATE == 2400 int8_t delayBuf[7 + 1]; // Actual data storage for said FIFO #endif diff --git a/main.c b/main.c index 5ee8f33..526e76d 100755 --- a/main.c +++ b/main.c @@ -2,12 +2,12 @@ #include #include "device.h" -#include "util/FIFO.h" -#include "util/time.h" #include "hardware/AFSK.h" #include "hardware/Serial.h" #include "protocol/AX25.h" #include "protocol/KISS.h" +#include "util/time.h" +#include "util/FIFO.h" Serial serial; Afsk modem; diff --git a/protocol/KISS.c b/protocol/KISS.c index d3511a9..5c5248e 100755 --- a/protocol/KISS.c +++ b/protocol/KISS.c @@ -27,12 +27,12 @@ void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser) { FLOWCONTROL = false; } -// TODO: Revert to actual data -size_t decodes = 0; +// TODO: Remove debug functions +//size_t decodes = 0; void kiss_messageCallback(AX25Ctx *ctx) { - decodes++; - printf("%d\r\n", decodes); - /* + // decodes++; + // printf("%d\r\n", decodes); + fputc(FEND, &serial->uart0); fputc(0x00, &serial->uart0); for (unsigned i = 0; i < ctx->frame_len-2; i++) { @@ -47,7 +47,7 @@ void kiss_messageCallback(AX25Ctx *ctx) { fputc(b, &serial->uart0); } } - fputc(FEND, &serial->uart0);*/ + fputc(FEND, &serial->uart0); } void kiss_csma(AX25Ctx *ctx, uint8_t *buf, size_t len) { diff --git a/util/time.h b/util/time.h index 07398d2..661b05c 100755 --- a/util/time.h +++ b/util/time.h @@ -2,7 +2,6 @@ #define UTIL_TIME_H #include -#include "device.h" #define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor)) #define CLOCK_TICKS_PER_SEC CONFIG_SAMPLERATE