Najprościej wykonany układ DDS z popularnym modułem AD9850.
#include <Wire.h> #include <EEPROM.h> #include <LiquidCrystal_I2C.h> #include <Encoder_Polling.h> #include <AH_AD9850.h> //************ PORTY ARDUINO****************** //porty dla DDS AD9850 #define AD9850_RESET 9 #define AD9850_BITDATA 8 #define AD9850_FQUP 7 #define AD9850_CLK 6 //porty dla ENCODER #define ENCODER_SW 5 #define ENCODER_CLK 4 #define ENCODER_DT 3 //porty dla przycisków #define BUTTON_1 12 #define BUTTON_2 11 #define BUTTON_3 10 #define BUTTON_4 A0 //port dla diod LED #define LED 2 //pomiar napiecia #define VOL A1 //////////////// OBIEKTY ///// //********** MODUL DDS ********************************* // definicja AH_AD9850(CLK, FQUP, BitData, RESET) AH_AD9850 AD9850(AD9850_CLK, AD9850_FQUP, AD9850_BITDATA, AD9850_RESET); #define LCD_I2C_ADDRESS 0x27 ///LiquidCrystal_I2C(lcd_Addr,En,Rw,Rs,d4,d5,d6,d7,backlighPin,backlighPol); LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //Stałe #define ROW_1 0 #define ROW_2 1 const long MIN_FREQ = 7000000; // Poczatek zakresu pasma 40 m const long MAX_FREQ = 7200000; // Koniec zakresu pasma 40 m const long DEF_FREQ = 7100000; // Domyśla częstotliwość pasma 40 m const long OSCILATOR = 11998000; //Częstotliwość oscylatora BFO const long MAX_STEP = 10000; //Maksymaly krok zmiany częstotliwości const long MIN_STEP = 10; // Minimalny krok zmiany częstotliowsci const int MIN_ARRAY_STEP = 0; const int MAX_ARRAY_STEP = 9; //Zmienne long Freq = DEF_FREQ; long Step = 10; int Encoder_SW_state = HIGH; long Freq_VFO=0; int Is_display_freq = HIGH; int Volty =0; int Current_step = 0; int Array_steps[]={10,25,50,100,250,500,1000,2500,5000,10000}; int scan_up = LOW; int scan_down = LOW; int scan = LOW; //******************************************************* void setup() { pinMode(BUTTON_1, INPUT); pinMode(BUTTON_2, INPUT); pinMode(BUTTON_3, INPUT); pinMode(BUTTON_4, INPUT); pinMode(ENCODER_SW, INPUT); lcd.begin(16,2); lcd.home(); lcd.print("* RADUINO 3.0 *"); lcd.setCursor(0,ROW_2); lcd.print(" A.Sliwa SQ9TLA "); delay(3000); lcd.home (); lcd.print("U: V,S: 10 Hz"); lcd.setCursor (0, ROW_2); lcd.print("FERQ: MHz"); encoder_begin(ENCODER_DT,ENCODER_CLK); Freq=DEF_FREQ; } //******************************************************* void loop() { //Oodczyt stanu przycisków int button_1 = digitalRead(BUTTON_1); int button_2 = digitalRead(BUTTON_2); int button_3 = digitalRead(BUTTON_3); int button_4 = digitalRead(BUTTON_4); //Skanowanie pasma if ((button_1 == HIGH) and (scan_up == LOW)) { scan_down=LOW; scan_up = HIGH; } if ((button_1 == HIGH) and (scan_up == HIGH)) { scan_down=LOW; scan_up = LOW; } if ((button_2 == HIGH) and (scan_down == LOW)) { scan_down=HIGH; scan_up = LOW; } if ((button_2 == HIGH) and (scan_down == HIGH)) { scan_down=LOW; scan_up = LOW; } if (scan_up == HIGH) { Freq = Freq + Step; delay(1000); } if (scan_down == HIGH) { Freq = Freq - Step; delay(1000); } //Zmiana freq od przycisków if (button_3 == HIGH) Freq=Freq - 100; if (button_4 == HIGH) Freq=Freq + 100; //Obsługa enkodera int dir = encoder_data(); Encoder_SW_state= digitalRead(ENCODER_SW); //Zmiana kroku if (Encoder_SW_state == LOW) { if( dir > 0) { if (Current_step < MAX_ARRAY_STEP) Current_step++; } if (dir < 0 ) { if (Current_step > MIN_ARRAY_STEP) Current_step--; } } //Zmiana częstotliwości else { if(dir > 0) { Freq = Freq + Step; } if (dir <0 ) { Freq = Freq - Step; } } Step=Array_steps[Current_step]; //Ograniczniki dla pasm if (Freq < MIN_FREQ) { Freq = MIN_FREQ; scan_down = LOW; } if (Freq > MAX_FREQ) { Freq = MAX_FREQ; scan_up = LOW; } //Wyswietlanie kroku na wyświetlaczu if (Encoder_SW_state == LOW) { if (Is_display_freq == HIGH) { lcd.setCursor(0,ROW_2); lcd.print("STEP: Hz"); Is_display_freq = LOW; } lcd.setCursor(6,ROW_2); switch(Step) { case 10000 : lcd.print(" 10000"); break; case 5000 : lcd.print(" 5000"); break; case 2500 : lcd.print(" 2500"); break; case 1000 : lcd.print(" 1000"); break; case 500 : lcd.print(" 500"); break; case 250 : lcd.print(" 250"); break; case 100 : lcd.print(" 100"); break; case 50 : lcd.print(" 50"); break; case 25 : lcd.print(" 25"); break; case 10 : lcd.print(" 10"); break; case 1 : lcd.print(" 1"); break; } lcd.setCursor(10,ROW_1); switch(Step) { case 10000 : lcd.print("10 kHz"); break; case 5000 : lcd.print(" 5 kHz"); break; case 2500 : lcd.print("2.5kHz"); break; case 1000 : lcd.print(" 1 kHz"); break; case 500 : lcd.print("500 Hz"); break; case 250 : lcd.print("250 Hz"); break; case 100 : lcd.print("100 Hz"); break; case 50 : lcd.print(" 50 Hz"); break; case 25 : lcd.print(" 25 Hz"); break; case 10 : lcd.print(" 10 Hz"); break; case 1 : lcd.print(" 1 HZ"); break; } } else { if (Is_display_freq == LOW) { lcd.setCursor(0,ROW_2); lcd.print("FERQ: MHz"); Is_display_freq = HIGH; } lcd.setCursor(6,ROW_2); lcd.print(Freq/10); lcd.setCursor(5,ROW_2); lcd.print("7."); } //Obsługa DDS-a Freq_VFO=OSCILATOR - Freq; AD9850.set_frequency(Freq_VFO); button_1 = LOW; button_2 = LOW; button_3 = LOW; button_4 = LOW; delay(100); }