2012年12月11日火曜日

50Mhz PLLユニット

TC9256を使った50Mhz 用PLLユニットです。コントロールは、ATTINY2313を使いBASCOMでプログラムを書きました。
メモリー1ch(プログラムで書いた値)とVFO 2個があり、電源off前のメモリー機能があります。
プログラムしたマイコンを初めて使うとき、EEPデータが無いので表示が乱れます。VFO0とVFO1をMem chで初期化してください。









LCD表示画面一例です。
VFO1を使い送信した状態です。










回路図です。
IF455khz(シングルスーパー用)の定数も参考値として書きました。




                                






'********************************************************
'50Mhz AM Tranceiver TC9256 PLL program
' Single super version(IF 455khz)         5khz step
'     Frequency 50.105Mhz to 50.895Mhz Limitted!
'                                       2012/09/03
' BASCOM AVR                              JA2GQP
'********************************************************
'
$regfile = "attiny2313.dat"
$crystal = 800000
Declare Sub Enc_sub                     'define subrutine
Declare Sub Pll_sub
Declare Sub Lcd_sub
Declare Sub Vfo_sub
Declare Sub Tx_sub
Declare Sub Mem_sub
'define memory
Dim Pll_adr As Byte                     'PLL command adress
Dim Pll_dat As Word                     '    freqency data
Dim Pll_cmd As Byte                     '    command
Dim Frq_wrk As Word                     'freqency
Dim Dsp_frq As String * 6               'Display frequency
Dim Frq_man As Word                     'main channel
Dim Flg As Byte                         'flag
Dim Flg_tx As Byte                      'TX flag
Dim Frqa_eep As Eram Word               'power off frequency A
Dim Frqb_eep As Eram Word               'power off frequency B
Dim Flg_eep As Eram Byte
'--------------
'Main roution
'--------------
Main:
   Disable Interrupts
   Config Lcdpin = Pin , Db7 = Portb.0 , Db6 = Portb.1
   Config Lcdpin = Pin , Db5 = Portb.2 , Db4 = Portb.3
   Config Lcdpin = Pin , E = Portb.4 , Rs = Portb.5
   Config Lcd = 16 * 2
   Config Porta.1 = Output              'Period
   'None,D6=TX,D5=VFO,D4=ENC B,D3=ENC A,D2=Main ch,D1=Clock,D0=Data
   Config Portd = &B00000011
   'None,Input=D6,D5,D4,D3,D2,Output=D0,D1
   Portd = &B01111100                   'pull up input pin
   Config Debounce = 1
   'PLL initial data set
   Pll_adr = &B11010000                 'pll CMD address
   Pll_cmd = &B01010110                 'Xtal 4.5Mhz,5khz step,FMl
   Frq_man = 10029                      '(50.60Mhz-455khz)/5khz
   Flg_tx = 0                           'initial TX flag
   Flg = Flg_eep                        'Restore memory
   If Flg = 0 Then
      Pll_dat = Frqa_eep
      Else
         Pll_dat = Frqb_eep
         End If
   Cursor Off
   Cls
   Call Pll_sub                         'Dummy write
   Call Pll_sub                         'PLL write
   Call Lcd_sub                         'LCD write
   Enable Interrupts
   Do
      If Flg_tx = 0 Then                'TX?
         Debounce Pind.2 , 0 , Mem_sub , Sub       '  no,recive!
         Debounce Pind.3 , 0 , Enc_sub , Sub
         Debounce Pind.5 , 0 , Vfo_sub , Sub
         Debounce Pind.6 , 0 , Tx_sub , Sub
         Else
            If Pind.6 = 1 Then          'Send SW off?
               Flg_tx = 0
               Call Pll_sub
               Locate 2 , 7
               Lcd "  "
               End If
         End If
      Loop
End
'-----------------------------
'Memory channel set
'-----------------------------
Sub Mem_sub
   Pll_dat = Frq_man
   Call Pll_sub
   Call Lcd_sub
   If Flg = 0then
      Frqa_eep = Pll_dat
      Else
         Frqb_eep = Pll_dat
         End If
    While Pind.2 = 0
      Wend
End Sub
'-----------------------------
'Encoder counts and PLL set
'-----------------------------
Sub Enc_sub
   If Pind.4 = 1 Then                   'Up
      Pll_dat = Pll_dat + 1
      Else                              'down
         Pll_dat = Pll_dat - 1
         End If
   If Pll_dat <= 9929 Then              'pll_data <= (50.10Mhz-455khz)/5khz ?
      Pll_dat = 9930
      End If
   If Pll_dat >= 10089 Then             'pll_data >= (50.90Mhz-455khz)/5khz ?
      Pll_dat = 10088
      End If
   Call Pll_sub
   Call Lcd_sub
   If Flg = 0then
      Frqa_eep = Pll_dat
      Else
         Frqb_eep = Pll_dat
         End If
End Sub
'-----------------------------
'TC9256 Data write
'-----------------------------
Sub Pll_sub
   Set Portd.0                          'Data is High
   Set Portd.1                          'Clock is High
   Set Porta.1                          'period is High
   Reset Porta.1                        'period is Low
   Shiftout Portd.0 , Portd.1 , Pll_adr , 2 , 8 , 1       'ADDRESS set
   Set Porta.1
   Shiftout Portd.0 , Portd.1 , Pll_dat , 2 , 16 , 1       'PLL data set
   Shiftout Portd.0 , Portd.1 , Pll_cmd , 2 , 8 , 1
   Reset Porta.1
End Sub
'-----------------------------
'LCD Data write
'-----------------------------
Sub Lcd_sub
   Cls
   Locate 1 , 1
   Frq_wrk = Pll_dat * 5
   Frq_wrk = Frq_wrk + 455              'pll_dat+455khz
   Dsp_frq = Str(frq_wrk)
   Dsp_frq = Format(dsp_frq , "00.000")
   Lcd "FREQ:" ; Dsp_frq ; "Mhz"
   Locate 2 , 1
   Lcd "VFO:" ; Flg
   Locate 2 , 7
   Lcd "  "
   Locate 2 , 10
   Lcd "JA2GQP"
End Sub
'-----------------------------
'VFO
'-----------------------------
Sub Vfo_sub
   If Flg = 0then
      Flg = 1
      Pll_dat = Frqb_eep
      Else
         Flg = 0
         Pll_dat = Frqa_eep
         End If
   Flg_eep = Flg
   Call Pll_sub
   Call Lcd_sub
   While Pind.5 = 0
      Wend
End Sub

'-----------------------------
'TX
'-----------------------------
Sub Tx_sub
   If Flg_tx = 0 Then
      Flg_tx = 1
      Frq_wrk = Pll_dat
      Pll_dat = Pll_dat + 91            'pll_dat+455khz
      Call Pll_sub                      'PLL data write
      Pll_dat = Frq_wrk
      Locate 2 , 7
      Lcd "TX"
      End If
End Sub







0 件のコメント: