2023年9月1日金曜日

Pico Stack SDR (Si5351A) 90度位相シフト テスト

Si5351A【CLK0】【CLK1】を90度移相シフト発信周波数をローテータエンコーダで選択するようにした。
7000000(7MHz)
14000000(14MHz) 
21000000(21MHz)
28000000(28MHz)
50000000(50MHz)
79500000(79.5MHz)
144000000(144MHz)

7MHz


















7MHzはSi5351A【CLK0】【CLK1】
90度移相シフトが【CLK0】方がなぜか90度遅れている?(7MHzはCLK0が遅れます)



14MHz




















21MHz




















28MHz




















50MHz




















79.5MHz





144MHz









Arduino IDE
【ボード:Raspberry Pi Pico】

プログラム 

//JA7MLC 2023/07/14

#include <Wire.h>
#include <LiquidCrystal.h>
//LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(4, 5, 0, 1, 2, 3);

#define Si5351A_ADDR 0x60
#define OUTPUT_CTRL 3 //Output Enable Control
#define CLK0_CTRL 16  //CLK0 Control
#define CLK1_CTRL 17  //CLK1 Control
#define CLK2_CTRL 18  //CLK2 Control
#define MSNA_ADDR 26  //Multisynth NA Parameters
#define MSNB_ADDR 34  //Multisynth NB Parameters
#define MS0_ADDR 42   //Multisynth0 Parameters
#define MS1_ADDR 50   //Multisynth1 Parameters
#define MS2_ADDR 58   //Multisynth2 Parameters
#define CLK0_PHOFF 165  //CLK0 Initial Phase Offset
#define CLK1_PHOFF 166  //CLK1 Initial Phase Offset
#define PLL_RESET 177   //PLL Reset
#define XTAL_LOAD_C 183 //Crystal Internal Load Capacitance

int Pointer=0;
int Pointer_OLD = Pointer;
uint32_t FREQ;
uint32_t frequency;
const uint32_t XtalFreq = 25000000; //25MHz

uint32_t P1;
uint32_t P2;
uint32_t P3;
uint32_t PllFreq;
uint32_t l;
float f;
uint8_t mult;
uint32_t num;
uint32_t denom;
uint32_t divider;
char PLL;
uint8_t PLL_ADDR;
uint8_t MS_ADDR;

//Rotary endoder関係の定義
#define ENC_A 17
#define ENC_B 14
#define SW_STEP 11
volatile uint8_t old_value = 0x11;
volatile uint8_t value = 0;
volatile int8_t count = 0;
volatile uint8_t D;
 
//ROtary encoder 割込みサービスルーチン
void rotary(){
  value = (digitalRead(ENC_B)<<1) | digitalRead(ENC_A);
  if(old_value != value){
    D = ((old_value << 1) ^ value) & 3;
    if(D < 2){
      count += 1;
    }else{
      count -= 1;
    }
  if(count >= 4){
    Pointer += 1;
    count = 0;
  }else if(count <= -4){
    Pointer -= 1;
    count = 0;
  }
  Pointer = constrain(Pointer,0,6); //下限と上限を超えないように
  old_value = value;
  }
}

void si5351(){
//PLLAのセット 900MHz,CLK0=10MHz 
//N(divider) = fvco(PLLA) / fout(CLK0)
frequency = FREQ;
divider = 900000000 / frequency; //divider = fvco / fout
if (divider % 2) divider--;
PLL_Set('A',frequency,divider);

//CLK0の設定
Si5351_write(CLK0_CTRL,0x4C); //Reg16 Sorce PLLA
MS_Set(0,divider);
Si5351_write(CLK0_PHOFF,0);//CLK0 delay 0

//CLK1の設定
Si5351_write(CLK1_CTRL,0x4C); //Reg17 Sorce PLLA
MS_Set(1,divider);
Si5351_write(CLK1_PHOFF,divider);//Reg166 delay T/4 (90degree)

Si5351_write(PLL_RESET,0xA0); //Reg177 PLLA and PLLB
}

void setup(){
  Wire.setSDA(12);  //SDA 
  Wire.setSCL(13);  //SCL  
  Wire.begin(); // Arduino is Master
  //ロータリーエンコーダとSTEP使用ピンの設定とプルアップ
  pinMode(ENC_A, INPUT_PULLUP);
  pinMode(ENC_B, INPUT_PULLUP);
  pinMode(SW_STEP, INPUT);  
  //ロータリーエンコーダ割込み設定
  attachInterrupt(ENC_A, rotary, CHANGE);
  attachInterrupt(ENC_B, rotary, CHANGE); 
 
  lcd.begin( 16, 2 ); 
  lcd.clear();
  FREQ=7000000;
  lcd.setCursor(3,1);
  lcd.print(FREQ);    
  Si5351_init(); //Si5351 initialize
  si5351();
}

void loop(){
  
  if(Pointer != Pointer_OLD){ //ローテータエンコーダを回転した時書換える
  switch (Pointer) {    
    case 0: FREQ=7000000 ; break;  
    case 1: FREQ=14000000 ; break;    
    case 2: FREQ=21000000 ; break;   
    case 3: FREQ=28000000 ; break;
    case 4: FREQ=50000000 ; break;
    case 5: FREQ=79500000 ; break;
    case 6: FREQ=144000000 ; break;
     }
     lcd.clear();
     lcd.setCursor(3,1);
     lcd.print(FREQ);
     si5351();
     Pointer_OLD = Pointer;
  }
  
    delay(10);
}

//Si5351のレジスタに1バイトデータを書き込む。
void Si5351_write(byte Reg , byte Data)
{
Wire.beginTransmission(Si5351A_ADDR);
Wire.write(Reg);
Wire.write(Data);
Wire.endTransmission();
}

//Si5351Aの初期化
void Si5351_init(){
Si5351_write(OUTPUT_CTRL,0xFF); //Reg3 Disable Output
Si5351_write(CLK0_CTRL,0x80); //Reg16 CLOCK0 Power down
Si5351_write(CLK1_CTRL,0x80); //Reg17 CLOCK1 Power down
Si5351_write(CLK2_CTRL,0x80); //Reg18 CLOCK2 Power down
Si5351_write(XTAL_LOAD_C,0x92); //Reg183 Crystal Load Capasitance=8pF
Si5351_write(PLL_RESET,0xA0); //Reg177 Reset PLLA and PLLB
Si5351_write(CLK0_CTRL,0x4F); //Reg16 CLOCK0 Power up
Si5351_write(CLK1_CTRL,0x4F); //Reg17 CLOCK0 Power up
// Si5351_write(CLK2_CTRL,0x4F); //Reg18 CLOCK0 Power up
Si5351_write(OUTPUT_CTRL,0xFC); //Reg3 Enable CLOCK0,CLOCK1
}

//PLLの設定
void PLL_Set(char Pll,uint32_t Freq,uint32_t Div){
PllFreq = Div * Freq; //fvco =d * fout
mult = PllFreq / XtalFreq; //整数部 mult = a = fvco / fxtal
l = PllFreq % XtalFreq; // L = fvco % fxtal
f = l;
f *= 1048575;
f /= XtalFreq;
num = f;
denom = 1048575;

P1 = (uint32_t)(128 * ((float)num /(float)denom)); //128*(b/c)
P1 = (uint32_t)(128 * (uint32_t)(mult) + P1 - 512); //128*a + (128*(b/c))-512 
P2 = (uint32_t)(128 * ((float)num / (float)denom)); //128*(b/c)
P2 = (uint32_t)(128 * num -denom * P2); //128*b–c*(128*(b/c))
P3=denom;

if (Pll == 'A')
{
PLL_ADDR = MSNA_ADDR;
}else
{
PLL_ADDR = MSNB_ADDR;
}
Parameter_write(PLL_ADDR,P1,P2,P3);
}

//MultiSynth(分周器)のセット
void MS_Set(uint8_t MS_No,uint32_t Div){
P1 = 128 * Div - 512;
P2 = 0;
P3 = 1;
switch(MS_No){
case 0:
MS_ADDR = MS0_ADDR;
break;
case 1:
MS_ADDR = MS1_ADDR;
break;
case 2:
MS_ADDR = MS2_ADDR;
break;
default:
MS_ADDR = MS0_ADDR;
}
Parameter_write(MS_ADDR,P1,P2,P3);
}

//レジスタにパラメータP1,P2,P3を書き込む。
void Parameter_write(uint8_t REG_ADDR,uint32_t Pa1,uint32_t Pa2,uint32_t Pa3)
{
Si5351_write(REG_ADDR + 0,(Pa3 & 0x0000FF00) >> 8);
Si5351_write(REG_ADDR + 1,(Pa3 & 0x000000FF));
Si5351_write(REG_ADDR + 2,(Pa1 & 0x00030000) >> 16);
Si5351_write(REG_ADDR + 3,(Pa1 & 0x0000FF00) >> 8);
Si5351_write(REG_ADDR + 4,(Pa1 & 0x000000FF));
Si5351_write(REG_ADDR + 5,((Pa3 & 0x000F0000) >> 12) | ((Pa2 & 0X000F0000) >> 16));
Si5351_write(REG_ADDR + 6,(Pa2 & 0x0000FF00) >> 8);
Si5351_write(REG_ADDR + 7,(Pa2 & 0x000000FF));

0 件のコメント:

コメントを投稿

Pi Pico Rx - SDR試作 7MHz SSB CW受信

Pi Pico Rx(0-30MHz,CW/SSB/AM/FM)シンプルSDRを試作して、注目したPico PIOアッセンブルによるIQ局発と直交ミキサの構成で7MHz SSB CWの受信を行いました( FMは29MHzFMモードで受信確認) 同ブログ関連記事 【 Pi Pico...