回路図。
出力回路は、抵抗で終端したが、1対1のトランスにすると出力(現在、160uW at 17.05MHz)が6dB増える。ミキサー回路に使うのであれば、このままでも良いかも知れない。
Filter DesignによるLPFシュミレーション結果。
program
AD9851とAD9850の違いは、DDS_CLK = 192000000LとDDS_CMD = B00000001の2行である。(基準クロック 6倍のパラメータ)
//////////////////////////////////////////////////////////////////////
// AD9851 DDS VFO Premixed type program ver.1.0
//
// Copyright(C)2014-2015.JA2GQP.All rights reserved.
//
// 7.000MHz to 7.200MHz Limitted.
// (Target frequency = IF frquency + frequency)
// 2015/1/20
// JA2GQP
//--------------------------------------------------------------------
// Function
// 1.Upper Heterodyne(Target Frequency = IF Frequency + Frequency)
// 2.RIT Operation(-50kHZ to 50kHZ)
// 3.STEP(100k,10k,1k,100,10)
// 4.Memory Operation is Push RIT
// (Frequency and Step)
// 5.Protection Operation At The Time Of Transmission
// 6.Channel Memory.Main Channel(Ch0) + 3 Channel(Ch1,Ch2,Ch3)
// 7.Split Operation(7.00MHz to 7.20MHz Limited!)
//--------------------------------------------------------------------
// Library
// http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
//
//////////////////////////////////////////////////////////////////////
#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; // Encoeder B
const byte DATA = 4; // DIO4
const byte W_CLK = 5; // DIO5
const byte FQ_UD = 6; // DIO6
const byte SW_STEP = 7; // STEP Sw
const byte SW_RIT = 8; // RIT Sw
const byte SW_SPLIT = 9; // SPLIT Sw
const byte SW_CH1 = 10; // Channel 1
const byte SW_CH2 = 11; // 2
const byte SW_CH3 = 12; // 3
const byte SW_TX = 13; // TX Sw
const long IF_FRQ = 9996500L; // IF Frequency
const long LW_FRQ = 7000000L; // Lower Limit
const long HI_FRQ = 7200000L; // Upper Limit
const long DEF_FRQ = 7050000L; // Init Frequency
const long DEF_STP = 1000L; // Init STEP
const long LW_RIT = -50000L; // RIT Lower Limit
const long HI_RIT = 50000L; // RIT Upper Limit
const long LW_VFO = IF_FRQ + LW_FRQ; // Vfo Lower Limit
const long HI_VFO = IF_FRQ + HI_FRQ; // Vfo Upper Limit
const long DEF_VFO = IF_FRQ + DEF_FRQ; // Vfo Default Frequency
const unsigned long DDS_CLK = 192000000L; // AD9851 Clock(32MHz * 6)
const unsigned long TWO_E32 = 4294967295L;// 2^32
const byte DDS_CMD = B00000001; // AD9851 Command
//---------- 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
//---------- 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 Rit_Dat = 0; // RIT Data
long Rit_Datb = 0; // RIT Data Old
long Enc_Stp = 0; // STEP
long Lng_Wk1 = 0; // Long Work1
long Lng_Wk2 = 0; // Long Work2
char *Lcd_Dat = " "; // Lcd Display Buffer
byte Byt_Chn = 0; // Channel SW
byte Byt_Chnb = 0; // Channel SW Old
byte Flg_Rit = 0; // RIT Flag
byte Flg_Ritb = 0; // RIT Flag Old
byte Flg_Tx = 0; // TX Flag
byte Flg_Spl = 0; // SPLIT Flag
//---------- Initialization Program ---------------
void setup(){
lcd.init(); // initialize the lcd
lcd.backlight(); // LCD backlight on
pinMode(SW_STEP,INPUT_PULLUP);
pinMode(SW_RIT,INPUT_PULLUP);
pinMode(SW_SPLIT,INPUT_PULLUP);
pinMode(SW_TX,INPUT_PULLUP);
pinMode(SW_CH1,INPUT_PULLUP);
pinMode(SW_CH2,INPUT_PULLUP);
pinMode(SW_CH3,INPUT_PULLUP);
lcd.begin(16, 2); // LCD 16*2
PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei(); // INT Enable
pinMode(FQ_UD,OUTPUT);
pinMode(W_CLK,OUTPUT);
pinMode(DATA,OUTPUT);
Flg_Tx = 0;
Flg_Rit = 0;
Flg_Spl = 0;
lcd.clear();
Fnc_Chsw(); // Channel Sw Read
Byt_Chnb = Byt_Chn;
Fnc_Eep_Rd(); // EEPROM Read
}
//---------- 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_RIT) == LOW){ // RIT Sw On?
Fnc_Rit(); // Yes,RIT proc.
}
if(digitalRead(SW_SPLIT) == LOW){ // SPLIT Sw On?
Fnc_Spl(); // Yes,SPLIT proc.
}
Fnc_Chsw(); // Channel Sw read
if(Byt_Chnb != Byt_Chn){ // Channnel SW Chenge?
if(Byt_Chnb == 0){ // Channnel 0?
Fnc_Eep_Sav4(Vfo_Dat,Frq_Eep0); // Yes,Vfo_Dat Save
Fnc_Eep_Sav4(Enc_Stp,Stp_Eep0); // Enc_Step Save
Flg_Ritb = Flg_Rit;
Rit_Datb = Rit_Dat;
Flg_Rit = 0;
Flg_Spl = 0;
Rit_Dat = 0;
}
if(Byt_Chnb != 0){ // Other(Ch1-Ch3) Channnel?
Flg_Rit = 0;
Flg_Spl = 0;
if((Byt_Chn == 0) && (Flg_Ritb == 1)){
Flg_Rit = 1;
Rit_Dat = Rit_Datb;
}
}
Byt_Chnb = Byt_Chn;
Fnc_Eep_Rd();
}
}
if(digitalRead(SW_TX) == LOW){ // Tx On?
Flg_Tx = 1; // Yes,Flg_Tx Set
}
else{
Flg_Tx = 0; // No,Flg_Tx Reset
}
if(Flg_Rit == 1){ // RIT?
Dds_Dat = Vfo_Dat + Rit_Dat; // Yes,Dds_Dat Set
}
else{
Dds_Dat = Vfo_Dat; // No,Dds_Dat Set
}
if(Flg_Tx == 1){ // Tx?
if(Flg_Spl == 1){ // SPLIT?
Dds_Dat = Vfo_Dat + Rit_Dat; // Yes,Dds_Dat Set
}
else{
Dds_Dat = Vfo_Dat; // No,Dds_Dat Set
}
}
Fnc_Dds(Dds_Dat); // AD9850 DDS Out
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){
Lng_Wk1 = Vfo_Dat + Enc_Stp;
Lng_Wk2 = Rit_Dat + Enc_Stp;
}
else{
Lng_Wk1 = Vfo_Dat - Enc_Stp;
Lng_Wk2 = Rit_Dat - Enc_Stp;
}
if((Flg_Rit == 1) || (Flg_Spl == 1)){
Rit_Dat = Lng_Wk2;
}
else{
Vfo_Dat = Lng_Wk1;
Rit_Dat = 0;
}
Vfo_Dat = constrain(Vfo_Dat,LW_VFO,HI_VFO);
if(Flg_Spl == 1){
Rit_Dat = constrain(Rit_Dat,(LW_VFO - Vfo_Dat),(HI_VFO - Vfo_Dat));
}
else{
Rit_Dat = constrain(Rit_Dat,LW_RIT,HI_RIT);
}
}
}
}
//---------- Function DDS set ---------------
void Fnc_Dds(double frquency){
unsigned long wrk = frquency * TWO_E32 / DDS_CLK;
digitalWrite(FQ_UD,LOW);
shiftOut(DATA,W_CLK,LSBFIRST,wrk);
shiftOut(DATA,W_CLK,LSBFIRST,(wrk >> 8));
shiftOut(DATA,W_CLK,LSBFIRST,(wrk >> 16));
shiftOut(DATA,W_CLK,LSBFIRST,(wrk >> 24));
shiftOut(DATA,W_CLK,LSBFIRST,DDS_CMD); // AD9851 command
digitalWrite(FQ_UD,HIGH);
}
//---------- Function Encorder STEP ---------
void Fnc_Stp(){
if(Enc_Stp == 10){ // Step = 10Hz ?
Enc_Stp = 100000; // Yes,100khz 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);
lcd.print(" "); // Clear step display
lcd.setCursor(0,1);
if(1 <= (Enc_Stp / 1000)){ // kiro?
lcd.print(Enc_Stp / 1000); // Yes,Convert kiro
lcd.print("k");
}
else{
lcd.print(Enc_Stp);
}
}
//---------- 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();
if(Flg_Rit == 1){
lcd.setCursor(5,1);
lcd.print("R: ");
Fnc_Dot_Edit(Lcd_Dat,Rit_Dat);
lcd.setCursor(7,1);
lcd.print(Lcd_Dat);
if((Rit_Dat >= 1000) || (Rit_Dat <= -1000)){
lcd.print("k");
}
}
if(Flg_Spl == 1){
lcd.setCursor(5,1);
lcd.print("X: ");
Fnc_Dot_Edit(Lcd_Dat,Rit_Dat);
lcd.setCursor(7,1);
lcd.print(Lcd_Dat);
if((Rit_Dat >= 1000) || (Rit_Dat <= -1000)){
lcd.print("k");
}
}
if((Flg_Rit == 0) && (Flg_Spl == 0)){
Fnc_Dot_Edit(Lcd_Dat,Vfo_Dat - IF_FRQ);
lcd.setCursor(1,0);
lcd.print(": ");
lcd.setCursor(3,0);
lcd.print(Lcd_Dat);
lcd.print("MHz");
lcd.setCursor(5,1);
lcd.print(" JA2GQP");
}
}
//---------- Function Rit ---------
void Fnc_Rit(){
if(Flg_Rit == 0){
Rit_Dat = 0;
Flg_Rit = 1;
Flg_Spl = 0;
switch(Byt_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;
}
}
else{
Flg_Rit = 0;
}
while(digitalRead(SW_RIT) == LOW)
;
delay(250);
}
//---------- Function Channel SW Check ---------
void Fnc_Chsw(){
if(digitalRead(SW_CH1) == LOW){
Byt_Chn = 1;
}
else if(digitalRead(SW_CH2) == LOW){
Byt_Chn = 2;
}
else if(digitalRead(SW_CH3) == LOW){
Byt_Chn = 3;
}
else{
Byt_Chn = 0;
}
}
//---------- Function EEPROM Read ---------
void Fnc_Eep_Rd(){
if(Fnc_Eep_Lod4(Frq_Eep0) <= LW_VFO){
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 Split ---------
void Fnc_Spl(){
if(Flg_Spl == 0){
Flg_Spl = 1;
Flg_Rit = 0;
Rit_Dat = 0;
}
else{
Flg_Spl = 0;
}
while(digitalRead(SW_SPLIT) == LOW)
;
delay(250);
}
1 件のコメント:
TNX for help to make my VFO
73 de Karl OE1KLA
コメントを投稿