#include <rotary.
h>
#include <Adafruit_LiquidCrystal.h>
/*
VFO DDS MULTIPROPOSITO
LU1AGP - 2016-
CIRCUITOS E INFO ADICIONAL EN : [Link]
(basado en el codigo de Richard Visokey AD7C)
GRACIAS RICHARD !!!
PARA CAMBIAR EL VALOR DE FI Y LA SUMA O RESTA PARA CADA EQUIPO MODIFICAR LAS LINEAS
MARCADAS AL FINAL DEL PROGRAMA CON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*/
// Inclusion de librerias
//#include <LiquidCrystal.h>
//definicion de algunos items
#define W_CLK 8 // Pin 8 - (CLK)AD9850
#define FQ_UD 9 // Pin 9 - (FQ)AD9850
#define DATA 10 // Pin 10 - (DATA)AD9850
#define RESET 11 // Pin 11 -(RESET) AD9850
#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
Rotary r = Rotary(2, 3); // pins del rotary encoder
Adafruit_LiquidCrystal lcd(12, 13, 7, 6, 5, 4); // pins al LCD
int_fast32_t rx = 7100000; // Frecuencia de inicio VFO
int_fast32_t rx2 = 1; // Variable auxiliar para retener la nueva frecuencia
int_fast32_t increment = 10; // paso de sintonia inicial.
int_fast32_t iffreq = 0000000; //FRECUENCIA INTERMEDIA
int buttonstate = 0;// var boton pasos de sintonia
int buttonband = 0;// var boton cambio de banda
int buttoneq = 0;// var boton cambio equipo
int GoIF = 1;//var suma o resta FI
int equip = 0; //var numero de equipo
String hertz = " 10 Hz";
int hertzPosition = 10;
byte ones, tens, hundreds, thousands, tenthousands, hundredthousands,
millions ; //Ubicacion lugares
String freq; // string para retener la frecuencia
int_fast32_t timepassed = millis(); //
String bandax = "40m";// string indicador de banda ,inicia en 40m
int banda = 40;//inicia BAND 40m
String equipx = "VFO"; // string indicador de equipo o VFO, inicia en VFO
void setup() {
pinMode(A0, INPUT); // STEP (Boton a GND que cambia los pasos de sintonia)
pinMode(A1, INPUT); // BAND (boton a GND que cambia de banda)
pinMode(A2, INPUT); // EQUIPO (boton a GND que cambia de equipo)
digitalWrite(A0, HIGH);
digitalWrite(A1, HIGH);
digitalWrite(A2, HIGH);
[Link](16, 2);
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei();
pinMode(FQ_UD, OUTPUT);
pinMode(W_CLK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(RESET, OUTPUT);
pulseHigh(RESET);
pulseHigh(W_CLK);
pulseHigh(FQ_UD); // este pulso habilita el modo serie del AD9850
[Link](1, 0);
[Link]("LU1AGP DDS VFO");
delay (3000);
[Link](hertzPosition, 1);
[Link](hertz);
[Link](0, 1);
[Link](equipx);
[Link](6, 1);
[Link](bandax);
}
void loop() {
// Lee boton cambio de banda
buttonband = digitalRead(A1);
if (buttonband == LOW) {
cambiobanda();
}
// Lee boton cambio equipo
buttoneq = digitalRead (A2);
if (buttoneq == LOW) {
equipo();
}
// Actualiza la frecuencia del display cuando la frecuencia nueva es distinta a
al actual
if (rx != rx2) {
showFreq();
sendFrequency(rx);
rx2 = rx;
}
// Lee el boton STEP y cambia los pasos de sintonia (10, 100, 1k , 10k)
buttonstate = digitalRead(A0);
if (buttonstate == LOW) {
setincrement();
};
sendFrequency(rx);
}
// rutina de interrupcion del rotary encoder
ISR(PCINT2_vect) {
unsigned char result = [Link]();
if (result) {
if (result == DIR_CW) {
rx = rx + increment;
}
else {
rx = rx - increment;
};
if (rx >= 30000000) {
rx = rx2;
}; // LIMITE SUPERIOR DEL VFO
if (rx <= 1000000) {
rx = rx2;
}; // LIMITE INFERIOR DEL VFO
}
}
// CALCULO DE FRECUENCIA DDS= <sys clock> * <frequency tuning word>/2^32
void sendFrequency(double frequency) {
if (GoIF == 1) {
frequency = frequency + iffreq;
}; //Si el pin esta en alto SUMA la FI
if (GoIF == 0) {
frequency = frequency - iffreq ;
}; // Si el pin esta en bajo RESTA la FI
int32_t freq = frequency * 4294967295 / 125000000; // 125 MHz clock del AD9850.
Se puede realizar un ajuste fino de frecuencia cambiando este valor.
for (int b = 0; b < 4; b++, freq >>= 8) {
tfr_byte(freq & 0xFF);
}
tfr_byte(0x000);// byte de control final
pulseHigh(FQ_UD); // Listo !!!
}
// transfiere los datos al AD9850
void tfr_byte(byte data)
{
for (int i = 0; i < 8; i++, data >>= 1) {
digitalWrite(DATA, data & 0x01);
pulseHigh(W_CLK);
}
}
//pasos de sintonia
void setincrement() {
if (increment == 10) {
increment = 100;
hertz = "100 Hz";
hertzPosition = 10;
}
else if (increment == 100) {
increment = 1000;
hertz = " 1 KHz";
hertzPosition = 10;
}
else if (increment == 1000) {
increment = 10000;
hertz = "10 KHz";
hertzPosition = 10;
}
else {
increment = 10;
hertz = " 10 Hz";
hertzPosition = 10;
};
[Link](9, 1);
[Link]("");
[Link](hertzPosition, 1);
[Link](hertz);
delay(500);
};
// muestra la frecuencia en el display
void showFreq() {
millions = int(rx / 1000000);
hundredthousands = ((rx / 100000) % 10);
tenthousands = ((rx / 10000) % 10);
thousands = ((rx / 1000) % 10);
hundreds = ((rx / 100) % 10);
tens = ((rx / 10) % 10);
ones = ((rx / 1) % 10);
[Link](0, 0);
[Link](" ");
if (millions > 9) {
[Link](2, 0);
}
else {
[Link](3, 0);
}
[Link](millions);
[Link](hundredthousands);
[Link](tenthousands);
[Link](thousands);
[Link](".");
[Link](hundreds);
[Link](tens);
[Link](" KHz ");
timepassed = millis();
};
// rutina cambio de banda
void cambiobanda () {
if (banda == 40) {
banda = 20;
bandax = "20m";
rx = 14150000;
}
else if (banda == 20) {
banda = 15;
bandax = "15m";
rx = 21200000;
}
else if (banda == 15) {
banda = 10;
bandax = "10m";
rx = 28500000;
}
else if (banda == 10) {
banda = 80;
bandax = "80m";
rx = 3650000;
}
else {
banda = 40;
bandax = "40m";
rx = 7100000;
};
[Link](6, 1);
[Link](bandax);
delay (500);
};
//rutina cambio equipo ,MODIFICAR VALORES PARA ADAPTARLO A SUS EQUIPOS Y USOS
void equipo() {
if (equip == 0) {
equip = 1;
equipx = "EQ1"; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< poner aqui el nombre del
EQUIPO #1
iffreq = 4000000; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<< valor de FI del EQUIPO #1
GoIF = 1; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< poner en 1 para sumar o en 0
para restar la FI
}
else if (equip == 1) {
equip = 2;
equipx = "EQ2"; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< poner aqui el nombre del
EQUIPO #2
iffreq = 2000000; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<< valor FI del EQUIPO #2
GoIF = 1; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< poner en 1 para sumar o en 0
para restar la FI
}
else if (equip == 2) {
equip = 3;
equipx = "EQ3"; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< poner aqui el nombre del
EQUIPO #3
iffreq = 1650000; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<< valor FI del EQUIPO #3
GoIF = 0; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< poner en 1 para sumar o en 0
para restar la FI
}
else {
equip = 0;
equipx = "VFO";
iffreq = 0;
GoIF = 1;
};
[Link](0, 1);
[Link] (equipx);
delay(500);
};