久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2949|回復: 0
打印 上一主題 下一主題
收起左側

波形發生FPGA程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:419865 發表于 2018-11-2 20:06 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
多功能波形發生器VHDL程序與仿真
--文件名:mine4.vhd。
--功能:實現4種常見波形正弦、三角、鋸齒、方波(A、B)的頻率、幅度可控輸出(方波
--A的占空比也是可控的),可以存儲任意波形特征數據并能重現該波形,還可完成
--各種波形的線形疊加輸出。
--說明: SSS(前三位)和SW信號控制4種常見波形種哪種波形輸出。4種波形的頻率、
--幅度(基準幅度A)的調節均是通過up、down、set按鍵和4個BCD碼置入器以及一
--個置入檔位控制信號(ss)完成的(AMP的調節范圍是0~5V,調節量階為1/51V)。
--其中方波的幅度還可通過u0、d0調節輸出數據的歸一化幅值(AMP0)進行進一步
--細調(調節量階為1/(51*255)V)。方波A的占空比通過zu、zp按鍵調節(調節
--量階1/64*T)。系統采用內部存儲器——RAM實現任意輸入波形的存儲,程序只支
--持鍵盤式波形特征參數置入存儲,posting 為進入任意波置入(set)、清除(clr)狀態
--控制信號,SSS控制存儲波形的輸出。P180為預留端口,
--最后修改日期:2004.3.26。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity mine4 is
port(clk : in std_logic;                                        --時鐘信號輸入
      set, clr, up, down, zu, zd : in std_logic;              --各個波形特征的調節觸發信號
      posting : in std_logic;                                    --任意波鍵盤置入信號
      u0,d0,sw : in std_logic;           --方波A、B的切換sw,和方波B的幅度調節按鍵
      ss : in std_logic_vector( 3 downto 0 );                        --檔位選擇信號
      sss : in std_logic_vector( 4 downto 0 );                       --波形選擇信號
      Data3, Data2, Data1,Data0 : in std_logic_vector(3 downto 0); --BCD碼輸入
      p180 : out std_logic;                                      --預留接口
      lcd : out std_logic_vector(7 downto 0);                       --顯示輸出
      shift : out std_logic_vector(3 downto 0);                      --位碼輸出
      dd, a : out std_logic_vector( 7 downto 0));                    --波形、幅度數據輸出
end mine4;
architecture behav of mine4 is
subtype word is std_logic_vector( 7 downto 0 );
type  unit is array(63 downto 0) of word;
signal ram : unit;
signal qqq : integer range 0 to 250000000;
signal qq : integer range 0 to 78125000;
signal tmp : integer range 0 to 9999;
signal coun : integer range 0 to 78125000;
signal coun0 : integer range 0 to 250000000;
signal b : integer range 0 to 78125000;
signal c : integer range 0 to 500000000;
signal z, con : integer range 0 to 63;
signal f : std_logic_vector( 7 downto 0 );
signal amp, amp0, d : std_logic_vector(7 downto 0);
signal bcd0,bcd1,bcd2,bcd3 : integer range 0 to 9;
signal bcd01,bcd11,bcd21,bcd31 : integer range 0 to 9;
signal bcd00,bcd10,bcd20,bcd30 : integer range 0 to 9;
signal y : integer range 0 to 9;
signal addr : integer range 0 to 63;
begin
qq<=781250 when ss="1000" else
      7812500 when ss="0100" else
      78125000 when ss="0010" else
      78125;
--qq信號對應SW=0時的檔位選擇信號SS,實現方波A和其他三種波形的頻率預置
qqq<= 500000 when ss="1000" else  
      5000000 when ss="0100" else
      50000000 when ss="0010" else
50000;
--qqq信號對應SW=1時的檔位選擇信號SS,實現方波B的頻率預置

process(clk)
--此進程分別描述了各種波形的頻率、幅度(方波A的占空比)調節以及各種波形的任意線
--形疊加等。
variable count4 : integer range 0 to 6250000;
variable count : integer range 0 to 78125000;
variable count3 : integer range 0 to 250000000;
variable count1 : integer range 0 to 12500000;
variable count0 : integer range 0 to 3249999;
variable ddd : std_logic_vector(9 downto 0);
variable dd0,dd1,dd2,dd3,dd4 : integer range 0 to 255;
variable adr : integer range 0 to 63;
begin
if rising_edge(clk) then
    if posting='1' then                              
      if count4=6249999 then count4:=0;              
