Moved to 20MHz clock, 2400 baud implemented

This commit is contained in:
Mark Qvist 2019-01-01 20:34:02 +01:00
parent 874689c602
commit 43724186c9
7 changed files with 48 additions and 36 deletions

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -7,7 +7,6 @@
#include <stdio.h>
#include <avr/pgmspace.h>
#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
#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
#if CONFIG_SAMPLERATE == 19200
#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
#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
#if CONFIG_SAMPLERATE == 19200
int8_t delayBuf[SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO
//int8_t delayBuf[3 + 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

4
main.c
View File

@ -2,12 +2,12 @@
#include <avr/io.h>
#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;

View File

@ -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) {

View File

@ -2,7 +2,6 @@
#define UTIL_TIME_H
#include <util/atomic.h>
#include "device.h"
#define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor))
#define CLOCK_TICKS_PER_SEC CONFIG_SAMPLERATE