2016-08-13 21:05:19 +00:00
|
|
|
/* Hamshield
|
|
|
|
* Example: PSK31Transmit
|
|
|
|
* This is a simple example to demonstrate HamShield PSK31
|
|
|
|
* transmit functionality.
|
|
|
|
* Connect the HamShield to your Arduino. Screw the antenna
|
|
|
|
* into the HamShield RF jack. Connect the Arduino to wall
|
|
|
|
* power and then to your computer via USB. After uploading
|
2016-08-26 21:40:47 +00:00
|
|
|
* this program to your Arduino, tune a PSK31 receiver and
|
2016-08-13 21:05:19 +00:00
|
|
|
* wait to receive the message "Why hello there, friend.
|
|
|
|
* Nice to meet you. Welcome to PSK31. 73, VE6SLP sk"
|
|
|
|
*/
|
|
|
|
|
2015-07-03 00:06:57 +00:00
|
|
|
#include <HamShield.h>
|
2016-08-17 19:24:36 +00:00
|
|
|
#include <DDS.h>
|
2015-07-03 00:06:57 +00:00
|
|
|
#include "varicode.h"
|
|
|
|
|
2015-11-23 16:54:10 +00:00
|
|
|
#define PWM_PIN 3
|
|
|
|
#define RESET_PIN A3
|
|
|
|
#define SWITCH_PIN 2
|
|
|
|
|
2015-07-03 00:06:57 +00:00
|
|
|
DDS dds;
|
|
|
|
|
|
|
|
void setup() {
|
2015-11-23 16:54:10 +00:00
|
|
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
|
|
pinMode(PWM_PIN, OUTPUT);
|
|
|
|
digitalWrite(PWM_PIN, LOW);
|
|
|
|
|
|
|
|
// prep the switch
|
|
|
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
|
|
|
|
|
|
// set up the reset control pin
|
|
|
|
pinMode(RESET_PIN, OUTPUT);
|
|
|
|
digitalWrite(RESET_PIN, HIGH);
|
|
|
|
|
2015-07-03 00:06:57 +00:00
|
|
|
Serial.begin(9600);
|
|
|
|
// put your setup code here, to run once:
|
2015-07-03 01:58:54 +00:00
|
|
|
dds.setReferenceClock(32000);
|
2015-07-03 00:06:57 +00:00
|
|
|
dds.start();
|
|
|
|
dds.setFrequency(1000);
|
|
|
|
dds.on();
|
|
|
|
}
|
|
|
|
|
|
|
|
volatile bool sent = true;
|
|
|
|
volatile uint16_t bitsToSend = 0;
|
|
|
|
volatile uint8_t zeroCount = 0;
|
|
|
|
|
|
|
|
void sendChar(uint8_t c) {
|
|
|
|
uint16_t bits = varicode[c];
|
|
|
|
while((bits&0x8000)==0) {
|
|
|
|
bits<<=1;
|
|
|
|
}
|
|
|
|
while(!sent) {} //delay(32);
|
|
|
|
cli();
|
|
|
|
sent = false;
|
|
|
|
bitsToSend = bits;
|
|
|
|
sei();
|
|
|
|
while(!sent) {} //delay(32);
|
|
|
|
//PORTD &= ~_BV(2); // Diagnostic pin (D2)
|
|
|
|
}
|
|
|
|
|
|
|
|
char *string = "Why hello there, friend. Nice to meet you. Welcome to PSK31. 73, VE6SLP sk\r\n";
|
|
|
|
void loop() {
|
|
|
|
int i;
|
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|
//for(i = 0; i<5; i++)
|
|
|
|
// sendChar(0);
|
|
|
|
// return;
|
|
|
|
for(i = 0; i < strlen(string); i++) {
|
|
|
|
sendChar(string[i]);
|
2015-07-03 01:58:54 +00:00
|
|
|
//Serial.println(string[i]);
|
2015-07-03 00:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-03 01:31:16 +00:00
|
|
|
const uint8_t amplitudeShape[41] = {
|
|
|
|
255, 241, 228, 215, 203, 191, 181, 171, 161, 152, 143, 135, 128, 121, 114, 107, 101, 96, 90, 85, 80, 76, 72, 68, 64, 60, 57, 54, 51, 48, 45, 42, 40, 38, 36, 34, 32, 30, 28, 27, 25
|
|
|
|
};
|
|
|
|
|
2015-07-03 00:06:57 +00:00
|
|
|
// This will trigger at 8kHz
|
|
|
|
ISR(ADC_vect) {
|
2015-07-03 01:58:54 +00:00
|
|
|
static uint8_t outer = 0;
|
2015-07-03 00:06:57 +00:00
|
|
|
static uint8_t tcnt = 0;
|
|
|
|
TIFR1 |= _BV(ICF1);
|
|
|
|
// Wave shaping
|
2015-07-03 01:31:16 +00:00
|
|
|
// TODO: Improve how this would perform.
|
|
|
|
//else if(tcnt > (255-64))
|
|
|
|
// dds.setAmplitude((255 - tcnt));
|
|
|
|
//else dds.setAmplitude(255);
|
2015-07-03 01:58:54 +00:00
|
|
|
if(tcnt < 81)
|
|
|
|
dds.setAmplitude(amplitudeShape[(81-tcnt)/2]);
|
|
|
|
if(tcnt > (255-81))
|
|
|
|
dds.setAmplitude(amplitudeShape[(tcnt-174)/2]);
|
2015-07-03 00:06:57 +00:00
|
|
|
dds.clockTick();
|
2015-11-23 16:54:10 +00:00
|
|
|
//PORTD &= ~_BV(2);
|
2015-07-03 01:58:54 +00:00
|
|
|
if(outer++ == 3) {
|
|
|
|
outer = 0;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-03 00:06:57 +00:00
|
|
|
if(tcnt++ == 0) { // Next bit
|
|
|
|
//PORTD ^= _BV(2); // Diagnostic pin (D2)
|
|
|
|
if(!sent) {
|
|
|
|
if((bitsToSend & 0x8000) == 0) {
|
|
|
|
zeroCount++;
|
|
|
|
dds.changePhaseDeg(+180);
|
|
|
|
} else {
|
|
|
|
zeroCount = 0;
|
|
|
|
}
|
|
|
|
bitsToSend<<=1;
|
|
|
|
if(zeroCount == 2) {
|
|
|
|
sent = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Idle on zeroes
|
|
|
|
dds.changePhaseDeg(+180);
|
|
|
|
}
|
|
|
|
}
|
2015-11-23 16:54:10 +00:00
|
|
|
//PORTD &= ~_BV(2);
|
2015-07-03 00:06:57 +00:00
|
|
|
}
|