#include //WA3TFS six meter FM SDR control software REV 39 (TFS-6FM-SDR-R1-0.ino //JULY 29, 2018 This software may be used for any non-commercial application for amateur radio communications //Specifically written to support the Super Simple WA3TFS 6 meter FM SDR design //Sub-audible tone generation madded May 18, 2018 uint32_t frequency; //The desired frequency must be divided by 50 ex.51.24Mhz = 1024800 uint32_t tword = frequency * 3435973836 / 125000000; //tuning word calculation byte W[5] = {0, 0, 0, 0, 0}; const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); //these are the prescalers for the ADC sampling rate. const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0); const unsigned char PS_16 = (1 << ADPS2); int mic = 512; unsigned long freq; unsigned long tempfreq; unsigned int subtone = 72; //SET THE SUBAUDIBLE TONE FREQUENCY IN HERTZ HERE, May not set exactly but within 1/2 Hertz void setup() { tone(3, 72); //IF YOU DO NOT WANT A SUBAUDIBLE TONE, COMMENT OUT THIS COMMAND DDRB = B00111110; //portb outputs set, PORTB = 0x00; pinMode (A0, INPUT); // here comes the audio frequency in from mic SPI.setDataMode(SPI_MODE0); // set SPI mode 0 SPI.setClockDivider(SPI_CLOCK_DIV2); // set SPI speed SPI.setBitOrder(LSBFIRST); // AD9850 load LSB first SPI.begin(); // set up the ADC ADCSRA &= ~PS_128; // remove bits set by Arduino library ADCSRA |= PS_32; // setting the sampling rate at 16MHz/32 this makes the analogRead() complete in around 40μs Serial.begin(9600); // setup communications with USB port } void loop() { if (Serial.available()) { freq = Serial.parseInt(); } { if (freq >= 50000000 && freq <= 55000000) { tempfreq = (freq / 50); Serial.println("transmit accepted"); // Serial.println(freq); //debug // Serial.println(tempfreq); //debug } else { // do nothing, frequency stays last programmed { } } } { if (tempfreq != 0) { frequency = (tempfreq); //Serial.println (frequency); mic = analogRead(A0); //reading the AF from microphone input signal frequency = frequency + (2.5 * mic) - 450; //1024800 this is the Frequency Modulation. the -329 calibrates frequency. Higher number lowers frequency //EACH NUMBER CHANGES OUTPUT FREQUENCY BY ABOUT 52 HZ. tword = frequency * 1718; //calculating the tuning word for AD9850 W[0] = (byte) tword; W[1] = (byte) (tword >> 8); W[2] = (byte) (tword >> 16); //converting it to bytes W[3] = (byte) (tword >> 24); W[4] = 0; //phase zero //start sending with spi interface PORTB = B00000010; //call out pin 13, PORTB = 0x00; //pulse FU_UD for (int j = 0; j < 5; j++) { SPI.transfer(W[j]); //send the word to DDS } PORTB = B00000100; PORTB = 0x00; //pulse FU_UD } } }