|
|||||||||||
| 技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測(cè)控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動(dòng)編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機(jī) | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計(jì) | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
請(qǐng)教256個(gè)數(shù)求平均值的問(wèn)題 |
| 作者:madke 欄目:EDA技術(shù) |
編了一個(gè)256個(gè)數(shù)求均值的程序,仿真不對(duì)! 幫忙看看,錯(cuò)在哪里?謝謝! use ieee.std_logic_unsigned.all; entity average is PORT( clr,clk:in std_logic; a:in std_logic_vector(7 downto 0); s:out std_logic_vector(7 downto 0)); end average; architecture bhv of average is signal s256:std_logic_vector(15 downto 0); signal seg256:std_logic_vector(7 downto 0); begin PROCESS(clk,clr) begin if clr='1' then s256<=(others=>'0');seg256<=(others=>'0'); elsif clk'EVENT and clk='1' then s256<=s256+a; if seg256<255 then seg256<=seg256+1; else seg256<=(others=>'0'); end if; end if; end PROCESS; PROCESS(seg256) begin if seg256=255 then for i in 0 to 7 loop s(i)<=s256(i+8); end loop; end if; end PROCESS; end bhv; |
| 2樓: | >>參與討論 |
| 作者: picklas 于 2005/3/15 0:19:00 發(fā)布:
re 感覺(jué)是 PROCESS(seg256) begin if seg256=255 then for i in 0 to 7 loop s(i)<=s256(i+8); end loop; end if; end PROCESS; 的問(wèn)題,建議你用仿真器把所有的信號(hào)都加上去看看。 如果可以換成下面的進(jìn)程是一下: PROCESS(clk) if rising_edge(clk) then if seg256=255 then s <= s256(15 downto 8); end if; end if; end PROCESS; 試試吧。 |
|
| 3樓: | >>參與討論 |
| 作者: madke 于 2005/3/16 12:38:00 發(fā)布:
thanks 謝謝指教!修改后程序如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity average is PORT( clr,clk:in std_logic; a:in std_logic_vector(7 downto 0); so:out std_logic; s:out std_logic_vector(7 downto 0)); end average; architecture bhv of average is signal s256:std_logic_vector(15 downto 0); signal seg256:std_logic_vector(8 downto 0); signal soseg:std_logic; begin PROCESS(clk,clr) begin if clr='1' then seg256<=(others=>'0');seg256<=(others=>'0'); elsif clk'EVENT and clk='1' then if seg256<"11111111" then seg256<=seg256+1; else seg256<="100000000"; end if; end if; end PROCESS; PROCESS(clk,clr) begin if clr='1' then s256<=(others=>'0'); elsif clk'EVENT and clk='1' then if seg256<"100000000" then s256<=s256+a; end if; end if; end PROCESS; PROCESS(clr,seg256) begin if clr='1' then soseg<='0'; elsif seg256="100000000" then soseg<='1'; else soseg<='0'; end if; end PROCESS; PROCESS(clr,soseg) begin if clr='1' then s<=(others=>'0'); elsif soseg='1' then for i in 0 to 7 loop s(i)<=s256(i+8); end loop; end if; end PROCESS; so<=soseg; end bhv; |
|
|
|
| 免費(fèi)注冊(cè)為維庫(kù)電子開(kāi)發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號(hào) |