關於VHDL用點距陣做跑馬燈… |
缺席
|
a0132022002
一般會員 發表:1 回覆:1 積分:0 註冊:2005-11-04 發送簡訊給我 |
我們的作業是這樣的:
顯示數字為0~3
開關為00時→數字要向左捲動
開關為01時→數字要向右捲動
開關為10時→數字要向上捲動
開關為11時→數字要向下捲動 當我寫完左右移時,把上下加進去compiler完竟然跟我說邏輯元件不夠了啊,
我們用的實驗平台是LP-2900,只有576個元件,我再怎麼弄還是用到900多個邏輯閘。
我是用位移的方式去做的,這是我的一小段程式碼:
if(sw="01")then
col1(1 to 31)<=col1(0 to 30);
col1(0)<=col1(31);
col2(1 to 31)<=col2(0 to 30);
col2(0)<=col2(31);
col4(1 to 31)<=col4(0 to 30);
col4(0)<=col4(31);
col5(1 to 31)<=col5(0 to 30);
col5(0)<=col5(31);
elsif(sw="00")then
col1(0 to 30)<=col1(1 to 31);
col1(31)<=col1(0);
col2(0 to 30)<=col2(1 to 31);
col2(31)<=col2(0);
col4(0 to 30)<=col4(1 to 31);
col4(31)<=col4(0);
col5(0 to 30)<=col5(1 to 31);
col5(31)<=col5(0);
end if; 這是左右的,上下的我也用同樣的方法寫,可是邏輯閘就是不夠用,本來是想說用位移的指令(ROR ROL…等),可是MAX PLUS 2不支援這個指令啊,我朋友有寫出來,可是他已經連續狂操5天5夜,寫了300多行,才能執行,我完全看不懂他的程式碼,我非常確認我的程式沒有錯,可是邏輯閘就是不夠用,雖然我只有100多行。有沒有大大知道有沒有更好的節省邏輯閘的方法啊…,我也已經三天三夜都在搞這個,搞到嘴巴都破了兩個大洞了…。我是希望程式的可讀性高,又能加入數字,例如我可以更改成0~5之類的,有沒有大大能夠指導一下的,小弟先在此感謝了…。
|
ssejack
高階會員 發表:87 回覆:143 積分:106 註冊:2005-06-27 發送簡訊給我 |
|
vicious_devil
一般會員 發表:0 回覆:1 積分:0 註冊:2005-11-04 發送簡訊給我 |
Hi :
引言:col1(1 to 31)<=col1(0 to 30); col1(0)<=col1(31); col2(1 to 31)<=col2(0 to 30); col2(0)<=col2(31); col4(1 to 31)<=col4(0 to 30); col4(0)<=col4(31); col5(1 to 31)<=col5(0 to 30); col5(0)<=col5(31);↑這裡應該可以改成 col1 <= col1(31) & col1(0 to 30); col2 <= col2(31) & col2(0 to 30); col3 <= col3(31) & col3(0 to 30); col4 <= col4(31) & col4(0 to 30); col5 <= col5(31) & col5(0 to 30); 這樣程式碼會短一點!! |
a0132022002
一般會員 發表:1 回覆:1 積分:0 註冊:2005-11-04 發送簡訊給我 |
我po上來完整的程式碼好了,大家幫幫忙吧。
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; entity ary2 is port( sw: in std_logic_vector(0 to 1); clk_in,reset:in std_logic; dsp_row: out std_logic_vector(0 to 7); dsp_col: out std_logic_vector(0 to 7) ); end ary2; architecture b of ary2 is component clk_n_div generic(div: integer:=500000); port(clk_in: in std_logic; clk_out: out std_logic ); end component; component clk_n_div2 generic(div: integer:=15000); port(clk_in: in std_logic; clk_out2: out std_logic ); end component; signal ck1,ck2: std_logic; signal col1,col2,col3,col4,col5,col6,col7,col8: std_logic_vector(0 to 31); signal row3,row4,row5,row6: std_logic_vector(0 to 47); signal cn2: integer:=0; signal cn1: integer:=0; begin ic1: clk_n_div port map(clk_in,ck1); ic2: clk_n_div2 port map(clk_in,ck2); process(ck1) begin IF(reset='1') then col1<="00111100000100001111000000111100"; col2<="00100100000100000001000000000100"; col3<="00100100000100000001000000000100"; col4<="00100100000100001111000000111100"; col5<="00100100000100001000000000000100"; col6<="00100100000100001000000000000100"; col7<="00100100000100001000000000000100"; col8<="00111100000100001111000000111100"; row6<="111111110000000000000000111100010000111111110000"; row5<="100000010000111111110000100100010000100010010000"; row4<="100000010000000000000000100111110000100010010000"; row3<="111111110000000000000000000000000000100010010000"; elsif(ck1'EVENT and ck1='1') then if(sw="01")then col1 <= col1(31) & col1(0 to 30); col2 <= col2(31) & col2(0 to 30); col4 <= col4(31) & col4(0 to 30); col5 <= col5(31) & col5(0 to 30); elsif(sw="00")then col1 <= col1(1 to 31) & col1(0); col2 <= col2(1 to 31) & col2(0); col4 <= col4(1 to 31) & col4(0); col5 <= col5(1 to 31) & col5(0); elsif(sw="10")then row6 <= row6(47) & row6(0 to 46); row5 <= row5(47) & row5(0 to 46); row4 <= row4(47) & row4(0 to 46); row3 <= row3(47) & row3(0 to 46); end if; end if; end process; process(ck2) begin if(ck2'event and ck2='1')then if(sw="00" or sw="01")then if(cn2=0)then dsp_row<="10000000"; dsp_col<=col1(0 to 7); cn2<=cn2 1; elsif(cn2=1)then dsp_row<="01000000"; dsp_col<=col2(0 to 7); cn2<=cn2 1; elsif(cn2=2)then dsp_row<="00100000"; dsp_col<=col2(0 to 7); cn2<=cn2 1; elsif(cn2=3)then dsp_row<="00010000"; dsp_col<=col4(0 to 7); cn2<=cn2 1; elsif(cn2=4)then dsp_row<="00001000"; dsp_col<=col5(0 to 7); cn2<=cn2 1; elsif(cn2=5)then dsp_row<="00000100"; dsp_col<=col5(0 to 7); cn2<=cn2 1; elsif(cn2=6)then dsp_row<="00000010"; dsp_col<=col5(0 to 7); cn2<=cn2 1; elsif(cn2=7)then dsp_row<="00000001"; dsp_col<=col1(0 to 7); cn2<=0; end if; elsif(sw="10")then if(cn1=0)then dsp_col<="00100000"; dsp_row<=row3(0 to 7); cn1<=cn1 1; elsif(cn1=1)then dsp_col<="00010000"; dsp_row<=row4(0 to 7); cn1<=cn1 1; elsif(cn1=2)then dsp_col<="00001000"; dsp_row<=row5(0 to 7); cn1<=cn1 1; elsif(cn1=3)then dsp_col<="00000100"; dsp_row<=row6(0 to 7); cn1<=0; end if; end if; end if; end process; END b;這個沒有向下捲動的部分,因為我本來左右是可以的,後來才加進一個上捲就跟我說邏輯閘過多了,他只有576個而我用了760個,我只能縮短到這個樣子了…各位幫幫我吧…3Q 發表人 - ㊣ 於 2005/11/07 16:12:27 |
ssejack
高階會員 發表:87 回覆:143 積分:106 註冊:2005-06-27 發送簡訊給我 |
|
阿信
版主 發表:111 回覆:983 積分:813 註冊:2005-03-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |