Last active
August 29, 2015 14:03
-
-
Save ibanezmatt13/18ca088154f6012073f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <util/crc16.h> | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdarg.h> | |
#include <SPI.h> | |
#include <avr/pgmspace.h> | |
#include "ax25modem.h" | |
static const uint8_t PROGMEM _sine_table[] = { | |
#include "sine_table.h" | |
}; | |
/* CONFIGURABLE BITS */ | |
#define APRS_TX_INTERVAL 120000 // APRS TX Interval | |
#define RADIO_POWER 0x07 | |
/* | |
0x02 5db (3mW) | |
0x03 8db (6mW) | |
0x04 11db (12mW) | |
0x05 14db (25mW) | |
0x06 17db (50mW) | |
0x07 20db (100mW) | |
*/ | |
#define HX1_ENABLE 5 | |
#define HX1_TXD 9 | |
#define BAUD_RATE (1200) | |
#define TABLE_SIZE (512) | |
#define PREAMBLE_BYTES (25) | |
#define REST_BYTES (5) | |
#define PLAYBACK_RATE (F_CPU / 256) | |
#define SAMPLES_PER_BAUD (PLAYBACK_RATE / BAUD_RATE) | |
#define PHASE_DELTA_1200 (((TABLE_SIZE * 1200L) << 7) / PLAYBACK_RATE) | |
#define PHASE_DELTA_2200 (((TABLE_SIZE * 2200L) << 7) / PLAYBACK_RATE) | |
#define PHASE_DELTA_XOR (PHASE_DELTA_1200 ^ PHASE_DELTA_2200) | |
char txstring[80]; | |
volatile static uint8_t *_txbuf = 0; | |
volatile static uint8_t _txlen = 0; | |
volatile int txstatus=1; | |
volatile int txstringlength=0; | |
volatile char txc; | |
volatile int txi; | |
volatile int txj; | |
volatile boolean lockvariables = 0; | |
_txbuf = "NORMAN PRICE\n" | |
void setup() { | |
pinMode(HX1_ENABLE, OUTPUT); | |
digitalWrite(HX1_ENABLE, LOW); | |
wait(500); | |
initialise_interrupt(); | |
ISR(TIMER2_OVF_vect) | |
{ | |
static uint16_t phase = 0; | |
static uint16_t step = PHASE_DELTA_1200; | |
static uint16_t sample = 0; | |
static uint8_t rest = PREAMBLE_BYTES + REST_BYTES; | |
static uint8_t byte; | |
static uint8_t bit = 7; | |
static int8_t bc = 0; | |
/* Update the PWM output */ | |
OCR2B = pgm_read_byte(&_sine_table[(phase >> 7) & 0x1FF]); | |
phase += step; | |
if(++sample < SAMPLES_PER_BAUD) return; | |
sample = 0; | |
/* Zero-bit insertion */ | |
if(bc == 5) | |
{ | |
step ^= PHASE_DELTA_XOR; | |
bc = 0; | |
return; | |
} | |
/* Load the next byte */ | |
if(++bit == 8) | |
{ | |
bit = 0; | |
if(rest > REST_BYTES || !_txlen) | |
{ | |
if(!--rest) | |
{ | |
/* Disable radio and interrupt */ | |
//PORTA &= ~TXENABLE; | |
TIMSK2 &= ~_BV(TOIE2); | |
/* Prepare state for next run */ | |
phase = sample = 0; | |
step = PHASE_DELTA_1200; | |
rest = PREAMBLE_BYTES + REST_BYTES; | |
bit = 7; | |
bc = 0; | |
return; | |
} | |
/* Rest period, transmit ax.25 header */ | |
byte = 0x7E; | |
bc = -1; | |
} | |
else | |
{ | |
/* Read the next byte from memory */ | |
byte = *(_txbuf++); | |
if(!--_txlen) rest = REST_BYTES + 2; | |
if(bc < 0) bc = 0; | |
} | |
} | |
/* Find the next bit */ | |
if(byte & 1) | |
{ | |
/* 1: Output frequency stays the same */ | |
if(bc >= 0) bc++; | |
} | |
else | |
{ | |
/* 0: Toggle the output frequency */ | |
step ^= PHASE_DELTA_XOR; | |
if(bc >= 0) bc = 0; | |
} | |
byte >>= 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment