Re: [問題] VHDL之計數器問題
之前try過~
剛剛跑過一次function模擬~應該沒問題
不過我寫的verilog的~~XD
n可以去改bit數~~
module test_DDR_counter (clk, reset, q_out);
parameter n = 4; //n-bit counter
input clk, reset;
output [n-1:0] q_out;
reg [n-1:0] q_odd;
reg [n-1:0] q_even;
always @ (posedge clk or posedge reset)
if (reset)
begin
q_odd [n-1:0] <= {{(n-2){1'b0}}, 1'b1};
q_even [n-1:0] <= {(n-1){1'b0}};
end
else
begin
q_odd [n-1:0] <= q_odd[n-1:0] + 2'b10;
q_even [n-1:0] <= q_even[n-1:0] + 2'b10;
end
assign q_out [n-1:0]= clk ? q_even [n-1:0] : q_odd [n-1:0];
endmodule
※ 引述《CuckooBoy (阿書)》之銘言:
: http://ilook.tw/7e6a
: 這是一個,上/下緣皆累加的計數器
: 但是發現有一個問題
: 如圖中, 框/圈起來的地方...
: 也就是cnt_r跟cnt_f都為3後歸0的那段會出問題
: 不知道如何解決呢?小弟一直想不出什麼辦法!
: 此模擬的程式如下,請大大指點...感謝~~
: ===========================================================
: library IEEE;
: use IEEE.STD_LOGIC_1164.ALL;
: use IEEE.STD_LOGIC_ARITH.ALL;
: use IEEE.STD_LOGIC_UNSIGNED.ALL;
: entity test is
: Port ( Clock : in std_logic;
: Led : out std_logic_vector(3 downto 0));
: end test;
: architecture Behavioral of test is
: signal cnt : std_logic_vector(3 downto 0);
: signal cnt_r:std_logic_vector(3 downto 0);
: signal cnt_f:std_logic_vector(3 downto 0);
: begin
: process(Clock)
: begin
: if rising_edge(Clock) then
: if cnt_r<3 then
: cnt_r<=cnt_r+'1';
: end if;
: end if;
: end process;
: process(Clock)
: begin
: if falling_edge(Clock) then
: if cnt_f<3 then
: cnt_f <= cnt_f + '1';
: end if;
: end if;
: end process;
: cnt <= cnt_r + cnt_f;
: Led<=cnt;
: end Behavioral;
--
╭─╮ ╭───╮───╮─╭─☆─╮─╮───╮───╮
│█│ │█ █│█◤█│█ █│█ █│█◤█│█◤█│
│█★─╮█ █│█ ─╯█◢◤╯█◤█│█◤◣╯█◢╭╯
│█◢█│█◢█│█◢█│█ █│╮◢╭╯█◢█│█╭★
╰───╯───╯───╯─╯─╯╰─╯╰───╯─╯ ζcapsid
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.193.146.81
→
05/15 00:30, , 1F
05/15 00:30, 1F
→
05/15 01:23, , 2F
05/15 01:23, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 4 篇):