adr:=conv_integer(Data3)*10+conv_integer(Data2);--存儲單位地址
        if adr<64 then   
          if set='1' then ram(adr)<=conv_std_logic_vector((conv_integer(Data1)*10
+conv_integer(Data0))*2,8); --對置入的任意波形數據進行儲存
          elsif clr='1' then  adr:=0;                             --存儲器所有單元清零
            for i in 0 to 63 loop
            ram(i)<=(others=>'0');
            end loop;
          end if;
        end if;
      else count4:=count4+1;
      end if;
    else  
if set='1' then coun<=0; b<=0; coun0<=0;c<=0;z<=31;amp0<="01111111"; addr<=0;
tmp<=conv_integer(Data3)*1000+conv_integer(Data2)*100
+conv_integer(Data1)*10+conv_integer(Data0);      --頻率數據
      amp<="01111111";                                     --幅值
      else
        if tmp>0 then
          if sw='0' then
            if coun<qq then coun<=coun+tmp; b<=b+1;    --頻率到采樣點間隔脈沖數轉換  
            else
              if count=b then count:=1;
                if f=63 then f<="00000000";
                else f<=f+1;
                end if;
                if sss="00010" then                                      --方波A
                  if con<=z then  dd<=amp0; con<=con+1;
                  elsif con=63 then con<=0; dd<="00000000";
                  else con<=con+1; dd<="00000000";
                  end if;
                elsif sss="10000" then dd<=d;                             --正弦波
                elsif sss="00100" then dd<=f(5 downto 0)&"00";              --鋸齒波
                elsif sss="01000" then --三角波
                  if f>31 then dd<=("111111"-f(5 downto 0))&"00";
                  else dd<=f(5 downto 0)&"00";
                  end if;
                elsif sss="00001" then                                   --任意波
                  if addr<63 then dd<=ram(addr); addr<=addr+1;
                  elsif addr=63 then dd<=ram(63); addr<=0;
                  end if;
                else                                  --完成5種波形的線形疊加
                  if sss(1)='1' then
                    if con<=z then con<=con+1;
dd0:=conv_integer(amp0);      --方波波形數據dd0
                    else con<=con+1; dd0:=0;
                    end if;
                  end if;
                  if sss(4)='1' then dd1:=conv_integer(d);        --正弦波波形數據dd1
                  end if;
                  if sss(2)='1' then dd2:=conv_integer(f(5 downto 0)&"00");
                                                          --鋸齒波波形數據dd2
                  end if;            
                  if sss(3)='1' then
                    if f>31 then dd3:=conv_integer(("111111"-f(5 downto 0))&"00");
                    else dd3:=conv_integer(f(5 downto 0)&"00"); --三角波波形數據dd3
                    end if;
                  end if;
                  if sss(0)='1' then
                    if addr<63 then dd4:=conv_integer(ram(addr)); addr<=addr+1;
                    elsif addr=63 then dd4:=conv_integer(ram(63)); addr<=0;
                    end if;                                --任意波波形數據dd4
                  end if;
                ddd:=conv_std_logic_vector((dd0+dd1+dd2+dd3+dd4),10);
--波形線形疊加輸出
                dd<=ddd(9 downto 2);
                end if;
              else count:=count+1;
              end if;
            end if;
          else
            if coun0<qqq then coun0<=coun0+tmp; c<=c+1;
            else
              if count3<=c/2 then count3:=count3+1; dd<=amp0;
              elsif count3=c then count3:=1;dd<="00000000";
              else count3:=count3+1; dd<="00000000";
              end if;
            end if;
          end if;  
        end if;
        if count1=12499999 then count1:=0;                       --調方波A的占空比
          if zu='1' then
            if z<63 then z<=z+1;
            else z<=63;
            end if;
          elsif zd='1' then
            if z>0 then z<=z-1;
            else z<=0;
            end if;
          end if;
        else count1:=count1+1;
        end if;
        if count0=3249999 then count0:=0;
--up、down對4種波形幅度調節,u0、d0進一步對方波進行幅度調節
          if u0='1' then
            if amp0<"11111111" then amp0<=amp0+1;
            else amp0<="11111111";
            end if;
          elsif d0='1' then
            if amp0>"00000000" then amp0<=amp0-1;
   else amp0<="00000000";
            end if;
          elsif up='1' then
            if amp<"11111111" then amp<=amp+1;
            else amp<="11111111";
            end if;
          elsif down='1' then
            if amp>"00000000" then amp<=amp-1;
            else amp<="00000000";
            end if;
          end if;
        else count0:=count0+1;
        end if;
      end if;
