⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fsk调制.txt

📁 这是我们本学期的试验作业,FSK源码很多了,我这个加了很多详细注解.不妨参考一下.
💻 TXT
字号:
library IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity fsk is
port(clock: in std_logic; 
     a:in std_logic_vector(2 downto 0);     ----输入控制信号,3位用来选择M序列长度
     b:in std_logic_vector(1 downto 0);      ----输入控制信号,2位用来选择M序列反馈系数
     load:in std_logic; ----m序列控制信号
     d:out std_logic_vector (7 downto 0); 
     load_clock:buffer std_logic; 
      load_clock1:buffer std_logic; 
     code,coderate: buffer std_logic;
     jump_high:buffer std_logic;   
     jump_low:buffer std_logic);  
end fsk;

architecture ab of fsk is
 signal  q1: std_logic;
signal c0,c1,c2,c3,c4,c5,c6,c7:std_logic;                                                   ---所以采用双相码分别表示-1,1,0

signal count64:std_logic_vector (7 downto 0);
signal count32: std_logic_vector (4 downto 0);
signal count: std_logic_vector (2 downto 0);
signal count1: std_logic_vector (1 downto 0);
signal count20:std_logic_vector (3 downto 0);
signal sinclk: std_logic;
--signal sinclk1: std_logic;
signal temp:std_logic;
begin
process(clock) --100khz分频10得到load_clock为10khz
begin
  if(clock'event and clock='1') then
 if(count="100") then --记录10个周期
    count<="000";
   load_clock<=not load_clock;
   else count<=count+'1';
if(count20="1001") then --记录20个周期
    count20<="0000";
   load_clock1<=not load_clock1;
   else count20<=count20+'1';
end if;
  end if;
  end if;
end process;

--process(load_clock1)
--begin
 --if(load_clock1'event and load_clock1='1') then
--if(count1="11") then --4
  --  count1<="00";
   -- load_clock1<=not load_clock1;
  -- else count1<=count1+'1';
  -- end if;
 -- end if;
--end process;


process(load_clock1)  --load_clock分频64得到0.5KHz码元速率
begin
 if(load_clock1'event and load_clock1='1') then
   if(count32="11111") then --记录32个周期
    count32<="00000";
    coderate<=not coderate;
   else count32<=count32+'1';
   end if;
  end if;
end process;

process( coderate) ---m序列进程
begin
if  coderate'event and  coderate='1' then   -----二分频时钟信号上升沿
case a is
when "000"  =>  ---a为000,010,001分别表示M序列级数为0,1,2此时设置为复位
q1<='0';
when "001"  =>  
q1<='0';
when "010" =>     ---a为010代表M序列级数为2时此时序列长度为3,反馈系数为7=111 
if load='1' or ((  c1 or c0)='0') then
             -----load 优先控制 避免全零

c1<='1';
c0<='1';
q1<=c1;
else

c0<=c1 xor c0  ;  ------设置反馈方式
c1<=c0;
q1<=c1;
end if;
when "011" =>     ---a为011代表M序列级数为3时此时序列长度为7,反馈系数为13=1011 
if load='1' or ((  c2 or c1 or c0)='0')   then
             -----load 优先控制 避免全零
c2<='1';
c1<='1';
c0<='1';
q1<=c2;

else

c0<=c1 xor c2 ;  ------设置反馈方式
c2<=c1;
c1<=c0;
q1<=c2;
end if;
when "100" =>       ---a为100代表M序列级数为4时此时序列长度为15,反馈系数为23=10011  
if load='1' or (( c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零

c3<='0';
c2<='0';
c1<='0';
c0<='1';
q1<=c4;
else
c0<=c2 xor c3 ;  ------设置反馈方式
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c3;
end if;
when "101"=>     ---a为101代表M序列级数为5时此时序列长度为31,反馈系数为45,67,75  
case b is
when  "00" =>   -----b为00时,则设定此时无反馈系数
q1<='0';
when  "01" =>   -----b为01时,则设定此反馈系数为45=100101

if load='1' or (( c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c4;
else
c0<=c4  xor c2;  ------设置反馈方式
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c4;
end if;
when "10" =>   -----b为10时,则设定此反馈系数为67=110111
if load='1' or (( c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c4;
else
c0<=c4 xor c3 xor c2 xor c0 ;------设置反馈方式
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c4;
end if;
when "11" =>   -----b为11时,则设定此反馈系数为75=111101
if load='1' or (( c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c4;
else
c0<=c0 xor c1 xor c2 xor c4 ;  ------设置反馈方式
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c4;
end if;
when others =>
q1<='0';
end case;

when "110"=>     ---a为110代表M序列级数为6时此时序列长度为63,反馈系数为103,147,155
case  b  is
when  "00" =>   -----b为00时,则设定此时无反馈系数
q1<='0';

when "01" =>      ----b为00或01时,则设定此反馈系数为103=1000011

if load='1' or ((  c5 or c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零

c5<='0';
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c5;
else
c0<=c5  xor c4 ;  ------设置反馈方式
c5<=c4;
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c5;
end if;
when "10" =>   -----b为10时,则设定此反馈系数为147=1100111
if load='1' or (( c5 or c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零

c5<='0';
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c5;
else
c0<=c5 xor c4 xor c1 xor c0 ;  ------设置反馈方式
c5<=c4;
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c5;
end if;
when "11" =>   -----b为11时,则设定此反馈系数为155=1101101
if load='1' or (( c5 or c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零

c5<='0';
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c5;
else
c0<=c5 xor c4 xor c2 xor c1 ;  ------设置反馈方式
c5<=c4;
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c5;
end if;
when others =>
q1<='0';
end case;
when "111"=>     ---a为111代表M序列级数为7时此时序列长度为127,反馈系数为203,211,217,235,277,313,325,345,367
                 ----此处选择反馈系数203,211,217,235为例
case b is
when "00" =>   -----b为00时,则设定此反馈系数为203=10000011
if load='1' or ((c6 or c5 or c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零

c6<='0';
c5<='0';
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c6;
else
c0<=c6 xor c0 ;  ------设置反馈方式
c6<=c5;
c5<=c4;
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c6;
end if;
when "01" =>   -----b为01时,则设定此反馈系数为211=10001001
if load='1' or (( c6 or c5 or c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零
c6<='0';
c5<='0';
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c6;
else
c0<=c6 xor  c2 ;  ------设置反馈方式
c6<=c5;
c5<=c4;
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c6;
end if;
when "10" =>   -----b为10时,则设定此反馈系数为217=10001111
if load='1' or ((c6 or c5 or c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零
c6<='0';
c5<='0';
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c6;
else
c0<=c6 xor c2 xor c1 xor c0 ;  ------设置反馈方式
c6<=c5;
c5<=c4;
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c6;
end if;
when "11" =>   -----b为10时,则设定此反馈系数为235=10011101
if load='1' or (( c6 or c5 or c4 or c3 or c2 or c1 or c0)='0') then
             -----load 优先控制 避免全零
c6<='0';
c5<='0';
c4<='0';
c3<='0';
c2<='0';
c1<='1';
c0<='1';
q1<=c6;
else

c0<=c6 xor c3 xor c2 xor c1;  ------设置反馈方式

c6<=c5;
c5<=c4;
c4<=c3;
c3<=c2;
c2<=c1;
c1<=c0;
q1<=c6;
end if;
when others=>
q1<='0';
end case;
when others=>
q1<='0';
end case;
end if;
end  process;
code<=q1;
sinclk<=load_clock; 
--sinclk1<=load_clock1;   
jump_high<=(not temp) and code; --0到1跳变
jump_low<=(not code) and temp;  --1到0跳变

 
process(sinclk)
begin
 if(sinclk'event and sinclk='1') then
         temp<=code;     
   if((jump_high='1')or(count64="00111111")or (jump_low='1')) 
               then count64<="00000000"; 
        elsif(temp='0')then 
             if(count1="01")then
                  count1<="00";
          count64<=count64+'1';
                else count1<=count1+'1';
          --end if;

            if (temp='1')then 
               count64<=count64+'1';   
  end if;         
 end if;
   end if;          
 end if;           
         
--end if;
  -- end if;
    
--if(sinclk1'event and sinclk1='1') then
   --if((jump_low='1')or(count64="00111111")) 
              -- then count64<="00000000"; 
        --elsif(temp='1') then 
          --count64<=count64+'1';   
  -- end if;      
   --end if;
end process;


process(count64)
begin
 case count64 is
when "00000000"=> d<="00000000"  ;when "00000001"=> d<="00000001"  ;
when "00000010"=> d<="00000100"  ;when "00000011"=> d<="00001000"  ;
when "00000100"=> d<="00001101"  ;when "00000101"=> d<="00010011"  ;
when "00000110"=> d<="00011010"  ;when "00000111"=> d<="00100010"  ;
when "00001000"=> d<="00101011"  ;when "00001001"=> d<="00110101"  ;
when "00001010"=> d<="01000000"  ;when "00001011"=> d<="01001011"  ;
when "00001100"=> d<="01010111"  ; when "00001101"=> d<="01100011"  ;
when "00001110"=> d<="01110000"  ;when "00001111"=> d<="01111100"  ;
when "00010000"=> d<="10001001"  ; when "00010001"=> d<="10010110"  ;
when "00010010"=> d<="10100010"  ;when "00010011"=> d<="10101110"  ;
when "00010100"=> d<="10111010"  ; when "00010101"=> d<="11000101"  ;
when "00010110"=> d<="11001111"  ;when "00010111"=> d<="11011001"  ;
when "00011000"=> d<="11100001"  ; when "00011001"=> d<="11101001"  ;
when "00011010"=> d<="11101111"  ;when "00011011"=> d<="11110101"  ;
when "00011100"=> d<="11111001"  ; when "00011101"=> d<="11111100"  ;
when "00011110"=> d<="11111110"  ;when "00011111"=> d<="11111111"  ;

when "00100000"=> d<="11111111"  ; when "00100001"=> d<="11111110"  ;
when "00100010"=> d<="11111100"  ;when "00100011"=> d<="11111001"  ;
when "00100100"=> d<="11110101"  ; when "00100101"=> d<="11101111"  ;
when "00100110"=> d<="11101001"  ;when "00100111"=> d<="11100001"  ;
when "00101000"=> d<="11011001"  ; when "00101001"=> d<="11001111"  ;
when "00101010"=> d<="11000101"  ;when "00101011"=> d<="10111010"  ;
when "00101100"=> d<="10101110"  ; when "00101101"=> d<="10100010"  ;
when "00101110"=> d<="10010110"  ;when "00101111"=> d<="10001001"  ;
when "00110000"=> d<="01111100"  ; when "00110001"=> d<="01110000"  ;
when "00110010"=> d<="01100011"  ;when "00110011"=> d<="01010111"  ;
when "00110100"=> d<="01001011"  ; when "00110101"=> d<="01000000"  ;
when "00110110"=> d<="00110101"  ;when "00110111"=> d<="00101011"  ;
when "00111000"=> d<="00100010"  ; when "00111001"=> d<="00011010"  ;
when "00111010"=> d<="00010011"  ;when "00111011"=> d<="00001101"  ;
when "00111100"=> d<="00001000"  ; when "00111101"=> d<="00000100"  ;
when "00111110"=> d<="00000001"  ;when "00111111"=> d<="00000000"  ;

 when others=>null;
end case;
end process;

end ab; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -