// This application is that of an all HF touch screen digital vfo micro-controller. // The application is designed to control the AD9851 DDS device, of which two such circuits are required. // The 1st I.F. or roofing filter is at 32MHz, the local oscillator vfo runs high from 32MHz to 62MHz, // spanning 30MHz in all.All the ham bands from LF (136KHz) through to 10m (28MHz) are covered, in addition // to a general coverage receiver, where-by the dial display will change from green to yellow. // // As I have not tested this software with a digital vfo, appologise for any errors, constructors need to // sure that the vfo is behaving before transmission. Apart from this, I am not aware of any errors. // Th ekeen eyed amongest you may realise that the button screens are revised touh butons test software // used for the "All HF digital vfo" project. // // Each Ham radio band has a last used recall for the dial frequency, carrier mode and vfo step change. // // The touch screen 3·5" colour display was sourced from "Sainsmart" on the internet, as well as the driver codes. // // The Ham Radio application was written by ALastair GW0AJU: current version date 17th June 2016 // // This program requires the ITDB02_Graph library (8bit mode) // or ITDB02_Graph16 (16bit mode). // // It is assumed that the ITDB02 module is connected to a // ITDB02 Shield, a ITDB02 Mega Shield or that you know how // to change the pin numbers in the setup. // // Remember to change the next line if you are using as 16bit module! #include #include #include // Declare which fonts we will be using extern uint8_t BigFont[]; extern uint8_t SevenSegNumFont[]; // Uncomment the next two lines for the ITDB02 Shield UTFT myGLCD(SSD1289, 38, 39, 40, 41); ITDB02_Touch myTouch(6, 5, 4, 3, 2); // Uncomment the next two lines for the ITDB02 Mega Shield // ITDB02 myGLCD(38,39,40,41); // Remember to add ASPECT_16x9 if you are using an ITDB02-3.2WC! // ITDB02_Touch myTouch(6,5,4,3,2); int x, y; //long rx = 7100250; // radio carrier frequency variable long rx; int line_h = 0; int place = 0; int item = 0; int text_char = 0; int signal_meter = 200; // signal strength meter variable float RST_measure = 0; int sig_number = 0; int db_over_load = 0; int db_over_load_text = 0; int tx_power = 50; // transmitter power output variable int tx_measure = 0; int tx_number = 0; //*********** rotary encoder dial setup ************** int clk_location = 2; int dt_location = 3; //*********** dds vfo setup ************** #define DDS_CLOCK 180E6 // using the AD9851 DDS chip #define CLOCK 9 // W_CLK = Pin 4- connect to AD9850 module word load clock pin (CLK) #define LOAD 10 // FQ_UD = Pin 5 - connect to freq update pin (FQ_UD) #define DATA 11 // DATA = Pin 6 - connect to serial data load pin (AD9850 D7 = DATA) #define RESET 12 // RESET = Pin 7 - connect to DDS reset line //************ dds bfo setup ************* #define CLOCK_bfo 5 // W_CLK = Pin 4- connect to AD9850 module word load clock pin (CLK) #define LOAD_bfo 6 // FQ_UD = Pin 5 - connect to freq update pin (FQ_UD) #define DATA_bfo 7 // DATA = Pin 6 - connect to serial data load pin (AD9850 D7 = DATA) #define RESET_bfo 8 // RESET = Pin 7 - connect to DDS reset line //*************** touch key variables ********** long first = 0; long Second = 0; long third = 0; long fourth = 0; long fifth = 0; long sixth = 0; long seventh = 0; long eigth = 0; long total = 0; long count_number = 0; long entry_number = 0; int end_stop = 1; int test_stop = 1; byte recall_vfo_step = 0x00; byte RF_mode = 0x00; byte RF_step = 0x00; int mod_end_stop = 0; int band_select = 0; int mode_select = 0; int address_mode = 0; // memory for carrier mode set int step_select = 0; int address_step = 0; // memory for vfo step int address_store = 0; int ham_gen = 0; // indicate general coverage mode //*********** arduino uno eeprom setup ************* #include long start_freq; long address; // *************** twi control panel interface bnoard ********** // TWI bus location for the pcf8754 i/o 8bit bus expander chip. int PCF_bfo = 32; // ( 32 = 0x20 ) TWI interface output for bfo demodulation circuits int PCF_switch_low = 33; // ( 33 = 0x21 ) TWI interface for data switch low of HF bands int PCF_switch_high = 34; // ( 34 = 0x22 ) TWI interface for data switch high of HF bands int PCF_tx_rx_switch = 35; // ( 35 = 0x23 ) TWI interface for tx rx switching byte inpRead; //******************** morse key/ptt and tx_rx relay ************** int cw_key_ptt = 13; // pin 13 for cw key / ptt connection int test_cw_key_ptt; int check_cw_key_ptt = HIGH; int test_key = LOW; int tx_rx_label = HIGH; // ******************************************************* int run_once = 1; float result = 0; unsigned long IF_LO; unsigned long freq; unsigned long bfo_freq; long last_Set_vfo; long last_set_bfo; long dial_step; long carrier_centre; float dial_post = 0; int move_dial = 0; int dial_delay_clk = 0; int dial_delay_anti_clk = 0; int dial_delay_movement = 0; int start_line = 0; //**************** SWR bridge and antenna load calculations variables **************** long swr_forward = 0; long swr_reflected = 0; float vswr_forward = 0; float vswr_reflected = 0; float v_forward = 0; float v_reflected = 0; float swr_impedance = 0; float RL = 0; float Zin = 0; float swr =0; float ind = 0; float cap = 0; float cap_scale = 0; float ind_scale = 0; float cap_scale_t = 0; float ind_scale_t = 0; float res = 0; float res_load = 0; //*********** transmitter power variables ************ float rx_signal_level = 0; float rx_signal_voltage = 0; float tx_signal_level = 0; float tx_power_output = 0; //********** start of arduino DDS VFO control program ********* int first_run = 1; //This function will write a 4 byte (32bit) long to the eeprom at //the specified address to address + 3. void EEPROMWritelong(int address, long value) { //Decomposition from a long to 4 bytes by using bitshift. //One = Most significant -> Four = Least significant byte byte four = (value & 0xFF); byte three = ((value >> 8) & 0xFF); byte two = ((value >> 16) & 0xFF); byte one = ((value >> 24) & 0xFF); //Write the 4 bytes into the eeprom memory. EEPROM.write(address, four); EEPROM.write(address + 1, three); EEPROM.write(address + 2, two); EEPROM.write(address + 3, one); } //This function will return a 4 byte (32bit) long from the eeprom //at the specified address to address + 3. long EEPROMReadlong(long address) { //Read the 4 bytes from the eeprom memory. long four = EEPROM.read(address); long three = EEPROM.read(address + 1); long two = EEPROM.read(address + 2); long one = EEPROM.read(address + 3); //Return the recomposed long by using bitshift. return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF); } void setup() { // Initial setup myGLCD.InitLCD(LANDSCAPE); myGLCD.clrScr(); myTouch.InitTouch(LANDSCAPE); myTouch.setPrecision(PREC_MEDIUM); Serial.begin(9600); //*************** initialise the memory on first time boot up ***************** long band_boot_up_freq = 0; address = 0; //Starting at the first byte on the eeprom. band_boot_up_freq = 136500; start_freq = EEPROMReadlong(address); if (start_freq > 136000 && start_freq < 137000) { carrier_centre = EEPROMReadlong(address); } else // if (start_freq < 1800000 && start_freq > 2000000) { EEPROMWritelong(address, band_boot_up_freq ); address = 0; carrier_centre = EEPROMReadlong(address); address_mode = 101; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 201; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 4; band_boot_up_freq = 475000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 470000 && start_freq < 478000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 4; carrier_centre = EEPROMReadlong(address); address_mode = 102; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 202; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 8; band_boot_up_freq = 1830000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 1800000 && start_freq < 2000000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 8; carrier_centre = EEPROMReadlong(address); address_mode = 103; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 203; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 12; band_boot_up_freq = 3640000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 3500000 && start_freq < 3800000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address =12; carrier_centre = EEPROMReadlong(address); address_mode = 104; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 204; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 16; band_boot_up_freq = 5300000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 5500000 && start_freq < 6000000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 16; carrier_centre = EEPROMReadlong(address); address_mode = 105; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 205; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 20; band_boot_up_freq = 7023000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 7000000 && start_freq < 7200000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 20; carrier_centre = EEPROMReadlong(address); address_mode = 106; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 206; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 24; band_boot_up_freq = 10100000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 10000000 && start_freq < 10150000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 24; carrier_centre = EEPROMReadlong(address); address_mode = 107; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 207; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 28; band_boot_up_freq = 14000000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 14000000 && start_freq < 14350000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 28; carrier_centre = EEPROMReadlong(address); address_mode = 108; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 208; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 32; band_boot_up_freq = 18100000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 18060000 && start_freq < 18160000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 32; carrier_centre = EEPROMReadlong(address); address_mode = 109; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 209; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 36; band_boot_up_freq = 21000000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 21000000 && start_freq < 21450000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 36; carrier_centre = EEPROMReadlong(address); address_mode = 110; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 210; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 40; band_boot_up_freq = 24890000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 24890000 && start_freq < 24990000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 40; carrier_centre = EEPROMReadlong(address); address_mode = 111; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 211; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } address = 44; band_boot_up_freq = 28000000; //Starting at the first byte on the eeprom. start_freq = EEPROMReadlong(address); if (start_freq > 28000000 && start_freq < 29700000) { carrier_centre = EEPROMReadlong(address); } else { EEPROMWritelong(address, band_boot_up_freq ); address = 44; carrier_centre = EEPROMReadlong(address); address_mode = 112; EEPROM.write(address_mode, 0x09); // first bootup = CW carreir mode address_step = 212; EEPROM.write(address_step, 0x03); // firts bootup = 10Hz vfo step } myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 0); myGLCD.setColor(0, 255, 0); // green text myGLCD.print("HF coverage",10, 10); myGLCD.print("ham radio",10 ,40); myGLCD.print("By Alastair",10 ,70); myGLCD.print("GW0AJU",10 ,100); delay(1000); //***************** last used memory recall and carrier mode starup ****************** address = 50; // band selection band_select = EEPROM.read(address); address = 49; // vfo step selection step_select = EEPROM.read(address); address = 48; // carrier mode selection mode_select = EEPROM.read(address); Serial.println("address 50 band select = "); Serial.println(band_select,HEX); Serial.println("address 49 vfo step = "); Serial.println(step_select,HEX); Serial.println("address 48 carrier mode = "); Serial.println(mode_select,HEX); myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 0); band_change(); // display ham band chosen dial_frequency(); // display the radio vfo frequency carrier_mode(); // display radio carrier mode vfo_step_change(); // display vfo step rate receiver_signal(); // display the Rx signal meter transmitter_power(); // display the Tx power output and antenna values pinMode(CLOCK, OUTPUT); pinMode(LOAD, OUTPUT); pinMode(DATA, OUTPUT); pinMode(RESET, OUTPUT); pinMode(CLOCK_bfo, OUTPUT); pinMode(LOAD_bfo, OUTPUT); pinMode(DATA_bfo, OUTPUT); pinMode(RESET_bfo, OUTPUT); pinMode( clk_location, INPUT); pinMode( dt_location, INPUT); pinMode(cw_key_ptt, INPUT); AD9850_reset(); AD9850_init(); AD9850_bfo_reset(); AD9850_bfo_init(); } //******************** main loop ******************************************************************************* void loop() { read_touch_screen(); // read touch screen for DDS vfo control systems radio_status(); // to determine the radsio set iniether Tx or Rx mode getEncoderTurn(); // rotary encoder sub-routine for rotary movement of dial setting and vfo update } //*************** start of program code sub-routines *********************************************************** void reprint_graphic_display() { address = 50; // band selection band_select = EEPROM.read(address); address = 49; // vfo step selection step_select = EEPROM.read(address); address = 48; // carrier mode selection mode_select = EEPROM.read(address); myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 0); band_change(); // display ham band chosen dial_frequency(); // display the radio vfo frequency carrier_mode(); // display radio carrier mode vfo_step_change(); // display vfo step rate receiver_signal(); // display the Rx signal meter transmitter_power(); // display the Tx power output and antenna values } void dial_frequency() { rx = carrier_centre; where_on_hf(); if ( band_select != 13) { myGLCD.setColor(0,255 ,0); // green text for ham mode } else { myGLCD.setColor(255,255 , 0); // yellow text for Rx mode } myGLCD.setFont(SevenSegNumFont); myGLCD.printNumI(rx,CENTER, 30); myGLCD.setFont(BigFont); } void read_touch_screen() { test_stop = 0; while ( test_stop == 0) { if (myTouch.dataAvailable()) { myTouch.read(); x=myTouch.getX(); y=myTouch.getY(); if ((y>=190) && (y<=250)) // lower half of screen { if ((x>=10) && (x<=100)) // Button: bottom left side { input_HFband_mode(); // input new HF band setting x=0; y=0; test_stop = 1; } } if ((y>=190) && (y<=250)) // lower half of screen { if ((x>=220) && (x<=320)) // Button: bottom right side { input_radio_carrier(); // set the radio carrier mode x=0; y=0; test_stop = 1; } } if ((y>= 1) && (y<= 50)) // top half left of screen { if ((x>= 5) && ( x<= 100)) // button top left side on frequency display { input_dial_frequency(); // input new frequency routine x=0; y=0; test_stop = 1; } } if ((y>= 1) && (y<= 50)) // top half right of screen { if ((x>= 225) && ( x<= 320)) // button top right side on frequency display { input_freq_step(); // input new vfo step change x=0; y=0; test_stop = 1; } } } test_stop = 1; } } void input_HFband_mode() // select the hf band { myGLCD.clrScr(); draw_band_select(); touch_band_select(); reprint_graphic_display(); } void input_radio_carrier() // select rf carrier mode { myGLCD.clrScr(); draw_carrier_mode(); touch_carrier_mode(); reprint_graphic_display(); } void input_dial_frequency() //input direct frequency { myGLCD.clrScr(); draw_button_keyboard(); touch_key_entry(); where_on_hf(); reprint_graphic_display(); } void input_freq_step() // select vfo step { myGLCD.clrScr(); draw_vfo_step(); touch_vfo_step(); reprint_graphic_display(); } //****************************************** select the hf band ************************************************ void draw_band_select() { myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 255); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(0*60), 10, 60+(0*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(0*60), 10, 60+(0*60), 60); myGLCD.print("LF", 20+(0*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(1*60), 10, 60+(1*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(1*60), 10, 60+(1*60), 60); myGLCD.print("MF", 20+(1*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(2*60), 10, 60+(2*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(2*60), 10, 60+(2*60), 60); myGLCD.print("160", 12+(2*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(3*60), 10, 60+(3*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(3*60), 10, 60+(3*60), 60); myGLCD.print("80", 20+(3*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(4*60), 10, 60+(4*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(4*60), 10, 60+(4*60), 60); myGLCD.print("60", 20+(4*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(0*60), 70, 60+(0*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(0*60), 70, 60+(0*60), 120); myGLCD.print("40", 20+(0*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(1*60), 70, 60+(1*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(1*60), 70, 60+(1*60), 120); myGLCD.print("30", 20+(1*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(2*60), 70, 60+(2*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(2*60), 70, 60+(2*60), 120); myGLCD.print("20", 20+(2*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(3*60), 70, 60+(3*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(3*60), 70, 60+(3*60), 120); myGLCD.print("17", 20+(3*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(4*60), 70, 60+(4*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(4*60), 70, 60+(4*60), 120); myGLCD.print("15", 20+(4*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(0*60), 130, 60+(0*60), 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(0*60), 130, 60+(0*60), 180); myGLCD.print("12", 20+(0*60), 145); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(1*60), 130, 60+(1*60), 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(1*60), 130, 60+(1*60), 180); myGLCD.print("10", 20+(1*60), 145); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(2*60), 130, 60+(2*60), 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(2*60), 130, 60+(2*60), 180); myGLCD.print("Rx", 20+(2*60), 145); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (190, 130, 300, 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (190, 130, 300, 180); myGLCD.print("Cancel", 200, 147); } void touch_band_select() { address_store = 50; mod_end_stop = 0; while ( mod_end_stop == 0 ) { if (myTouch.dataAvailable()) { myTouch.read(); x=myTouch.getX(); y=myTouch.getY(); if ((y>=10) && (y<=60)) // Upper row { if ((x>=10) && (x<=60)) // Button: LF { waitForIt(10, 10, 60, 60); ham_gen = 1; band_select = 1; EEPROM.write(address_store, 0x01); mod_end_stop = 1; address = 0; carrier_centre = EEPROMReadlong(address); address_mode = 101; address_step = 201; x=0; y=0; delay(250); } if ((x>=70) && (x<=120)) // Button: MF { waitForIt(70, 10, 120, 60); ham_gen = 1; band_select = 2; EEPROM.write(address_store, 0x02); mod_end_stop = 1; address = 4; carrier_centre = EEPROMReadlong(address); address_mode = 102; address_step = 202; x=0; y=0; delay(250); } if ((x>=130) && (x<=180)) // Button: 160m { waitForIt(130, 10, 180, 60); ham_gen = 1; band_select = 3; EEPROM.write(address_store, 0x03); mod_end_stop = 1; address = 8; carrier_centre = EEPROMReadlong(address); address_mode = 103; address_step = 203; x=0; y=0; delay(250); } if ((x>=190) && (x<=240)) // Button: 80m { waitForIt(190, 10, 240, 60); ham_gen = 1; band_select = 4; EEPROM.write(address_store, 0x04); mod_end_stop = 1; address = 12; carrier_centre = EEPROMReadlong(address); address_mode = 104; address_step = 204; x=0; y=0; delay(250); } if ((x>=250) && (x<=300)) // Button: 60m { waitForIt(250, 10, 300, 60); ham_gen = 1; band_select = 5; EEPROM.write(address_store, 0x05); mod_end_stop = 1; address = 16; carrier_centre = EEPROMReadlong(address); address_mode = 105; address_step = 205; x=0; y=0; delay(250); } } if ((y>=70) && (y<=120)) // Center row { if ((x>=10) && (x<=60)) // Button: 40m { waitForIt(10, 70, 60, 120); ham_gen = 1; band_select = 6; EEPROM.write(address_store, 0x06); mod_end_stop = 1; address = 20; carrier_centre = EEPROMReadlong(address); address_mode = 106; address_step = 206; x=0; y=0; delay(250); } if ((x>=70) && (x<=120)) // Button: 30m { waitForIt(70, 70, 120, 120); ham_gen = 1; band_select = 7; EEPROM.write(address_store, 0x07); mod_end_stop = 1; address = 24; carrier_centre = EEPROMReadlong(address); address_mode = 107; address_step = 207; x=0; y=0; delay(250); } if ((x>=130) && (x<=180)) // Button: 20m { waitForIt(130, 70, 180, 120); ham_gen = 1; band_select = 8; EEPROM.write(address_store, 0x08); mod_end_stop = 1; address = 28; carrier_centre = EEPROMReadlong(address); address_mode = 108; address_step = 208; x=0; y=0; delay(250); } if ((x>=190) && (x<=240)) // Button: 17m { waitForIt(190, 70, 240, 120); ham_gen = 1; band_select = 9; EEPROM.write(address_store, 0x09); mod_end_stop = 1; address = 32; carrier_centre = EEPROMReadlong(address); address_mode = 109; address_step = 209; x=0; y=0; delay(250); } if ((x>=250) && (x<=300)) // Button: 15m { waitForIt(250, 70, 300, 120); ham_gen = 1; band_select = 10; EEPROM.write(address_store, 0x0A); mod_end_stop = 1; address = 36; carrier_centre = EEPROMReadlong(address); address_mode = 110; address_step = 210; x=0; y=0; delay(250); } } if ((y>=130) && (y<=180)) // bottom row { if ((x>=10) && (x<=60)) // Button: 12m { waitForIt(10, 130, 60, 180); ham_gen = 1; band_select = 11; EEPROM.write(address_store, 0x0B); mod_end_stop = 1; address = 40; carrier_centre = EEPROMReadlong(address); address_mode = 111; address_step = 211; x=0; y=0; delay(250); } if ((x>=70) && (x<=120)) // Button: 10m { waitForIt(70, 130, 120, 180); ham_gen = 1; band_select = 12; EEPROM.write(address_store, 0x0C); mod_end_stop = 1; address = 44; carrier_centre = EEPROMReadlong(address); address_mode = 112; address_step = 212; x=0; y=0; delay(250); } if ((x>=130) && (x<=180)) // Button: Rx = general coverage { waitForIt(130, 130, 180, 180); ham_gen = 0; band_select = 13; EEPROM.write(address_store, 0x0D); mod_end_stop = 1; address = 52; carrier_centre = EEPROMReadlong(address); address_mode = 113; address_step = 213; x=0; y=0; delay(250); } if ((x>=190) && (x<=300)) // Button: cancel { waitForIt(190, 130, 300, 180); band_select = band_select; mod_end_stop = 1; address = address; carrier_centre = EEPROMReadlong(address); address_mode = address_mode; address_step = address_step; x=0; y=0; delay(250); } } } } } void band_change() { int address_store_look_up = 50; byte look_up_band = EEPROM.read(address_store_look_up); myGLCD.setColor(255, 0, 0); myGLCD.setFont(BigFont); if ( band_select == 1 || look_up_band == 0x01) // LF band { address = 0; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" LF Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000001); // LF band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // LF band Wire.endTransmission(); } else if ( band_select == 2 || look_up_band == 0x02) // MF band { address = 4; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" MF Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000010); // MF band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // MF band Wire.endTransmission(); } else if ( band_select == 3 || look_up_band == 0x03) // 160m band { address = 8; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 160m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000100); // 160m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // 160m band Wire.endTransmission(); } else if ( band_select == 4 || look_up_band == 0x04 ) // 80m band { address = 12; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 80m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00001000); // 80m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // 80m band Wire.endTransmission(); } else if ( band_select == 5 || look_up_band == 0x05) // 60m band { address = 16; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 60m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00010000); // 60m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // 60m band Wire.endTransmission(); } else if ( band_select == 6 || look_up_band == 0x06) // 40m band { address = 20; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 40m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00100000); // 40m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // 40m band Wire.endTransmission(); } else if ( band_select == 7 || look_up_band == 0x07) // 30m band { address = 24; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 30m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B01000000); // 30m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // 30m band Wire.endTransmission(); } else if ( band_select == 8 || look_up_band == 0x08) // 20m band { address = 28; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 20m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B10000000); // 20m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000000); // 20m band Wire.endTransmission(); } else if ( band_select == 9 || look_up_band == 0x09) // 17m band { address = 32; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 17m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000000); // 17m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000001); // 17m band Wire.endTransmission(); } else if ( band_select == 10 || look_up_band == 0x0A) // 15m band { address = 36; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 15m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000000); // 15m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000010); // 15m band Wire.endTransmission(); } else if ( band_select == 11 || look_up_band == 0x0B) // 12m band { address = 40; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 12m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000000); // 12m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00000100); // 12m band Wire.endTransmission(); } else if ( band_select == 12 || look_up_band == 0x0C) // 10m band { address = 44; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print(" 10m Ham Band ", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000000); // 10m band Wire.endTransmission(); Wire.beginTransmission(PCF_switch_high); Wire.write(B00001000); // 10m band Wire.endTransmission(); } if (band_select == 13 || look_up_band == 0x0D) // general coverage Rx { address = 52; carrier_centre = EEPROMReadlong(address); sendFrequency(carrier_centre); myGLCD.print("General Receiver", CENTER, 5); RF_mode = EEPROM.read(address_mode); RF_step = EEPROM.read(address_step); Wire.beginTransmission(PCF_switch_low); Wire.write(B00000000); // Rx band Wire.endTransmission(); if ( carrier_centre <= 2E6 ) { Wire.beginTransmission(PCF_switch_high); Wire.write(B00010000); // Rx band MF to 2MHz Wire.endTransmission(); } else if ( carrier_centre > 2E6 && carrier_centre <= 10E6 ) { Wire.beginTransmission(PCF_switch_high); Wire.write(B00100000); // Rx band 2MHZ to 10MHz Wire.endTransmission(); } else if ( carrier_centre > 10E6 && carrier_centre <= 20E6 ) { Wire.beginTransmission(PCF_switch_high); Wire.write(B01000000); // Rx band 10MHZ to 20MHz Wire.endTransmission(); } else if ( carrier_centre > 20E6 && carrier_centre <= 30E6 ) { Wire.beginTransmission(PCF_switch_high); Wire.write(B10000000); // Rx band 20MHZ to 30MHz Wire.endTransmission(); } } } //****************************************************** carrier mode change ********************************************** void draw_carrier_mode() { myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 255); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(0*60), 10, 60+(0*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(0*60), 10, 60+(0*60), 60); myGLCD.print("LSB",12+(0*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(1*60), 10, 60+(1*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(1*60), 10, 60+(1*60), 60); myGLCD.print("USB", 12+(1*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(2*60), 10, 60+(2*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(2*60), 10, 60+(2*60), 60); myGLCD.print("CW", 20+(2*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(3*60), 10, 60+(3*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(3*60), 10, 60+(3*60), 60); myGLCD.print("AM", 20+(3*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(4*60), 10, 60+(4*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(4*60), 10, 60+(4*60), 60); myGLCD.print("FM", 20+(4*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (190, 130, 300, 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (190, 130, 300, 180); myGLCD.print("Cancel", 200, 147); } void touch_carrier_mode () { myGLCD.setColor(255, 255, 255); myGLCD.setFont(BigFont); int carrier_end_stop = 0; while ( carrier_end_stop == 0 ) { if (myTouch.dataAvailable()) { myTouch.read(); x=myTouch.getX(); y=myTouch.getY(); if ((y>=10) && (y<=60)) // Upper row { if ((x>=10) && (x<=60)) // Button: LSB { waitForIt(10, 10, 60, 60); mode_select = 1; carrier_end_stop = 1; address = 48; EEPROM.write(address, B00000001); EEPROM.write(address_mode, 0x01); // to set carrier mode per selected hf band x=0; y=0; delay(250); } if ((x>=70) && (x<=120)) // Button: USB { waitForIt(70, 10, 120, 60); mode_select = 2; carrier_end_stop = 1; address = 48; EEPROM.write(address, B00000010); EEPROM.write(address_mode, 0x02); // to set carrier mode per selected hf band x=0; y=0; delay(250); } if ((x>=130) && (x<=180)) // Button: CW { waitForIt(130, 10, 180, 60); mode_select = 3; carrier_end_stop = 1; address = 48; EEPROM.write(address, B00000100); EEPROM.write(address_mode, 0x03); // to set carrier mode per selected hf band x=0; y=0; delay(250); } if ((x>=190) && (x<=240)) // Button: AM { waitForIt(190, 10, 240, 60); mode_select = 4; carrier_end_stop = 1; address = 48; EEPROM.write(address, B00001000); EEPROM.write(address_mode, 0x04); // to set carrier mode per selected hf band x=0; y=0; delay(250); } if ((x>=250) && (x<=300)) // Button: FM { waitForIt(250, 10, 300, 60); mode_select = 5; carrier_end_stop = 1; address = 48; EEPROM.write(address, B00010000); EEPROM.write(address_mode, 0x05); // to set carrier mode per selected hf band x=0; y=0; delay(250); } } if ((y>=130) && (y<=180)) // bottom row { if ((x>=190) && (x<=300)) // Button: cancel { waitForIt(190, 130, 300, 180); mode_select = mode_select; carrier_end_stop = 1; x=0; y=0; delay(250); } } } } } void carrier_mode() { // 1st roofing IF = 32MHz -- the Local oscillator setting is to place the dial freq reading // to mid channel of the radio relative to the I.F. frequency. myGLCD.setColor(255, 255, 255); myGLCD.setFont(BigFont); address = 48; byte recall_carrier_mode = EEPROMReadlong(address); RF_mode = EEPROM.read(address_mode); // recall rf carrier mode for selected hf band use if (recall_carrier_mode == B00000001 || RF_mode == 0x01)// lsb { IF_LO = (32E6 - (carrier_centre)); // Rx/Tx L.O. output for 32MHz I.F. LSB if (last_Set_vfo != IF_LO) { sendFrequency(IF_LO); last_Set_vfo = IF_LO; myGLCD.print("Mode:LSB", 5, 90); } bfo_freq = (9E6 + 1500); // bfo 9MHz 2nd I.F. SSB crystal filter plus LSB resolve if (last_set_bfo != bfo_freq) { sendFrequency_bfo(bfo_freq); last_set_bfo = bfo_freq; Serial.println("lsb reception"); // error correction message with ide monitor } Wire.beginTransmission(PCF_bfo); Wire.write(B00000001); // LSB Wire.endTransmission(); } else if (recall_carrier_mode == B00000010 || RF_mode == 0x02) // USB { IF_LO = (32E6 - (carrier_centre)); // Rx/Tx L.O. output for 32MHz I.F. USB if (last_Set_vfo != IF_LO) { sendFrequency(IF_LO); last_Set_vfo = IF_LO; myGLCD.print("Mode:USB", 5, 90); } bfo_freq = (9E6 - 1500); // bfo 9MHz 2nd I.F. SSB crystal filter plus USB resolve if (last_set_bfo != bfo_freq) { sendFrequency_bfo(bfo_freq); last_set_bfo = bfo_freq; Serial.println("usb reception"); // error correction message with ide monitor } Wire.beginTransmission(PCF_bfo); Wire.write(B00000010); // USB Wire.endTransmission(); } else if (recall_carrier_mode == B00000100 || RF_mode == 0x03) // CW { IF_LO = (32E6 - (carrier_centre)); // Rx/Tx L.O. output for 32MHz I.F. CW if (last_Set_vfo != IF_LO) { sendFrequency(IF_LO); last_Set_vfo = IF_LO; myGLCD.print("Mode:CW ", 5, 90); } bfo_freq = (9E6 + 600); // bfo 9MHz 2nd I.F. SSB crystal filter plus CW resolve if (last_set_bfo != bfo_freq) { sendFrequency_bfo(bfo_freq); last_set_bfo = bfo_freq; Serial.println("CW reception"); // error correction message with ide monitor } Wire.beginTransmission(PCF_bfo); Wire.write(B00000100); // CW Wire.endTransmission(); } else if (recall_carrier_mode == B00001000 || RF_mode == 0x04) // AM { IF_LO = (32E6 - (carrier_centre)); // Rx/Tx L.O. output for 32MHz I.F. AM if (last_Set_vfo != IF_LO) { sendFrequency(IF_LO); last_Set_vfo = IF_LO; myGLCD.print("Mode:AM ", 5, 90); } bfo_freq = (9E6 - 455E3); // 455KHz 3rd I.F. for AM signal demodulation if (last_set_bfo != bfo_freq) { sendFrequency_bfo(bfo_freq); last_set_bfo = bfo_freq; Serial.println("AM reception"); // error correction message with ide monitor } Wire.beginTransmission(PCF_bfo); Wire.write(B00001000); // AM Wire.endTransmission(); } else if (recall_carrier_mode == B00010000 || RF_mode == 0x05) // FM { IF_LO = (32E6 - (carrier_centre)); // Rx/Tx L.O. output for 32MHz I.F. FM if (last_Set_vfo != IF_LO) { sendFrequency(IF_LO); last_Set_vfo = IF_LO; myGLCD.print("Mode:FM ", 5, 90); } bfo_freq = (9E6 - 455E3); // 455KHz 3rd I.F. for FM signal demodulation if (last_set_bfo != bfo_freq) { sendFrequency_bfo(bfo_freq); last_set_bfo = bfo_freq; Serial.println("FM reception"); // error correction message with ide monitor } Wire.beginTransmission(PCF_bfo); Wire.write(B00010000); // FM Wire.endTransmission(); } dial_post = carrier_centre; // display show centre channel frequency of Radio set operation rx = carrier_centre; } void AD9850_bfo_reset() { //reset sequence is: // CLOCK & LOAD = LOW // Pulse RESET high for a few uS (use 5 uS here) // Pulse CLOCK high for a few uS (use 5 uS here) // Set DATA to ZERO and pulse LOAD for a few uS (use 5 uS here) // data sheet diagrams show only RESET and CLOCK being used to reset the device, but I see no output unless I also // toggle the LOAD line here. digitalWrite(CLOCK_bfo, LOW); digitalWrite(LOAD_bfo, LOW); digitalWrite(RESET_bfo, LOW); delayMicroseconds(5); digitalWrite(RESET_bfo, HIGH); //pulse RESET_bfo delayMicroseconds(5); digitalWrite(RESET_bfo, LOW); delayMicroseconds(5); digitalWrite(CLOCK_bfo, LOW); delayMicroseconds(5); digitalWrite(CLOCK_bfo, HIGH); //pulse CLOCK_bfo delayMicroseconds(5); digitalWrite(CLOCK_bfo, LOW); delayMicroseconds(5); digitalWrite(DATA_bfo, LOW); //make sure DATA_bfo pin is LOW digitalWrite(LOAD_bfo, LOW); delayMicroseconds(5); digitalWrite(LOAD_bfo, HIGH); //pulse LOAD_bfo delayMicroseconds(5); digitalWrite(LOAD_bfo, LOW); // Chip is RESET now } void AD9850_bfo_init() { digitalWrite(RESET_bfo, LOW); digitalWrite(CLOCK_bfo, LOW); digitalWrite(LOAD_bfo, LOW); digitalWrite(DATA_bfo, LOW); } // *********** frequency control of the AD9851 DDS device for TX / Rx vfo ********* void sendFrequency_bfo(unsigned long frequency) { unsigned long tuning_word = (frequency * pow(2, 32)) / DDS_CLOCK; digitalWrite (LOAD_bfo, LOW); shiftOut(DATA_bfo, CLOCK_bfo, LSBFIRST, tuning_word); shiftOut(DATA_bfo, CLOCK_bfo, LSBFIRST, tuning_word >> 8); shiftOut(DATA_bfo, CLOCK_bfo, LSBFIRST, tuning_word >> 16); shiftOut(DATA_bfo, CLOCK_bfo, LSBFIRST, tuning_word >> 24); shiftOut(DATA_bfo, CLOCK_bfo, LSBFIRST, 0x00); digitalWrite(LOAD_bfo, HIGH); } //******************************************** dial frequency entry code ************************************************** void draw_button_keyboard() { myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 255); // Draw the upper row of buttons for (x=0; x<5; x++) { myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(x*60), 10, 60+(x*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(x*60), 10, 60+(x*60), 60); myGLCD.printNumI(x+1, 27+(x*60), 27); } // Draw the center row of buttons for (x=0; x<5; x++) { myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(x*60), 70, 60+(x*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(x*60), 70, 60+(x*60), 120); if (x<4) myGLCD.printNumI(x+6, 27+(x*60), 87); } myGLCD.print("0", 267, 87); // Draw the lower row of buttons myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10, 130, 150, 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10, 130, 150, 180); myGLCD.print("Clear", 40, 147); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (160, 130, 300, 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (160, 130, 300, 180); myGLCD.print("Enter", 190, 147); myGLCD.setBackColor (0, 0, 0); } // Draw a red frame while a button is touched void waitForIt(int x1, int y1, int x2, int y2) { myGLCD.setColor(255, 0, 0); myGLCD.drawRoundRect (x1, y1, x2, y2); while (myTouch.dataAvailable()) myTouch.read(); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (x1, y1, x2, y2); } void touch_key_entry() { end_stop = 0; while ( end_stop == 0 ) { if (myTouch.dataAvailable()) { myTouch.read(); x=myTouch.getX(); y=myTouch.getY(); if ((y>=10) && (y<=60)) // Upper row { if ((x>=10) && (x<=60)) // Button: 1 { waitForIt(10, 10, 60, 60); entry_number = 1; accumlate_number(); x=0; y=0; } if ((x>=70) && (x<=120)) // Button: 2 { waitForIt(70, 10, 120, 60); entry_number = 2; accumlate_number(); x=0; y=0; } if ((x>=130) && (x<=180)) // Button: 3 { waitForIt(130, 10, 180, 60); entry_number = 3; accumlate_number(); } if ((x>=190) && (x<=240)) // Button: 4 { waitForIt(190, 10, 240, 60); entry_number = 4; accumlate_number(); x=0; y=0; } if ((x>=250) && (x<=300)) // Button: 5 { waitForIt(250, 10, 300, 60); entry_number = 5; accumlate_number(); x=0; y=0; } } if ((y>=70) && (y<=120)) // Center row { if ((x>=10) && (x<=60)) // Button: 6 { waitForIt(10, 70, 60, 120); entry_number = 6; accumlate_number(); x=0; y=0; } if ((x>=70) && (x<=120)) // Button: 7 { waitForIt(70, 70, 120, 120); entry_number = 7; accumlate_number(); x=0; y=0; } if ((x>=130) && (x<=180)) // Button: 8 { waitForIt(130, 70, 180, 120); entry_number = 8; accumlate_number(); x=0; y=0; } if ((x>=190) && (x<=240)) // Button: 9 { waitForIt(190, 70, 240, 120); entry_number = 9; accumlate_number(); x=0; y=0; } if ((x>=250) && (x<=300)) // Button: 0 { waitForIt(250, 70, 300, 120); entry_number = 0; accumlate_number(); x=0; y=0; } } if ((y>=130) && (y<=180)) // lower row { if ((x>=10) && (x<=150)) // Button: Clear { waitForIt(10, 130, 150, 180); first = 0; Second = 0; third = 0; fourth = 0; fifth = 0; sixth = 0; seventh = 0; eigth = 0; total = 0; count_number = 0; entry_number = 0; myGLCD.print(" ",LEFT,224); myGLCD.setColor(0, 0, 0); myGLCD.fillRect(0, 224, 319, 239); x=0; y=0; } if ((x>=160) && (x<=300)) // Button: Enter { waitForIt(160, 130, 300, 180); total = 0; count_number = 0; first = 0; Second = 0; third = 0; fourth = 0; fifth = 0; sixth = 0; seventh = 0; eigth = 0; end_stop = 1; } if (count_number == 2) { total = 0; count_number = 0; first = 0; Second = 0; third = 0; fourth = 0; fifth = 0; sixth = 0; seventh = 0; eigth = 0; entry_number = carrier_centre; end_stop = 1; } x=0; y=0; } } } } void accumlate_number() { count_number = count_number + 1; if (count_number == 1) { first = entry_number; carrier_centre = first; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre, 5, 224); } else if (count_number == 2) { Second = entry_number; first = first * 10; carrier_centre = first + Second; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre, 5, 224); } else if (count_number == 3) { third = entry_number; Second = Second * 10; first = first * 10; carrier_centre = first + Second + third; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre, 5, 224); } else if (count_number == 4) { fourth = entry_number; third = third * 10; Second = Second * 10; first = first * 10; carrier_centre = first + Second + third + fourth; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre, 5, 224); } else if (count_number == 5) { fifth = entry_number; fourth = fourth * 10; third = third * 10; Second = Second * 10; first = first * 10; carrier_centre = first + Second + third + fourth + fifth; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre, 5, 224); } else if (count_number == 6) { sixth = entry_number; fifth = fifth * 10; fourth = fourth * 10; third = third * 10; Second = Second * 10; first = first * 10; carrier_centre = first + Second + third + fourth + fifth + sixth; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre, 5, 224); } else if (count_number == 7) { seventh = entry_number; sixth = sixth *10; fifth = fifth * 10; fourth = fourth * 10; third = third * 10; Second = Second * 10; first = first * 10; carrier_centre = first + Second + third + fourth + fifth + sixth + seventh; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre, 5, 224); } else if (count_number == 8) { eigth = entry_number; seventh = seventh * 10; sixth = sixth *10; fifth = fifth * 10; fourth = fourth * 10; third = third * 10; Second = Second * 10; first = first * 10; carrier_centre = first + Second + third + fourth + fifth + sixth + seventh + eigth; myGLCD.print(" ",5,224); myGLCD.printNumI(carrier_centre,5, 224); } } void where_on_hf() { int address_store = 50; ham_gen = 0; if (carrier_centre >= 136000 && carrier_centre <= 137000) { address = 0; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x01); ham_gen = 1; address_mode = 101; RF_mode = EEPROM.read(address_mode); address_step = 201; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 470000 && carrier_centre <= 478000) { address = 4; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x02); ham_gen = 1; address_mode = 102; RF_mode = EEPROM.read(address_mode); address_step = 202; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 1800000 && carrier_centre <= 2000000) { address = 8; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x03); ham_gen = 1; address_mode = 103; RF_mode = EEPROM.read(address_mode); address_step = 203; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 3500000 && carrier_centre <= 3800000) { address = 12; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x04); ham_gen = 1; address_mode = 104; RF_mode = EEPROM.read(address_mode); address_step = 204; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 5200000 && carrier_centre <= 5500000) { address = 16; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x05); ham_gen = 1; address_mode = 105; RF_mode = EEPROM.read(address_mode); address_step = 205; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 7000000 && carrier_centre <= 7200000) { address = 20; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x06); ham_gen = 1; address_mode = 106; RF_mode = EEPROM.read(address_mode); address_step = 206; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 10000000 && carrier_centre <= 10150000) { address = 24; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x07); ham_gen = 1; address_mode = 107; RF_mode = EEPROM.read(address_mode); address_step = 207; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 14000000 && carrier_centre <= 14350000) { address = 28; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x08); ham_gen = 1; address_mode = 108; RF_mode = EEPROM.read(address_mode); address_step = 208; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 18060000 && carrier_centre <= 18160000) { address = 32; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x09); ham_gen = 1; address_mode = 109; RF_mode = EEPROM.read(address_mode); address_step = 209; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 21000000 && carrier_centre <= 21450000) { address = 36; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x0A); ham_gen = 1; address_mode = 110; RF_mode = EEPROM.read(address_mode); address_step = 210; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 24890000 && carrier_centre <= 24990000) { address = 40; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x0B); ham_gen = 1; address_mode = 111; RF_mode = EEPROM.read(address_mode); address_step = 211; RF_step = EEPROM.read(address_step); } if (carrier_centre >= 28000000 && carrier_centre <= 29700000) { address = 44; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x0C); ham_gen = 1; address_mode = 112; RF_mode = EEPROM.read(address_mode); address_step = 212; RF_step = EEPROM.read(address_step); } if ( ham_gen != 1 ) { address = 52; EEPROMWritelong(address,carrier_centre); EEPROM.write(address_store, 0x0D); ham_gen = 0; address_mode = 113; RF_mode = EEPROM.read(address_mode); address_step = 213; RF_step = EEPROM.read(address_step); } } //************************************************ vfo step cahnge code ************************************************ void draw_vfo_step() { myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 255); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(0*60), 10, 60+(0*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(0*60), 10, 60+(0*60), 60); myGLCD.print("5k", 20+(0*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(1*60), 10, 60+(1*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(1*60), 10, 60+(1*60), 60); myGLCD.print("3k", 20+(1*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(2*60), 10, 60+(2*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(2*60), 10, 60+(2*60), 60); myGLCD.print("1k", 20+(2*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(3*60), 10, 60+(3*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(3*60), 10, 60+(3*60), 60); myGLCD.print("500", 12+(3*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(4*60), 10, 60+(4*60), 60); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(4*60), 10, 60+(4*60), 60); myGLCD.print("300", 12+(4*60), 27); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(0*60), 70, 60+(0*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(0*60), 70, 60+(0*60), 120); myGLCD.print("100", 12+(0*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(1*60), 70, 60+(1*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(1*60), 70, 60+(1*60), 120); myGLCD.print("50", 20+(1*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(2*60), 70, 60+(2*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(2*60), 70, 60+(2*60), 120); myGLCD.print("25", 20+(2*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(3*60), 70, 60+(3*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(3*60), 70, 60+(3*60), 120); myGLCD.print("10", 20+(3*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(4*60), 70, 60+(4*60), 120); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(4*60), 70, 60+(4*60), 120); myGLCD.print("5", 25+(4*60), 87); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (10+(0*60), 130, 60+(0*60), 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (10+(0*60), 130, 60+(0*60), 180); myGLCD.print("1", 25+(0*60), 145); myGLCD.setColor(0, 0, 255); myGLCD.fillRoundRect (190, 130, 300, 180); myGLCD.setColor(255, 255, 255); myGLCD.drawRoundRect (190, 130, 300, 180); myGLCD.print("Cancel", 200, 147); } void touch_vfo_step() { myGLCD.setColor(255, 255, 255); myGLCD.setFont(BigFont); int step_end_stop = 0; while ( step_end_stop == 0 ) { if (myTouch.dataAvailable()) { myTouch.read(); x=myTouch.getX(); y=myTouch.getY(); if ((y>=10) && (y<=60)) // Upper row { if ((x>=10) && (x<=60)) // Button: 5KHz step { waitForIt(10, 10, 60, 60); step_select = 1; step_end_stop = 1; address = 49; EEPROM.write(address, 0x01); EEPROM.write(address_step, 0x01); x=0; y=0; delay(250); } if ((x>=70) && (x<=120)) // Button: 3KHz step { waitForIt(70, 10, 120, 60); step_select = 2; step_end_stop = 1; address = 49; EEPROM.write(address, 0x02); EEPROM.write(address_step, 0x02); x=0; y=0; delay(250); } if ((x>=130) && (x<=180)) // Button: 1KHz step { waitForIt(130, 10, 180, 60); step_select = 3; step_end_stop = 1; address = 49; EEPROM.write(address, 0x03); EEPROM.write(address_step, 0x03); x=0; y=0; delay(250); } if ((x>=190) && (x<=240)) // Button: 500Hz step { waitForIt(190, 10, 240, 60); step_select = 4; step_end_stop = 1; address = 49; EEPROM.write(address, 0x04); EEPROM.write(address_step, 0x04); x=0; y=0; delay(250); } if ((x>=250) && (x<=300)) // Button: 300Hz step { waitForIt(250, 10, 300, 60); step_select = 5; step_end_stop = 1; address = 49; EEPROM.write(address, 0x05); EEPROM.write(address_step, 0x05); x=0; y=0; delay(250); } } if ((y>=70) && (y<=120)) // Center row { if ((x>=10) && (x<=60)) // Button: 100Hz step { waitForIt(10, 70, 60, 120); step_select = 6; step_end_stop = 1; address = 49; EEPROM.write(address, 0x06); EEPROM.write(address_step, 0x06); x=0; y=0; delay(250); } if ((x>=70) && (x<=120)) // Button: 50Hz step { waitForIt(70, 70, 120, 120); step_select =7; step_end_stop = 1; address = 49; EEPROM.write(address, 0x07); EEPROM.write(address_step, 0x07); x=0; y=0; delay(250); } if ((x>=130) && (x<=180)) // Button: 25Hz step { waitForIt(130, 70, 180, 120); step_select = 8; step_end_stop = 1; address = 49; EEPROM.write(address, 0x08); EEPROM.write(address_step, 0x08); x=0; y=0; delay(250); } if ((x>=190) && (x<=240)) // Button: 10Hz step { waitForIt(190, 70, 240, 120); step_select = 9; step_end_stop = 1; address = 49; EEPROM.write(address, 0x09); EEPROM.write(address_step, 0x09); x=0; y=0; delay(250); } if ((x>=250) && (x<=300)) // Button: 5Hz step { waitForIt(250, 70, 300, 120); step_select = 10; step_end_stop = 1; address = 49; EEPROM.write(address, 0x0A); EEPROM.write(address_step, 0x0A); x=0; y=0; delay(250); } } if ((y>=130) && (y<=180)) // bottom row { if ((x>=10) && (x<=60)) // Button: 1Hz step { waitForIt(10, 130, 60, 180); step_select = 11; step_end_stop = 1; address = 49; EEPROM.write(address, 0x0B); EEPROM.write(address_step, 0x0B); x=0; y=0; delay(250); } if ((x>=190) && (x<=300)) // Button: cancel { waitForIt(190, 130, 300, 180); step_select = step_select; step_end_stop = 1; x=0; y=0; delay(250); } } } } } void vfo_step_change() { myGLCD.setColor(255, 255, 255); myGLCD.setFont(BigFont); address = 49; recall_vfo_step = EEPROM.read(address); RF_step = EEPROM.read(address_step); // recall vfo step cahnge for hf band in use if (recall_vfo_step == 0x01 || RF_step == 0x01) // 5KHz step { dial_step = 5000; // 5KHz vfo increment dial_delay_movement = 5; myGLCD.print("Fs:5KHz", 205, 90); } else if (recall_vfo_step == 0x02 || RF_step == 0x02) // 3KHz step { dial_step = 3000; // 3KHz vfo increment dial_delay_movement = 5; myGLCD.print("Fs:3KHz", 205, 90); } else if (recall_vfo_step == 0x03 || RF_step == 0x03) // 1KHz step { dial_step = 1000; // 1KHz vfo increment dial_delay_movement = 5; myGLCD.print("Fs:1KHz", 205, 90); } else if (recall_vfo_step == 0x04 || RF_step == 0x04) // 500Hz step { dial_step = 500; // 500Hz vfo increment dial_delay_movement = 5; myGLCD.print("Fs:500Hz", 190, 90); } else if (recall_vfo_step == 0x05 || RF_step == 0x05) // 300Hz step { dial_step = 300; // 300Hz vfo increment dial_delay_movement = 3; myGLCD.print("Fs:300Hz", 190, 90); } else if (recall_vfo_step == 0x06 || RF_step == 0x06) // 100Hz step { dial_step = 100; // 100Hz vfo increment dial_delay_movement = 3; myGLCD.print("Fs:100Hz", 190, 90); } else if (recall_vfo_step == 0x07 || RF_step == 0x07) // 50Hz step { dial_step = 50; // 50Hz vfo increment dial_delay_movement = 1; myGLCD.print("Fs:50Hz", 205, 90); } else if (recall_vfo_step == 0x08 || RF_step == 0x08) // 25Hz step { dial_step = 25; // 25Hz vfo increment dial_delay_movement = 1; myGLCD.print("Fs:25Hz", 205, 90); } else if (recall_vfo_step == 0x09 || RF_step == 0x09) // 10Hz step { dial_step = 10; // 10Hz vfo increment dial_delay_movement = 1; myGLCD.print("Fs:10Hz", 205, 90); } else if (recall_vfo_step == 0x0A || RF_step == 0x0A) // 5Hz step { dial_step = 5; // 5Hz vfo increment dial_delay_movement = 1; myGLCD.print("Fs:5Hz ", 205, 90); } else if (recall_vfo_step == 0x0B || RF_step == 0x0B) // 1Hz step { dial_step = 1; // 1Hz vfo increment dial_delay_movement = 1; myGLCD.print("Fs:1Hz ", 205, 90); } } //************************************** radio panel Tx / Rx mode change switching ****************************** void radio_status() // to determine the radsio set iniether Tx or Rx mode { test_cw_key_ptt = digitalRead(cw_key_ptt); // old state of cw_key_ptt check_cw_key_ptt = test_cw_key_ptt; // at bootup, tx_rx_label is set HIGH // ptt and morse key change set low of tx enable, and disable Tx if radio out of ham band if ( check_cw_key_ptt == LOW && tx_rx_label == LOW && band_select != 13) { Wire.beginTransmission(PCF_tx_rx_switch); Wire.write(B00000001); // switch in Tx antenna and switch out Rx circuits, hex = 0x01 Wire.endTransmission(); delay(10); // 50ms delay to allow tx/rx relay to switch over into Tx position Wire.beginTransmission(PCF_tx_rx_switch); Wire.write(B00000011); // switch in Tx RF amplifier, hex = 0x03 Wire.endTransmission(); delay(10); // 10ms delay to settle the tx power supply Wire.beginTransmission(PCF_tx_rx_switch); Wire.write(B00000111); // switch in Tx RF modulation, hex = 0x07 Wire.endTransmission(); Wire.beginTransmission(PCF_tx_rx_switch); Wire.write(B00001111); // switch in Tx LED, hex = 0x0F Wire.endTransmission(); tx_rx_label = HIGH; } if ( check_cw_key_ptt == LOW) { transmitter_power(); // to continually measure TX output and antenna health } if ( check_cw_key_ptt == HIGH && tx_rx_label == HIGH ) // ptt and morse key change set high for rx enable { Wire.beginTransmission(PCF_tx_rx_switch); Wire.write(B00001001); // switch off the Tx RF amplifier and Tx modulation, hex = 0x0A Wire.endTransmission(); delay(10); // 10ms delay to settle the tx power supply into Rx mode Wire.beginTransmission(PCF_tx_rx_switch); Wire.write(B10000000); // switch in Rx antenna and switch out Tx relay and Tx LED, hex = 0x80 Wire.endTransmission(); Wire.beginTransmission(PCF_tx_rx_switch); Wire.write(B11110000); // switch in Rx ciruits of RF de-mode, AF stage and Rx LED, hex = 0xF0 Wire.endTransmission(); tx_rx_label = LOW; } if ( check_cw_key_ptt == HIGH ) { receiver_signal(); // to continually measure Rx signal strength } } // received signal display message void receiver_signal() { myGLCD.setColor(255,128 ,255); // colour text myGLCD.setFont(BigFont); float S_meter; double over_load; double signal_meter; int rx_signal_value = analogRead(3); // analog port 3 to measure RX signal input double rx_signal_voltage = ((rx_signal_value)); signal_meter = rx_signal_voltage; // signal_meter = 40; // ADC measured signal strength test values // the value of 500 indicates an "S 9" signal for a 10bit ADC, RST from "Rx:1.0" up to "Rx:9.0 +7dB" over_load = 20*(double)log10((signal_meter)/1); // for 10bit ADC for "S" meter, // the value of 5000 indicates an "S 9" signal for a 16bit ADC, RST from "Rx:0.1" up to "Rx:9.0 +23dB" // over_load = 20*(double)log10((signal_meter/100)/0.1); // for 16bit ADC for "S" meter S_meter = (over_load/0.6); myGLCD.print("Rx=",5 ,115); if (over_load <= 54 ) { //Serial.println("below S9"); // Serial.print("Rx= "); // Serial.print(S_meter/10); myGLCD.setColor(0, 0 ,0); // black text // myGLCD.print(" ", 5 ,115); myGLCD.setColor(255,128,255); // colour text myGLCD.setFont(BigFont); myGLCD.print(" ",150 ,115); RST_measure = (S_meter/10); myGLCD.printNumF(RST_measure,1,85, 115); } else { myGLCD.setColor(255,128,255); // colour text myGLCD.setFont(BigFont); myGLCD.print("9.0 +",85 ,115); float over_load_scale = over_load - 55; myGLCD.printNumF(over_load_scale,1,180 ,115); myGLCD.print("dB",240 ,115); } } // transmitter power output display message void transmitter_power() { float tx_power_measure = analogRead(2); // analog 2 to measure tx power output float tx_signal_level = 0.0048 * tx_power_measure; // tx_signal_level = 3.75; // test program values // tx power = (v * v) / antenna float tx_power = ((tx_signal_level * tx_signal_level) / 50) * 100; // set to 50Watts max scale myGLCD.setColor(255,255 ,0); // colour text myGLCD.setFont(BigFont); myGLCD.print("Tx= ", 5 , 140); myGLCD.printNumF(tx_power,1,85,140); myGLCD.print("Watts",190,140); // *** calculation of the antenna impedance match as the SWR value ********* swr_forward = 0; // reset value to zero swr_reflected = 0; // reset value to zero swr_forward = analogRead(0); // swr forward voltage from impedance bridge swr_reflected = analogRead(1); // swr reflected voltage from impedance bridge v_forward = 0.0048 * swr_forward; // forward swr voltage measured value v_reflected = 0.0048 * swr_reflected; // reverse swr voltage measured value //**************** antenna meter test voltages ************* // v_forward = 3.0; // v_reflected = 3.25; //**************** swr calculation ************************ float ratio = v_reflected / v_forward; float swr_value = ratio; // **** calculation of the antenna as an impedance vector angle ***** RL = swr_value * 50; // calculation of antenna resistance, assume match to a 50ohm co-axial cable reference float target = 50; float angle = ((double)atan2(RL,target))*(180/PI); // arc tangent of y/x myGLCD.setColor(0,255,255); // light blue clolur text myGLCD.print("Swr= 1:",5, 165); myGLCD.printNumF(swr_value,4,120,165); myGLCD.print("Vec= 50R @",5, 190); myGLCD.printNumF(angle,2,180,190); myGLCD.print("deg",270,190); myGLCD.print("Imp= ",5, 215); float res_load = RL; //******* capacitive loaded antenna ***** if (res_load < 50) { cap = 300E-9 / ( res_load * res_load); cap_scale = cap * 1E12; if (cap_scale <= 1000) { cap_scale_t = cap_scale; myGLCD.printNumI(res_load,85,215); myGLCD.print("R ",120,215); myGLCD.print("-j",150,215); myGLCD.printNumI(cap_scale_t,190,215); myGLCD.print("pF",250,215); } else if (cap_scale > 1E3 && cap_scale <= 1E6) { cap_scale_t = cap_scale/1E3; myGLCD.printNumF(res_load,1,85,215); myGLCD.print("R ",135,215); myGLCD.print("-j",160,215); myGLCD.printNumI(cap_scale_t,190,215); myGLCD.print("nF",250,215); } else if (cap_scale > 1E6 && cap_scale <= 1E9) { cap_scale_t = cap_scale/1E6; myGLCD.printNumF(res_load,2,85,215); myGLCD.print("R ",135,215); myGLCD.print("-j",160,215); myGLCD.printNumI(cap_scale_t,200,215); myGLCD.print("uF",250,215); } } if ( res_load < 0.1) { myGLCD.print(" short circuit ",85,215); delay(500); myGLCD.print(" ",80,215); } ///***** inductive loaded antenna ****** if (res_load > 50) { ind = (res_load * res_load) * 120E-12; ind_scale = ind * 1E12; if (ind_scale <= 1000) { ind_scale_t = ind_scale; myGLCD.printNumI(res_load,85,215); myGLCD.print("R ",120,215); myGLCD.print("+j",150,215); myGLCD.printNumI(ind_scale_t,190,215); myGLCD.print("pH",250,215); } else if (ind_scale > 1E3 && ind_scale <= 1E6) { ind_scale_t = ind_scale/1000; myGLCD.printNumI(res_load,85,215); myGLCD.print("R ",120,215); myGLCD.print("+j",150,215); myGLCD.printNumI(ind_scale_t,190,215); myGLCD.print("nH",250,215); } else if (ind_scale > 1E6 && ind_scale <= 1E9 && res_load <= 999) { ind_scale_t = ind_scale/1E6; myGLCD.printNumI(res_load,85,215); myGLCD.print("R ",120,215); myGLCD.print("+j",160,215); myGLCD.printNumF(ind_scale_t,1,200,215); myGLCD.print("uH",270,215); } else if (ind_scale > 1E9 && ind_scale <= 1E12) { ind_scale_t = ind_scale/1E9; float res_load_scale = res_load /1000; myGLCD.printNumF(res_load_scale,1,85,215); myGLCD.print("K ",135,215); myGLCD.print("+j",160,215); myGLCD.printNumF(ind_scale_t,0,210,215); myGLCD.print("mH",260,215); } } if ( res_load >= 5001) { myGLCD.print(" open circuit ",85,215); delay(500); myGLCD.print(" ",80,215); } if ( res_load == 50) { myGLCD.print("Imp= 50R antenna ",5, 215); delay(500); myGLCD.print(" ",80,215); } } //****************rotary encoder sub-routine for rotary movement of dial setting and vfo update ********************** void getEncoderTurn() // rotary encoder sub-routine for rotary movement { if (digitalRead(clk_location) == HIGH) // anti clock wise direction { dial_delay_clk = 0; delay(3); if (digitalRead(clk_location) == LOW) { dial_delay_anti_clk = dial_delay_anti_clk + 1; if ( dial_delay_anti_clk == dial_delay_movement ) // change the number 18 to a higher value for smoother operation { result = -1; // down band movement carrier_centre = carrier_centre + (result * dial_step); dial_post = carrier_centre; rx = carrier_centre; dial_frequency(); dial_delay_anti_clk = 0; } } } else if (digitalRead(dt_location) == HIGH) // clock wise direction { dial_delay_anti_clk = 0; delay(3); if (digitalRead(dt_location) == LOW) { dial_delay_clk = dial_delay_clk + 1; if ( dial_delay_clk == dial_delay_movement ) // change the number 18 to a higher value for smoother operation { result = 1; // up band movement carrier_centre = carrier_centre + (result * dial_step); dial_post = carrier_centre; rx = carrier_centre; dial_frequency(); dial_delay_clk = 0; } } } } //********************* display dial frequency ************* // **************************************************************************************** // ************* frequency VFO control from dial change ***************** void AD9850_reset() { //reset sequence is: // CLOCK & LOAD = LOW // Pulse RESET high for a few uS (use 5 uS here) // Pulse CLOCK high for a few uS (use 5 uS here) // Set DATA to ZERO and pulse LOAD for a few uS (use 5 uS here) // data sheet diagrams show only RESET and CLOCK being used to reset the device, but I see no output unless I also // toggle the LOAD line here. digitalWrite(CLOCK, LOW); digitalWrite(LOAD, LOW); digitalWrite(RESET, LOW); delayMicroseconds(5); digitalWrite(RESET, HIGH); //pulse RESET delayMicroseconds(5); digitalWrite(RESET, LOW); delayMicroseconds(5); digitalWrite(CLOCK, LOW); delayMicroseconds(5); digitalWrite(CLOCK, HIGH); //pulse CLOCK delayMicroseconds(5); digitalWrite(CLOCK, LOW); delayMicroseconds(5); digitalWrite(DATA, LOW); //make sure DATA pin is LOW digitalWrite(LOAD, LOW); delayMicroseconds(5); digitalWrite(LOAD, HIGH); //pulse LOAD delayMicroseconds(5); digitalWrite(LOAD, LOW); // Chip is RESET now } void AD9850_init() { digitalWrite(RESET, LOW); digitalWrite(CLOCK, LOW); digitalWrite(LOAD, LOW); digitalWrite(DATA, LOW); } // *********** frequency control of the AD9851 DDS device for TX / Rx vfo ********* void sendFrequency(unsigned long frequency) { unsigned long tuning_word = (frequency * pow(2, 32)) / DDS_CLOCK; digitalWrite (LOAD, LOW); shiftOut(DATA, CLOCK, LSBFIRST, tuning_word); shiftOut(DATA, CLOCK, LSBFIRST, tuning_word >> 8); shiftOut(DATA, CLOCK, LSBFIRST, tuning_word >> 16); shiftOut(DATA, CLOCK, LSBFIRST, tuning_word >> 24); shiftOut(DATA, CLOCK, LSBFIRST, 0x00); digitalWrite(LOAD, HIGH); }