end if;
end if;
end process;
a<=amp;                        --將幅值輸出。

cov_a:process(clk,amp,amp0)         
--主要實現各波形幅度值到BCD碼的轉化,由于方波和其他三種波形的幅度調節方式、精
--度不同,因此對幅度的處理方式分兩種:“sss="00010" or sw='1'”是判斷輸出波形是否為
--方波(A或B),bcd00,bcd10,bcd20,bcd30是本進程的輸出。
variable count : integer range 0 to 50004225;
variable counter : integer range 0 to 500055;
variable count1,count0 : integer range 0 to 4999999;
begin
if rising_edge(clk) then
    if sss="00010" or sw='1' then count0:=0;                                   --方波
      if count1=4999999 then count1:=0; bcd0<=0; bcd1<=0; bcd2<=0; bcd3<=0;
count:=(conv_integer(amp))*(conv_integer(amp0))*769; --幅值運算
      elsif count1=4999900 then count1:=count1+1;
bcd00<=bcd0; bcd10<=bcd1; bcd20<=bcd2; bcd30<=bcd3;  --數據輸出
      else count1:=count1+1;                         --二進制碼到BCD碼的數據轉換
        if count>9999999 then count:=count-10000000; bcd0<=bcd0+1;
        elsif count>999999 then count:=count-1000000; bcd1<=bcd1+1;
        elsif count>99999 then count:=count-100000; bcd2<=bcd2+1;
        elsif count>9999 then count:=count-10000; bcd3<=bcd3+1;
        else null;
        end if;
      end if;
    else count1:=0;                                        --正弦波、三角波、鋸齒波
      if count0=4999999 then counter:=conv_integer(amp)*1961;
count0:=0; bcd01<=0; bcd11<=0; bcd21<=0; bcd31<=0;
      elsif count0=4999000 then bcd00<=bcd01; bcd10<=bcd11; bcd20<=bcd21;
bcd30<=bcd31; count0:=count0+1;
      else count0:=count0+1;
        if counter>99999 then counter:=counter-100000; bcd01<=bcd01+1;
        elsif counter>9999 then counter:=counter-10000; bcd11<=bcd11+1;
        elsif counter>999 then counter:=counter-1000; bcd21<=bcd21+1;
        elsif counter>99 then counter:=counter-100; bcd31<=bcd31+1;
        else null;
        end if;
      end if;
    end if;
  end if;
end process;

process(clk)                             --輸出波形幅度(峰-峰值)數據譯碼動態顯示
variable count : integer range 0 to 499999;
begin
if rising_edge(clk) then
    if count<=124999 then y<=bcd00; count:=count+1; shift<="0111"; lcd(0)<='0';
    elsif count<=249999 then y<=bcd10; count:=count+1; shift<="1011";lcd(0)<='1';
    elsif count<=374999 then y<=bcd20; count:=count+1; shift<="1101";lcd(0)<='1';
    elsif count<499999 then y<=bcd30; count:=count+1; shift<="1110";lcd(0)<='1';
    elsif count=499999 then y<=bcd30; count:=0; shift<="1110";lcd(0)<='1';
    end if;
end if;
case y is                               --7段碼譯碼
    when 0 => lcd(7 downto 1)<="0000001";
    when 1 => lcd(7 downto 1)<="1001111";
    when 2 => lcd(7 downto 1)<="0010010";
    when 3 => lcd(7 downto 1)<="0000110";
    when 4 => lcd(7 downto 1)<="1001100";
    when 5 => lcd(7 downto 1)<="0100100";
    when 6 => lcd(7 downto 1)<="0100000";
    when 7 => lcd(7 downto 1)<="0001111";
    when 8 => lcd(7 downto 1)<="0000000";
    when 9 => lcd(7 downto 1)<="0000100";
when others => lcd(7 downto 1)<="0000001";
end case;
end process;

