【文章內(nèi)容簡介】
ponent vgasmode Define vag mode implement port (clk25m,clk1hz: in std_logic。 sw: in std_logic_vector(1 downto 0)。 hen,ven: in std_logic。 colors0,colors1,colors2,colors3: in std_logic_vector(5 downto 0)。 colors: out std_logic_vector(5 downto 0))。 end ponent。 ponent vgasig Define vag signal interface as a module port (clk25m: in std_logic。 ht,vt: in std_logic_vector(9 downto 0)。 hsync,vsync,henable,venable : out std_logic)。 end ponent。 ponent vgacolor Generate colors for each mode 數(shù)字電路綜合 實驗報告 第 16頁 port (clk25m,clk100hz,clk1hz: in std_logic。 hpos,vpos: in std_logic_vector(9 downto 0)。 button: in std_logic_vector(4 downto 0)。 sw : in std_logic_vector(5 downto 0)。 colors0,colors1,colors2,colors3: out std_logic_vector(5 downto 0))。 end ponent。 ponent usermode Sub mode for user port (clk25m,clk100hz,clk1hz: in std_logic。 hpos,vpos: in std_logic_vector(9 downto 0)。 button : in std_logic_vector(4 downto 0)。 usercolors: out std_logic_vector(5 downto 0))。 end ponent。 end vgapackage。 然后在 VGAController 中進行例化, VHDL描述如下(僅給出關(guān)鍵部分的描述)。 begin sw = (sw7,sw6,sw5,sw4,sw3,sw2,sw1,sw0)。 bt = (bt4,bt3,bt2,bt1,bt0)。 (r0,r1,g0,g1,b0,b1) = colors。 clock_port_map: clock port map(clk50m = clk50m, clk25m = clk25m, clk100hz = clk100hz, clk1hz = clk1hz)。 pixelt_port_map: pixelt port map(clk25m = clk25m, htout = ht, vtout = vt)。 vgasig_port_map: vgasig port map(clk25m = clk25m, ht = ht, 數(shù)字電路綜合 實驗報告 第 17頁 vt = vt,hsync = hs, vsync = vs, henable = hen, venable = ven)。 vgaemode_port_map: vgasmode port map(clk25m = clk25m, clk1hz = clk1hz, hen = hen ,ven = ven, colors0 = colors0,colors1 = colors1, colors2 = colors2,colors3 = colors3, colors = colors,sw = sw(1 downto 0))。 vgacolor_port_map: vgacolor port map(clk25m = clk25m, clk100hz = clk100hz, clk1hz = clk1hz, hpos = ht, vpos = vt, sw = sw(7 downto 2),button = bt, colors0 = colors0,colors1 = colors1, colors2 = colors2,colors3 = colors3)。 end arch。 圖 是 QuartusII 生成的總體電路圖 ,定義的第二層 5 個模塊均對應(yīng)生成了器件,由于 UserMode 模塊是在 VGAColor 模塊里進行的例化,故系統(tǒng)綜合時將其歸并在了 VGAColor 模塊內(nèi)。 QuartusII 生成的 電路圖 和 節(jié)中模塊設(shè)計圖一致,信號連接圖與 。設(shè)計是正確的。 數(shù)字電路綜合 實驗報告 第 18頁 圖 QuartusII 生成的總體電路圖 分塊電路的描述 本節(jié)給出分塊電路的硬件描述,對關(guān)鍵部分進行了分析。由于代碼長度較長,只給出部分代碼,完整的代碼請參見 。各模塊的 RTL圖參考 。 VGAMode 模塊的描述 定義狀態(tài)機的描述如下。 type states is (s0,s1,s2,s3)。 signal state:states:=s0。 該模塊主要描述狀態(tài)機的轉(zhuǎn)移,轉(zhuǎn)移條件是 SW1和 SW2的組合值,描述如下。 process(clk1hz) Detecting sw1 and sw0 and decide the state begin if(rising_edge(clk1hz)) then case sw is when 00 = state = s0。 when 01 = state = s1。 when 10 = state = s2。 when 11 = state = s3。 end case。 end if。 end process。 VGAMode 模塊負(fù)責(zé)根據(jù)當(dāng)前狀態(tài)選擇輸出 VGAColor 送入的不同模式下的顏色圖像信號,輸出到 VGA接口。 process(clk25m) Select color of one mode to VAG interface begin if(rising_edge(clk25m)) then case state is when s0 = colorstmp = colors0。 when s1 = colorstmp = colors1。 when s2 = colorstmp = colors2。 when s3 = colorstmp = colors3。 end case。 數(shù)字電路綜合 實驗報告 第 19頁 end if。 end process。 VGASig模塊的描述 該模塊 主要 負(fù)責(zé) VGA 標(biāo)準(zhǔn)中的行同步信號和列同步信號以及行列消隱信號。其輸入信號來自于 PixelCNT模塊的像素位置信號 ht和 vt。 VGA掃描顯示的原理關(guān)鍵點在于同步信號和消隱信號的產(chǎn)生。 由 VGA 標(biāo)準(zhǔn)中定義的時序關(guān)系,可以等效地計算出像素點的時序關(guān)系圖。其中,行同步時序列表如下: 表 21 VGA行同步時序表 根據(jù)時序表,容易確定水平掃描的四個狀態(tài)區(qū),即:行顯示區(qū)( h_video)、行前端消隱區(qū)( h_front)、行同步區(qū)( h_sync)、行后端消隱區(qū)( h_back)。如圖 。 數(shù)字電路綜合 實驗報告 第 20頁 圖 VGA行掃描狀態(tài)轉(zhuǎn)移圖 行同步信號產(chǎn)生描述如下。行同步區(qū)定義在 656~ 752像素之間。 process(clk25m) hsync begin if (rising_edge(clk25m)) then if (ht = (640+8+8) and ht (640+8+8+96)) then hsync = 39。039。 else hsync = 39。139。 end if。 end if。 end process。 類似行同步,列同步時序表如下: 表 22 VGA行 列 同步時序表 數(shù)字電路綜合 實驗報告 第 21頁 圖 VGA列掃描狀 態(tài)轉(zhuǎn)移圖 列同步信號產(chǎn)生描述如下。列同步區(qū)在 490~ 492像素點之間。 process(vt) vsync begin if (vt = (480+8+2) and vt (480+8+2+2)) then vsync = 39。039。 else vsync = 39。139。 end if。 end process。 值得說明的是,由于時鐘誤差在所難免, VGA 標(biāo)準(zhǔn)實現(xiàn)時像素的計數(shù)要求并非一個像素點都不能差,微小誤差是可以接受的。 最后是消隱信號的產(chǎn)生。當(dāng)顯示像素不在定義的 640 480 范圍內(nèi)時,不輸出顏色信號,稱其為消隱區(qū)。消隱去描述如下。 process(clk25m) no color when not in 640*480 begin if(rising_edge(clk25m)) then if((ht 640) or (vt 480)) then henable = 39。039。 venable = 39。039。 else henable = 39。139。 venable = 39。139。 end if。 end if。 end process。 VGAColor模塊的描述 該模塊 產(chǎn)生四種顯示模式 S0、 S S S3 的顏色圖像信號,其中用戶模式 S3 是調(diào)用 UserMode 模塊實現(xiàn)的。 數(shù)字電路綜合 實驗報告 第 22頁 橫向和縱向彩條顯示,只需分別判斷縱向和橫向像素位置即可。此處劃分采用了均分方式,只要增加劃分次數(shù)就可得到更多條幅,此處只按要求給出 8種顏色。 下面給出橫向條幅的的描述,縱向條幅描述類似。 process(clk25m) state s0 process: horizontal colors begin if(rising_edge(clk25m)) then if hpos 640 and vpos 60 then colors0 = 100100。 elsif hpos 640 and vpos 120 then colors0 = 000001。 elsif hpos 640 and vpos 180 the