Так а как соединить ардуинку нано с синтезатором adf 4351 ?есть cхема?Вот здесь все подробно, в картинках.
/*
ARDUINO ADF4351
D10 LE
D13 CLK
D12 LD
D11 DAT
GND GND
+5V +5V
*/
#include <SPI.h>
boolean mrk1, mrk1_old, mrk2, mrk2_old;
int press = 0;
int cnt_step = 1;
int cnt_step_old;
int cnt_fix = 2;
int cnt_fix_old;
int cnt_pwr = 1;
int cnt_pwr_old;
int mdbm = 3;
const int slaveSelectPin = 10;
long Freq;
long refin = 1000000;
unsigned long Reg[6];
int pegelZ = 0;
int outPegel = mdbm;
const int CLK = 13;
const int DATA = 11;
void setup() {
pinMode (slaveSelectPin, OUTPUT);
digitalWrite(slaveSelectPin, LOW);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV128);
SPI.begin();
delay(50);
SetFreq(43000000);
}
void loop() {
}
void SetFreq(long Frequ) {
ConvertFreq(Reg);
WriteADF2(5);
delayMicroseconds(25);
WriteADF2(4);
delayMicroseconds(25);
WriteADF2(3);
delayMicroseconds(25);
WriteADF2(2);
delayMicroseconds(25);
WriteADF2(1);
delayMicroseconds(25);
WriteADF2(0);
delayMicroseconds(25);
}
void WriteADF2(int idx) {
byte buf[4];
for (int i = 0; i < 4; i++)
buf[i] = (byte)(Reg[idx] >> (i * 8));
WriteADF(buf[3], buf[2], buf[1], buf[0]);
}
int WriteADF(byte a1, byte a2, byte a3, byte a4) {
digitalWrite(slaveSelectPin, LOW);
delayMicroseconds(10);
SPI.transfer(a1);
SPI.transfer(a2);
SPI.transfer(a3);
SPI.transfer(a4);
Toggle();
}
int Toggle() {
digitalWrite(slaveSelectPin, HIGH);
delayMicroseconds(5);
digitalWrite(slaveSelectPin, LOW);
}
void ConvertFreq(unsigned long R[]) {
int P_Phase = 1;
int Prescal = 0;
int PhaseAdj = 0;
int U1_CountRes = 0;
int U2_Cp3state = 0;
int U3_PwrDown = 0;
int U4_PDpola = 1;
int U5_LPD = 0;
int U6_LPF = 1;
int CP_ChgPump = 7;
int D1_DoublBuf = 0;
int R_Counter = 2;
int RD1_Rdiv2 = 1;
int RD2refdoubl = 0;
int M_Muxout = 0;
int LoNoisSpur = 0;
int D_Clk_div = 150;
int C_Clk_mode = 0;
int F1_Csr = 0;
int F2_ChgChan = 0;
int F3_ADB = 0;
int F4_BandSel = 0;
int D_out_PWR = mdbm;
int D_RF_ena = 1;
int D_auxOutPwr = mdbm;
int D_auxOutEna = 1;
int D_auxOutSel = 1;
int D_MTLD = 0;
int D_VcoPwrDown = 0;
int B_BandSelClk = 200;
int D_RfDivSel = 3;
int D_FeedBck = 1;
int D_LdPinMod = 1;
long RFout = Freq;
int outdiv = 1;
if (RFout >= 220000000) {
outdiv = 1;
D_RfDivSel = 0;
} if (RFout < 220000000) {
outdiv = 2;
D_RfDivSel = 1;
} if (RFout < 110000000) {
outdiv = 4;
D_RfDivSel = 2;
} if (RFout < 55000000) {
outdiv = 8;
D_RfDivSel = 3;
} if (RFout < 27500000) {
outdiv = 16;
D_RfDivSel = 4;
} if (RFout < 13800000) {
outdiv = 32;
D_RfDivSel = 5;
} if (RFout < 6900000) {
outdiv = 64;
D_RfDivSel = 6;
}
float PFDFreq = refin * ((1.0 + RD2refdoubl) / (R_Counter * (1.0 + RD1_Rdiv2)));
float N = ((RFout) * outdiv) / PFDFreq;
int N_Int = N;
long M_Mod = (PFDFreq * 100) / 100000;
int F_Frac = round((N - N_Int) * M_Mod);
R[0] = (unsigned long)(0 + F_Frac * pow(2, 3) + N_Int * pow(2, 15));
R[1] = (unsigned long)(1 + M_Mod * pow(2, 3) + P_Phase * pow(2, 15) + Prescal * pow(2, 27) + PhaseAdj * pow(2, 28));
R[2] = (unsigned long)(2 + U1_CountRes * pow(2, 3) + U2_Cp3state * pow(2, 4) + U3_PwrDown * pow(2, 5) + U4_PDpola * pow(2, 6) + U5_LPD * pow(2, 7) + U6_LPF * pow(2, 8) + CP_ChgPump * pow(2, 9) + D1_DoublBuf * pow(2, 13) + R_Counter * pow(2, 14) + RD1_Rdiv2 * pow(2, 24) + RD2refdoubl * pow(2, 25) + M_Muxout * pow(2, 26) + LoNoisSpur * pow(2, 29));
R[3] = (unsigned long)(3 + D_Clk_div * pow(2, 3) + C_Clk_mode * pow(2, 15) + 0 * pow(2, 17) + F1_Csr * pow(2, 18) + 0 * pow(2, 19) + F2_ChgChan * pow(2, 21) + F3_ADB * pow(2, 22) + F4_BandSel * pow(2, 23) + 0 * pow(2, 24));
R[4] = (unsigned long)(4 + D_out_PWR * pow(2, 3) + D_RF_ena * pow(2, 5) + D_auxOutPwr * pow(2, 6) + D_auxOutEna * pow(2, 8) + D_auxOutSel * pow(2, 9) + D_MTLD * pow(2, 10) + D_VcoPwrDown * pow(2, 11) + B_BandSelClk * pow(2, 12) + D_RfDivSel * pow(2, 20) + D_FeedBck * pow(2, 23));
R[5] = (unsigned long)(5 + 0 * pow(2, 3) + 3 * pow(2, 19) + 0 * pow(2, 21) + D_LdPinMod * pow(2, 22));
}
/*
ARDUINO ADF4351
D5 CE
D10 LE
D13 CLK
D12 LD
D11 DAT
GND GND
+5V +5V
*/
#include <SPI.h>
const char message[] = "SOS";
const int point_time = 80; // SPEED (ms)
const unsigned char freq_div = 1;
struct s_abc {
char letter;
char sign[7];
};
const s_abc abc[] = {
'A', ".-", 'B', "-...", 'W', ".--", 'G', "--.", 'D', "-..",
'E', ".", 'V', "...-", 'Z', "--..", 'I', "..",
'J', ".---", 'K', "-.-", 'L', ".-..", 'M', "--", 'N', "-.",
'O', "---", 'P', ".--.", 'R', ".-.", 'S', "...",
'T', "-", 'U', "..-", 'F', "..-.", 'H', "....", 'C', "-.-.",
'Q', "--.-", 'Y', "-.--", 'X', "-..-", '1', ".----",
'2', "..---", '3', "...--", '4', "....-", '5', ".....",
'6', "-....", '7', "--...", '8', "---..", '9', "----.",
'0', "-----", '.', "......", ',', ".-.-.-", ':', "---...",
';', "-.-.-.", '(', "-.--.-", '`', ".----.",
'"', ".-..-.", '-', "-....-", '/', "-..-.", '?', "..--..",
'!', "--..--", '@', ".--.-.", '\\', "..-.-"
};
unsigned char abc_size = sizeof(abc) / sizeof(abc[0]);
int press = 0;
int mdbm = 3; // mdbm0 = -4dBm mdbm = 3 = +5dBm
const int slaveSelectPin = 10;
long Freq = 14530000; // FREQUENCY 145.300 MHz (2m band)
long refin = 2500000; // REF OSCILLATOR
unsigned long Reg[6];
const int CLK = 13;
const int DATA = 11;
void setup() {
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
pinMode (slaveSelectPin, OUTPUT);
digitalWrite(slaveSelectPin, LOW);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV128);
pinMode(6, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
SPI.begin();
delay(50);
SetFreq(Freq);
}
void loop() {
for (int n = 0; message[n] != 0; n++)
send_letter(message[n]);
delay(1000); // TIME PAUSE
}
void send_letter(char l) {
if (l == ' ') {
delay(point_time * 7);
return;
}
unsigned char idx = 255;
for (unsigned char i = 0; i < abc_size; i++)
if (abc[i].letter == l) {
idx = i;
break;
}
if (idx == 255) return;
const char *s = abc[idx].sign;
for (unsigned char c = 0; s[c] != 0; c++) {
char q = s[c];
DDRB |= 1 << 1;
digitalWrite(5, HIGH);
if (q == '.') delay(point_time);
else delay(point_time * 3);
DDRB &= ~(1 << 1);
digitalWrite(5, LOW);
delay(point_time);
}
delay(point_time * 2);
}
void SetFreq(long Frequ) {
ConvertFreq(Reg);
WriteADF2(5);
delayMicroseconds(250);
WriteADF2(4);
delayMicroseconds(250);
WriteADF2(3);
delayMicroseconds(250);
WriteADF2(2);
delayMicroseconds(250);
WriteADF2(1);
delayMicroseconds(250);
WriteADF2(0);
delayMicroseconds(250);
}
void WriteADF2(int idx) {
byte buf[4];
for (int i = 0; i < 4; i++)
buf[i] = (byte)(Reg[idx] >> (i * 8));
WriteADF(buf[3], buf[2], buf[1], buf[0]);
}
int WriteADF(byte a1, byte a2, byte a3, byte a4) {
digitalWrite(slaveSelectPin, LOW);
delayMicroseconds(10);
SPI.transfer(a1);
SPI.transfer(a2);
SPI.transfer(a3);
SPI.transfer(a4);
Toggle();
}
int Toggle() {
digitalWrite(slaveSelectPin, HIGH);
delayMicroseconds(5);
digitalWrite(slaveSelectPin, LOW);
}
void ConvertFreq(unsigned long R[]) {
int P_Phase = 1;
int Prescal = 0;
int PhaseAdj = 0;
int U1_CountRes = 0;
int U2_Cp3state = 0;
int U3_PwrDown = 0;
int U4_PDpola = 1;
int U5_LPD = 0;
int U6_LPF = 1;
int CP_ChgPump = 7;
int D1_DoublBuf = 0;
int R_Counter = 2;
int RD1_Rdiv2 = 1;
int RD2refdoubl = 0;
int M_Muxout = 0;
int LoNoisSpur = 0;
int D_Clk_div = 150;
int C_Clk_mode = 0;
int F1_Csr = 0;
int F2_ChgChan = 0;
int F3_ADB = 0;
int F4_BandSel = 0;
int D_out_PWR = mdbm;
int D_RF_ena = 1;
int D_auxOutPwr = mdbm;
int D_auxOutEna = 1;
int D_auxOutSel = 1;
int D_MTLD = 0;
int D_VcoPwrDown = 0;
int B_BandSelClk = 200;
int D_RfDivSel = 3;
int D_FeedBck = 1;
int D_LdPinMod = 1;
long RFout = Freq;
int outdiv = 1;
if (RFout >= 220000000) {
outdiv = 1;
D_RfDivSel = 0;
} if (RFout < 220000000) {
outdiv = 2;
D_RfDivSel = 1;
} if (RFout < 110000000) {
outdiv = 4;
D_RfDivSel = 2;
} if (RFout < 55000000) {
outdiv = 8;
D_RfDivSel = 3;
} if (RFout < 27500000) {
outdiv = 16;
D_RfDivSel = 4;
} if (RFout < 13800000) {
outdiv = 32;
D_RfDivSel = 5;
} if (RFout < 6900000) {
outdiv = 64;
D_RfDivSel = 6;
}
float PFDFreq = refin * ((1.0 + RD2refdoubl) / (R_Counter * (1.0 + RD1_Rdiv2)));
float N = ((RFout) * outdiv) / PFDFreq;
int N_Int = N; long M_Mod = (PFDFreq * 100) / 100000; int F_Frac = round((N - N_Int) * M_Mod);
R[0] = (unsigned long)(0 + F_Frac * pow(2, 3) + N_Int * pow(2, 15));
R[1] = (unsigned long)(1 + M_Mod * pow(2, 3) + P_Phase * pow(2, 15) + Prescal * pow(2, 27) + PhaseAdj * pow(2, 28));
R[2] = (unsigned long)(2 + U1_CountRes * pow(2, 3) + U2_Cp3state * pow(2, 4) + U3_PwrDown * pow(2, 5) + U4_PDpola * pow(2, 6) + U5_LPD * pow(2, 7) + U6_LPF * pow(2, 8) + CP_ChgPump * pow(2, 9) + D1_DoublBuf * pow(2, 13) + R_Counter * pow(2, 14) + RD1_Rdiv2 * pow(2, 24) + RD2refdoubl * pow(2, 25) + M_Muxout * pow(2, 26) + LoNoisSpur * pow(2, 29));
R[3] = (unsigned long)(3 + D_Clk_div * pow(2, 3) + C_Clk_mode * pow(2, 15) + 0 * pow(2, 17) + F1_Csr * pow(2, 18) + 0 * pow(2, 19) + F2_ChgChan * pow(2, 21) + F3_ADB * pow(2, 22) + F4_BandSel * pow(2, 23) + 0 * pow(2, 24));
R[4] = (unsigned long)(4 + D_out_PWR * pow(2, 3) + D_RF_ena * pow(2, 5) + D_auxOutPwr * pow(2, 6) + D_auxOutEna * pow(2, 8) + D_auxOutSel * pow(2, 9) + D_MTLD * pow(2, 10) + D_VcoPwrDown * pow(2, 11) + B_BandSelClk * pow(2, 12) + D_RfDivSel * pow(2, 20) + D_FeedBck * pow(2, 23));
R[5] = (unsigned long)(5 + 0 * pow(2, 3) + 3 * pow(2, 19) + 0 * pow(2, 21) + D_LdPinMod * pow(2, 22));
}