ym:process(clk)                  --正弦波在一個周期內時域上的64個采樣點的波形數據
begin
if rising_edge(clk) then
case f is
when "00000000"=> d<="11111111"  ; when "00000001"=> d<="11111110"  ;
when "00000010"=> d<="11111100"  ;when "00000011"=> d<="11111001"  ;
when "00000100"=> d<="11110101"  ; when "00000101"=> d<="11101111"  ;
when "00000110"=> d<="11101001"  ;when "00000111"=> d<="11100001"  ;
when "00001000"=> d<="11011001"  ; when "00001001"=> d<="11001111"  ;
when "00001010"=> d<="11000101"  ;when "00001011"=> d<="10111010"  ;
when "00001100"=> d<="10101110"  ; when "00001101"=> d<="10100010"  ;
when "00001110"=> d<="10010110"  ;when "00001111"=> d<="10001001"  ;
when "00010000"=> d<="01111100"  ; when "00010001"=> d<="01110000"  ;
when "00010010"=> d<="01100011"  ;when "00010011"=> d<="01010111"  ;
when "00010100"=> d<="01001011"  ; when "00010101"=> d<="01000000"  ;
when "00010110"=> d<="00110101"  ;when "00010111"=> d<="00101011"  ;
when "00011000"=> d<="00100010"  ; when "00011001"=> d<="00011010"  ;
when "00011010"=> d<="00010011"  ;when "00011011"=> d<="00001101"  ;
when "00011100"=> d<="00001000"  ; when "00011101"=> d<="00000100"  ;
when "00011110"=> d<="00000001"  ;when "00011111"=> d<="00000000"  ;
when "00100000"=> d<="00000000"  ; when "00100001"=> d<="00000001"  ;
when "00100010"=> d<="00000100"  ;when "00100011"=> d<="00001000"  ;
when "00100100"=> d<="00001101"  ; when "00100101"=> d<="00010011"  ;
when "00100110"=> d<="00011010"  ;when "00100111"=> d<="00100010"  ;
when "00101000"=> d<="00101011"  ; when "00101001"=> d<="00110101"  ;
when "00101010"=> d<="01000000"  ;when "00101011"=> d<="01001011"  ;
when "00101100"=> d<="01010111"  ; when "00101101"=> d<="01100011"  ;
when "00101110"=> d<="01110000"  ;when "00101111"=> d<="01111100"  ;
when "00110000"=> d<="10001001"  ; when "00110001"=> d<="10010110"  ;
when "00110010"=> d<="10100010"  ;when "00110011"=> d<="10101110"  ;
when "00110100"=> d<="10111010"  ; when "00110101"=> d<="11000101"  ;
when "00110110"=> d<="11001111"  ;when "00110111"=> d<="11011001"  ;
when "00111000"=> d<="11100001"  ; when "00111001"=> d<="11101001"  ;
when "00111010"=> d<="11101111"  ;when "00111011"=> d<="11110101"  ;
when "00111100"=> d<="11111001"  ; when "00111101"=> d<="11111100"  ;
when "00111110"=> d<="11111110"  ;when "00111111"=> d<="11111111"  ;
when others=> null;
end case;
end if;
end process;
p180<='1';
end behav;

8.23 波形發生程序.doc

60.5 KB, 下載次數: 13, 下載積分: 黑幣 -5

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美1级| 国产视频久久 | 99国产精品99久久久久久粉嫩 | 亚洲人成人一区二区在线观看 | 成人在线电影在线观看 | 欧美日韩视频在线 | 国产精品美女久久久久aⅴ国产馆 | 欧美一区二区三区免费电影 | 中文字幕国 | 一区影院 | 91成人免费电影 | 国产精品视频偷伦精品视频 | 在线观看成人小视频 | 日韩视频在线免费观看 | 99久久久久久99国产精品免 | 久久99精品久久久久久国产越南 | 无码日韩精品一区二区免费 | 浮生影院免费观看中文版 | 久久久中文 | 免费观看成人性生生活片 | 中国一级特黄真人毛片 | 黄色网址免费看 | 伊人欧美视频 | 国产色黄 | 最新国产精品视频 | 成人免费看片网 | 成人在线一区二区 | 亚洲国产成人精品在线 | 99精品视频在线观看 | 日本在线一区二区三区 | 神马久久久久久久久久 | 久久亚洲一区二区 | 99视频久| 成人av一区 | 国产在线色 | 亚洲精品天堂 | 国产精品久久久久国产a级 欧美日本韩国一区二区 | 久久久久久久久久性 | 4hu最新网址 | 中文字幕亚洲视频 | 国产精品久久久久久久久久 |