mirror of
https://github.com/markqvist/OpenModem.git
synced 2025-06-07 14:22:48 -04:00
Work on sample rate independency
This commit is contained in:
parent
3fb4c30604
commit
f285ae8cc0
4 changed files with 30 additions and 30 deletions
4
device.h
4
device.h
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
// Sampling & timer setup
|
// Sampling & timer setup
|
||||||
#define CONFIG_SAMPLERATE 19200UL
|
#define CONFIG_SAMPLERATE 19200UL
|
||||||
|
//#define CONFIG_SAMPLERATE 19200UL
|
||||||
//#define CONFIG_SAMPLERATE 9600
|
//#define CONFIG_SAMPLERATE 9600
|
||||||
|
|
||||||
// Serial settings
|
// Serial settings
|
||||||
|
@ -21,6 +22,9 @@
|
||||||
#define SERIAL_DEBUG false
|
#define SERIAL_DEBUG false
|
||||||
#define TX_MAXWAIT 2UL
|
#define TX_MAXWAIT 2UL
|
||||||
|
|
||||||
|
// CSMA Settings
|
||||||
|
#define CONFIG_CSMA_P 255
|
||||||
|
|
||||||
// Port settings
|
// Port settings
|
||||||
#if TARGET_CPU == m1284p
|
#if TARGET_CPU == m1284p
|
||||||
#define ADC_PORT PORTA
|
#define ADC_PORT PORTA
|
||||||
|
|
|
@ -256,7 +256,7 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
||||||
// In this comparison we also detect when no transmission
|
// In this comparison we also detect when no transmission
|
||||||
// (or silence) is taking place, and the demodulator
|
// (or silence) is taking place, and the demodulator
|
||||||
// returns an endless stream of zeroes. Due to the NRZ-S
|
// returns an endless stream of zeroes. Due to the NRZ-S
|
||||||
// coding, the actual bits send to this function will
|
// coding, the actual bits sent to this function will
|
||||||
// be an endless stream of ones, which this AND operation
|
// be an endless stream of ones, which this AND operation
|
||||||
// will also detect.
|
// will also detect.
|
||||||
if ((hdlc->demodulatedBits & HDLC_RESET) == HDLC_RESET) {
|
if ((hdlc->demodulatedBits & HDLC_RESET) == HDLC_RESET) {
|
||||||
|
@ -549,13 +549,18 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
|
||||||
|
|
||||||
ISR(ADC_vect) {
|
ISR(ADC_vect) {
|
||||||
TIFR1 = _BV(ICF1);
|
TIFR1 = _BV(ICF1);
|
||||||
|
|
||||||
|
//DAC_PORT ^= 0xFF;
|
||||||
|
//DAC_PORT = ADCH;
|
||||||
|
|
||||||
AFSK_adc_isr(AFSK_modem, (ADCH - 128));
|
AFSK_adc_isr(AFSK_modem, (ADCH - 128));
|
||||||
|
|
||||||
if (hw_afsk_dac_isr) {
|
if (hw_afsk_dac_isr) {
|
||||||
DAC_PORT = AFSK_dac_isr(AFSK_modem);
|
DAC_PORT = AFSK_dac_isr(AFSK_modem);
|
||||||
LED_TX_ON();
|
LED_TX_ON();
|
||||||
} else {
|
} else {
|
||||||
DAC_PORT = 128;
|
DAC_PORT = 127;
|
||||||
|
LED_TX_OFF();
|
||||||
}
|
}
|
||||||
|
|
||||||
++_clock;
|
++_clock;
|
||||||
|
|
|
@ -39,8 +39,8 @@ inline static uint8_t sinSample(uint16_t i) {
|
||||||
|
|
||||||
#define CPU_FREQ F_CPU
|
#define CPU_FREQ F_CPU
|
||||||
|
|
||||||
#define CONFIG_AFSK_RX_BUFLEN 64
|
#define CONFIG_AFSK_RX_BUFLEN CONFIG_SAMPLERATE/150
|
||||||
#define CONFIG_AFSK_TX_BUFLEN 64
|
#define CONFIG_AFSK_TX_BUFLEN CONFIG_SAMPLERATE/150
|
||||||
#define CONFIG_AFSK_RXTIMEOUT 0
|
#define CONFIG_AFSK_RXTIMEOUT 0
|
||||||
#define CONFIG_AFSK_TXWAIT 0UL
|
#define CONFIG_AFSK_TXWAIT 0UL
|
||||||
#define CONFIG_AFSK_PREAMBLE_LEN 350UL
|
#define CONFIG_AFSK_PREAMBLE_LEN 350UL
|
||||||
|
@ -50,33 +50,25 @@ inline static uint8_t sinSample(uint16_t i) {
|
||||||
#define BITRATE 1200
|
#define BITRATE 1200
|
||||||
#define SAMPLESPERBIT (CONFIG_SAMPLERATE / BITRATE)
|
#define SAMPLESPERBIT (CONFIG_SAMPLERATE / BITRATE)
|
||||||
#define TICKS_BETWEEN_SAMPLES ((((CPU_FREQ+FREQUENCY_CORRECTION)) / CONFIG_SAMPLERATE) - 1)
|
#define TICKS_BETWEEN_SAMPLES ((((CPU_FREQ+FREQUENCY_CORRECTION)) / CONFIG_SAMPLERATE) - 1)
|
||||||
#define PHASE_INC 1 // Nudge by an eigth of a sample each adjustment
|
|
||||||
|
|
||||||
#define DCD_MIN_COUNT 6
|
// TODO: Calculate based on sample rate
|
||||||
#define DCD_TIMEOUT_SAMPLES 96
|
#define PHASE_INC SAMPLESPERBIT/8 // Nudge by an eigth of a sample each adjustment
|
||||||
|
#define PHASE_BITS 8 // How much to increment phase counter each sample
|
||||||
#if BITRATE == 960
|
|
||||||
#define FILTER_CUTOFF 600
|
|
||||||
#define MARK_FREQ 960
|
|
||||||
#define SPACE_FREQ 1600
|
|
||||||
#define PHASE_BITS 10 // How much to increment phase counter each sample
|
|
||||||
#elif BITRATE == 1200
|
|
||||||
#define FILTER_CUTOFF 600
|
|
||||||
#define MARK_FREQ 1200
|
|
||||||
#define SPACE_FREQ 2200
|
|
||||||
#define PHASE_BITS 8
|
|
||||||
#elif BITRATE == 1600
|
|
||||||
#define FILTER_CUTOFF 800
|
|
||||||
#define MARK_FREQ 1600
|
|
||||||
#define SPACE_FREQ 2600
|
|
||||||
#define PHASE_BITS 8
|
|
||||||
#else
|
|
||||||
#error Unsupported bitrate!
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PHASE_MAX (SAMPLESPERBIT * PHASE_BITS) // Resolution of our phase counter = 64
|
#define PHASE_MAX (SAMPLESPERBIT * PHASE_BITS) // Resolution of our phase counter = 64
|
||||||
#define PHASE_THRESHOLD (PHASE_MAX / 2) // Target transition point of our phase window
|
#define PHASE_THRESHOLD (PHASE_MAX / 2) // Target transition point of our phase window
|
||||||
|
|
||||||
|
#define DCD_TIMEOUT_SAMPLES CONFIG_SAMPLERATE/100
|
||||||
|
#define DCD_MIN_COUNT CONFIG_SAMPLERATE/1600
|
||||||
|
|
||||||
|
#if BITRATE == 1200
|
||||||
|
#define FILTER_CUTOFF 600
|
||||||
|
#define MARK_FREQ 1200
|
||||||
|
#define SPACE_FREQ 2200
|
||||||
|
#else
|
||||||
|
#error Unsupported bitrate!
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct Hdlc
|
typedef struct Hdlc
|
||||||
{
|
{
|
||||||
uint8_t demodulatedBits;
|
uint8_t demodulatedBits;
|
||||||
|
@ -146,7 +138,7 @@ typedef struct Afsk
|
||||||
#define AFSK_DAC_INIT() do { DAC_DDR |= 0xFF; } while (0)
|
#define AFSK_DAC_INIT() do { DAC_DDR |= 0xFF; } while (0)
|
||||||
|
|
||||||
// Here's some macros for controlling the RX/TX LEDs
|
// Here's some macros for controlling the RX/TX LEDs
|
||||||
// THE _INIT() functions writes to the DDRB register
|
// THE _INIT() functions writes to the DDR registers
|
||||||
// to configure the pins as output pins, and the _ON()
|
// to configure the pins as output pins, and the _ON()
|
||||||
// and _OFF() functions writes to the PORT registers
|
// and _OFF() functions writes to the PORT registers
|
||||||
// to turn the pins on or off.
|
// to turn the pins on or off.
|
||||||
|
|
|
@ -18,7 +18,7 @@ unsigned long custom_preamble = CONFIG_AFSK_PREAMBLE_LEN;
|
||||||
unsigned long custom_tail = CONFIG_AFSK_TRAILER_LEN;
|
unsigned long custom_tail = CONFIG_AFSK_TRAILER_LEN;
|
||||||
|
|
||||||
unsigned long slotTime = 200;
|
unsigned long slotTime = 200;
|
||||||
uint8_t p = 63;
|
uint8_t p = CONFIG_CSMA_P;
|
||||||
|
|
||||||
void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser) {
|
void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser) {
|
||||||
ax25ctx = ax25;
|
ax25ctx = ax25;
|
||||||
|
@ -55,7 +55,6 @@ void kiss_csma(AX25Ctx *ctx, uint8_t *buf, size_t len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!sent) {
|
while (!sent) {
|
||||||
//puts("Waiting in CSMA");
|
|
||||||
if(!channel->hdlc.dcd) {
|
if(!channel->hdlc.dcd) {
|
||||||
uint8_t tp = rand() & 0xFF;
|
uint8_t tp = rand() & 0xFF;
|
||||||
if (tp < p) {
|
if (tp < p) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue