また、7MHz CW送信機として使う場合、フルブレイクインは出来ない。
DDS発振周波数は、3.5MHzから8.5MHzとした。これで3.5MHzから50MHz(6逓倍すれば)のVFOとなる。周波数設定は、周波数範囲が広いため、STEPに1MHzを追加した。
今回、チャンネルスイッチをプッシュボタンに変更したため、チャンネル切替時全てのチャンネルが、メモリー保存できる様に変更した。 新たにMULスイッチを追加した。MULスイッチで、DDS発振周波数の表示ができる。例えば、50.6MHzの時、MULスイッチ操作した表示が左側の写真である。この状態でエンコーダを回すと、1kHz/6 STEPで変化する。
回路図である。投稿済のBlogに公開した回路を一部変更とCQ hamradio記事の合体。
出力
3.5MHz 340mW
7MHz 300mW
8.433MHz 260mW
Program
周波数帯毎の運用周波数制限を行っている。範囲外の時、Overと表示。受信時および範囲外エラー時、DDS発振停止(0Hzを指定)。Arduino IDE1.0.6でコンパイルした。//////////////////////////////////////////////////////////////////////
// AD9834 DDS VFO program ver.1.0
// Copyright(C)2016.JA2GQP.All rights reserved.
//
// Frequency Limitted.
// <<<<< Arduino IDE 1.0.6 >>>>>
// 2016/3/3
// JA2GQP
//--------------------------------------------------------------------
// Function
// 1.STEP(1M,100k,10k,1k,100,10)
// 2.Channel Memory.Main Channel(Ch0) + 3 Channel(Ch1,Ch2,Ch3)
// 3.Protection Operation At The Time Of Transmission
//
//////////////////////////////////////////////////////////////////////
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <rotary.h>
#include <EEPROM.h>
//---------- LCD Pin Assign ------------------
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for
// a 16 chars and 2 line display
//---------- Define Constant Value ----------
const byte ENC_A = 2; // Encorder A
const byte ENC_B = 3; // B
const byte SDATA = 4; // AD9834 SDATA
const byte SCLK = 5; // SCLK
const byte FSYNC = 6; // FSYNC
const byte SW_STEP = 7; // STEP SW
const byte SW_CH = 8; // CH SW
const byte SW_ENT = 9; // ENT SW
const byte SW_MUL = 10; // MUL SW
const byte SW_TX = 13; // TX SW
const long DEF_STP = 1000L; // Init STEP
const long LW_VFO80 = 3500000L; // 3.5MHz Lower Limit
const long HI_VFO80 = 3575000L; // Upper Limit
const long LW_VFO40 = 7000000L; // 7MHz Lower Limit
const long HI_VFO40 = 7200000L; // Upper Limit
const long LW_VFO20 = 14000000L; // 14MHz Lower Limit
const long HI_VFO20 = 14350000L; // Upper Limit
const long LW_VFO15 = 21000000L; // 21MHz Lower Limit
const long HI_VFO15 = 21450000L; // Upper Limit
const long LW_VFO10 = 28000000L; // 28MHz Lower Limit
const long HI_VFO10 = 29700000L; // Upper Limit
const long LW_VFO6 = 50000000L; // 50MHz Lower Limit
const long HI_VFO6 = 54000000L; // Upper Limit
const long DEF_VFO = 7050000L; // Vfo Default Frequency
const unsigned long DDS_CLK = 56000000L; // AD9834 Clock 56Mhz
const unsigned long TWO_E28 = 268435456L; // 2^28
//---------- EEPROM Memory Address ----------
const byte Frq_Eep0 = 0x00; // Frequency Ch0
const byte Frq_Eep1 = 0x04; // Ch1
const byte Frq_Eep2 = 0x08; // Ch2
const byte Frq_Eep3 = 0x0c; // Ch3
const byte Stp_Eep0 = 0x10; // STEP Ch0
const byte Stp_Eep1 = 0x14; // Ch1
const byte Stp_Eep2 = 0x18; // Ch2
const byte Stp_Eep3 = 0x1c; // Ch3
const byte Chn_Eep = 0x20; // Channel
//---------- Encorder Pin Assign(INT) --------
Rotary r = Rotary(ENC_A,ENC_B); // 2 = ENC_A,3 = ENC_B
//---------- Memory Assign -------------------
long Vfo_Dat = 0; // VFO Data
long Dds_Dat = 0; // DDS Data
long Enc_Stp = 0; // STEP
long Lng_Wk1 = 0; // Long Work1
char *Lcd_Dat = " "; // Lcd Display Buffer
byte Byt_Chn = 0; // Channel SW
byte Byt_Chnb = 0; // Channel SW Old
byte Flg_Tx = 0; // TX Flag
byte Flg_Mul = 0; // Multi Flag
byte Byt_Mul = 0;
//---------- Initialization Program ---------------
void setup(){
lcd.init(); // initialize the lcd
lcd.backlight(); // LCD backlight on
pinMode(SW_STEP,INPUT_PULLUP);
pinMode(SW_ENT,INPUT_PULLUP);
pinMode(SW_MUL,INPUT_PULLUP);
pinMode(SW_TX,INPUT_PULLUP);
pinMode(SW_CH,INPUT_PULLUP);
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei(); // INT Enable
pinMode(FSYNC,OUTPUT);
pinMode(SCLK,OUTPUT);
pinMode(SDATA,OUTPUT);
Flg_Tx = 0;
lcd.clear();
Byt_Chn = EEPROM.read(Chn_Eep);
if((Byt_Chn < 0) || (Byt_Chn > 3))
Byt_Chn = 0;
Byt_Chnb = Byt_Chn;
Fnc_Eep_Rd(); // EEPROM Read
Fnc_Band(); // Band check
}
//---------- Main program ---------------
void loop() {
if(Flg_Tx == 0){ // TX off?
if(digitalRead(SW_STEP) == LOW){ // STEP SW On?
Fnc_Stp(); // Yes,STEP proc.
}
if(digitalRead(SW_ENT) == LOW){ // ENT SW On?
Fnc_Ent(); // Yes,ENT proc.
}
if(digitalRead(SW_MUL) == LOW){ // MUL SW On?
Fnc_Mul(); // Yes,MUL proc.
}
if(digitalRead(SW_CH) == LOW){ // CH SW On?
Fnc_Chsw();
}
if(Byt_Chnb != Byt_Chn){ // CH SW OLD != NEW?
Fnc_Eep_Wt(Byt_Chnb);
Byt_Chnb = Byt_Chn;
Fnc_Eep_Rd();
}
}
if(digitalRead(SW_TX) == LOW){ // Tx On?
Flg_Tx = 1; // Yes,Flg_Tx Set
Dds_Dat = Vfo_Dat;
}
else{
Flg_Tx = 0; // No,Flg_Tx Reset
Dds_Dat = 0;
}
Fnc_Band(); // Band check
if(Byt_Mul != 255)
Fnc_Dds(Dds_Dat / Byt_Mul); // AD9834 DDS Out
else
Fnc_Dds(0);
Fnc_Lcd(); // LCD Display
delay(100);
}
//---------- Encorder procedure(INT) ---------------
ISR(PCINT2_vect) {
unsigned char result = r.process();
if(Flg_Tx == 0){
if(result) {
if(result == DIR_CW)
Vfo_Dat = Vfo_Dat + Enc_Stp;
else
Vfo_Dat = Vfo_Dat - Enc_Stp;
}
}
}
//---------- Function DDS set ---------------
void Fnc_Dds(double frquency){
unsigned long wrk = frquency * TWO_E28 / DDS_CLK;
unsigned int wrk1,wrk2,wrk3;
wrk1 = 0x2000;
wrk2 = wrk & 0x3fff;
wrk2 = wrk2 | 0x4000;
wrk3 = wrk >> 14;
wrk3 = wrk3 & 0x3fff;
wrk3 = wrk3 | 0x4000;
digitalWrite(SCLK,HIGH);
digitalWrite(FSYNC,LOW);
shiftOut(SDATA,SCLK,MSBFIRST,(wrk1 >> 8));
shiftOut(SDATA,SCLK,MSBFIRST,wrk1);
shiftOut(SDATA,SCLK,MSBFIRST,(wrk2 >> 8));
shiftOut(SDATA,SCLK,MSBFIRST,wrk2);
shiftOut(SDATA,SCLK,MSBFIRST,(wrk3 >> 8));
shiftOut(SDATA,SCLK,MSBFIRST,wrk3);
digitalWrite(FSYNC,HIGH);
}
//---------- Function Encorder STEP ---------
void Fnc_Stp(){
if(Enc_Stp == 10){ // Step = 10Hz ?
Enc_Stp = 1000000; // Yes,1MHz set
}
else{
Enc_Stp = Enc_Stp / 10; // Step down 1 digit
}
delay(250);
Fnc_Step_Disp();
Fnc_Lcd();
while(digitalRead(SW_STEP) == LOW)
;
delay(250);
}
//---------- Function STEP Display ----------
void Fnc_Step_Disp(){
lcd.setCursor(0,1);
switch(Enc_Stp){
case 10:
lcd.print("10 ");
break;
case 100:
lcd.print("100 ");
break;
case 1000:
lcd.print("1k ");
break;
case 10000:
lcd.print("10k ");
break;
case 100000:
lcd.print("100k");
break;
case 1000000:
lcd.print("1M ");
break;
}
}
//---------- Function String Dot Edit --------
char *Fnc_Dot_Edit(char *str,long n){
int i = 0; // Write the number
char *p = str;
unsigned long u = abs(n);
do{
*p++ = "0123456789"[u % 10];
u = u / 10;
i++;
if((0 != u) && (0 == (i % 3)))
*p++ = '.';
}
while( 0 != u );
if ( n < 0 )
*p++ = '-';
*p = '\0';
Fnc_Revr( str );
return str;
}
//---------- Function String Reverse ---------
void Fnc_Revr(char *str){
int i,n;
char c;
n=strlen(str);
for(i = 0;i < n / 2;i++){
c=str[i];
str[i]=str[n - i - 1];
str[n - i - 1]=c;
}
}
//---------- Function Save EEPROM 2byte ---------
void Fnc_Eep_Sav2(unsigned int value,int address){
address += 1;
for(int i = 0;i < 2;i++){
byte toSave = value & 0xFF;
if(EEPROM.read(address) != toSave){
EEPROM.write(address,toSave);
}
value = value >> 8;
address--;
}
}
//---------- Function Save EEPROM 4byte ---------
void Fnc_Eep_Sav4(long value,int address){
address += 3;
for(int i = 0;i < 4;i++){
byte toSave = value & 0xFF;
if(EEPROM.read(address) != toSave){
EEPROM.write(address,toSave);
}
value = value >> 8;
address--;
}
}
//---------- Function Load EEPROM 2byte ---------
unsigned int Fnc_Eep_Lod2(int address){
unsigned int value = EEPROM.read(address);
value = value << 8;
return value | EEPROM.read(address + 1);
}
//---------- Function Load EEPROM 4byte ---------
long Fnc_Eep_Lod4(int address){
long value = 0;
for(int i = 0;i < 4;i++){
value = value | EEPROM.read(address);
if( i < 3){
value = value << 8;
address++;
}
}
return value;
}
//---------- Function LCD Display ---------
void Fnc_Lcd(){
if(Flg_Tx == 1){
lcd.setCursor(0,0);
lcd.print("T");
}
else{
lcd.setCursor(0,0);
lcd.print(Byt_Chn);
}
Fnc_Step_Disp();
lcd.setCursor(5,1);
if((Flg_Mul == 1) && (Byt_Mul != 255)){
lcd.print(" ");
lcd.setCursor(5,1);
lcd.print("x");
lcd.print(Byt_Mul);
Lng_Wk1 = Vfo_Dat / Byt_Mul;
}else if(Byt_Mul == 255){
lcd.print("Over");
Lng_Wk1 = Vfo_Dat;
}
else{
lcd.print(" ");
Lng_Wk1 = Vfo_Dat;
}
Fnc_Dot_Edit(Lcd_Dat,Lng_Wk1);
lcd.setCursor(1,0);
lcd.print(": ");
lcd.setCursor(3,0);
lcd.print(Lcd_Dat);
lcd.print("MHz");
lcd.setCursor(10,1);
lcd.print("JA2GQP");
}
//---------- Function ENT ---------
void Fnc_Ent(){
Fnc_Eep_Wt(Byt_Chn);
while(digitalRead(SW_ENT) == LOW)
;
delay(250);
}
//---------- Function Channel SW Check ---------
void Fnc_Chsw(){
switch(Byt_Chn){
case 0:
Byt_Chn = 1;
break;
case 1:
Byt_Chn = 2;
break;
case 2:
Byt_Chn = 3;
break;
case 3:
Byt_Chn = 0;
break;
default:
Byt_Chn = 0;
break;
}
while(digitalRead(SW_CH) == LOW)
;
delay(100);
}
//---------- Function EEPROM Read ---------
void Fnc_Eep_Rd(){
if(Fnc_Eep_Lod4(Frq_Eep0) <= 0){
Vfo_Dat = DEF_VFO;
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep0);
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep1);
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep2);
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep3);
}
else{
switch(Byt_Chn){
case 1:
Vfo_Dat = Fnc_Eep_Lod4(Frq_Eep1);
break;
case 2:
Vfo_Dat = Fnc_Eep_Lod4(Frq_Eep2);
break;
case 3:
Vfo_Dat = Fnc_Eep_Lod4(Frq_Eep3);
break;
default:
Vfo_Dat = Fnc_Eep_Lod4(Frq_Eep0);
break;
}
}
if(Vfo_Dat <= 0){
Vfo_Dat = DEF_VFO;
}
if(Fnc_Eep_Lod4(Stp_Eep0) <= 0){
Enc_Stp = DEF_STP;
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep0);
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep1);
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep2);
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep3);
}
else{
switch(Byt_Chn){
case 1:
Enc_Stp = Fnc_Eep_Lod4(Stp_Eep1);
break;
case 2:
Enc_Stp = Fnc_Eep_Lod4(Stp_Eep2);
break;
case 3:
Enc_Stp = Fnc_Eep_Lod4(Stp_Eep3);
break;
default:
Enc_Stp = Fnc_Eep_Lod4(Stp_Eep0);
break;
}
}
if(Enc_Stp <= 0){
Enc_Stp = DEF_STP;
}
}
//---------- Function Band ---------
void Fnc_Band(){
if((Vfo_Dat >= LW_VFO80) && (Vfo_Dat <= HI_VFO80))
Byt_Mul = 1;
else if((Vfo_Dat >= LW_VFO40) && (Vfo_Dat <= HI_VFO40))
Byt_Mul = 1;
else if((Vfo_Dat >= LW_VFO20) && (Vfo_Dat <= HI_VFO20))
Byt_Mul = 2;
else if((Vfo_Dat >= LW_VFO15) && (Vfo_Dat <= HI_VFO15))
Byt_Mul = 3;
else if((Vfo_Dat >= LW_VFO10) && (Vfo_Dat <= HI_VFO10))
Byt_Mul = 4;
else if((Vfo_Dat >= LW_VFO6) && (Vfo_Dat <= HI_VFO6))
Byt_Mul = 6;
else
Byt_Mul = 255;
}
//---------- Function EEPROM Write ---------
void Fnc_Eep_Wt(byte chn){
switch(chn){
case 1:
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep1);
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep1);
break;
case 2:
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep2);
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep2);
break;
case 3:
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep3);
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep3);
break;
default:
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep0);
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep0);
break;
}
EEPROM.write(Chn_Eep,Byt_Chn);
}
//---------- Function Multi ---------
void Fnc_Mul(){
if(Flg_Mul == 0)
Flg_Mul = 1;
else
Flg_Mul = 0;
while(digitalRead(SW_MUL) == LOW)
;
delay(250);
}