#include //WA3TFS six meter FM SDR control software REV 39 adapted for ten meters //SEPTEMBER 10,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 for 10 meters //Sub-audible tone generation madded May 18, 2018, disabled in this version long 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 long newfreq; //unsigned int subtone = 72; //SET THE SUBAUDIBLE TONE FREQUENCY IN HERTZ HERE, May not set exactly but within 1/2 Hertz // define our event codes const byte BUTTON_PUSH_EVENT = 1; // push a button const byte BUTTON_HOLD_EVENT = 2; // hold a button down for 5 seconds const byte ENCODER_TURN_EVENT = 3; // the encoder was turned // these are the event code and parameter generated by our I/O code byte _event = 0; int _eventParam; int _ms; // our main timing variable instead of using millis() directly. See comments in main loop. volatile byte _encoderCount = 0; // used by interupt code to communicate encoder rotation to main loop // encoder speed setting. 1 = maximum speed, 2 = half speed etc. This should only be set to a power of 2. byte _encoderSpeed = 1; void setup() { //tone(3, subtone); //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 = newfreq; } { if (freq >= 28500000 && freq <= 29700000) { 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); //tone (3, 72); mic = analogRead(A0); //reading the AF from microphone input signal frequency = frequency + (2.5 * mic) - 2187; //this is the Frequency Modulation. the -2060 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 } } } // // NORMAL mode. This is the normal "turn the dial and the frequency changes" mode // void NormalMode() { switch(_event) { case ENCODER_TURN_EVENT: // encoder was turned _frequency += ((long) _eventParam) * _frequencyStep; // adjust the frequency by the amount the encoder moved // _frequency = RestrictFrequency(_frequency); // restrict the frequency to the allowable range //SetDDSFrequency(); // set the DDS to the new frequency // PrintFrequency(_frequency); // print the new frequency //_frequencyHasChanged = true; // remember that te frequency has changed so we can save it to EEPROM later break; case BUTTON_PUSH_EVENT: // a button was pressed switch(_eventParam) { case 1: SetMode(TRANS_MODE); // move to QRSS mode break; case 2: SetMode(SILENT_MODE); // turn the output off. break; case 3: IncrementFrequencyStep(); // change the frequency step PrintFrequencyStep(); // print the new frequency step break; } break; } }