作者luckyBF (你若有钱~刘+0~嘛系你ㄟ)
站内Electronics
标题Re: [问题] VHDL之计数器问题
时间Mon May 14 23:04:12 2007
之前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
1F:→ luckyBF:一个数奇~一个数偶~~用clk去选输出~~ 05/15 00:30
2F:→ luckyBF:不过感觉在时序模拟时会有问题~ 05/15 01:23