求用VHDL语言实现 十进制同步减法计数器(异步清零、同步预置、下降沿触发、带借位输出BO端)

如题 用VHDL语言实现 十进制同步减法计数器(异步清零、同步预置、下降沿触发、带借位输出BO端)

VHDL语言实现 十进制同步减法计数器(异步清零、同步预置、下降沿触发、带借位输出BO端)。原程序如下,改程序已经通过仿真,仿真结果见图,输入D的值设为3,同步置位后,输出Q=D=3,功能实现。

LIBRARY ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

--*------------------实体描述--------------------------*--

ENTITY sub_counter IS                                       

   PORT(clk    : in std_logic;  --输入时钟信号;        

        clr    : in std_logic;  --异步清零,低电平有效;

        preset : in std_logic;  --同步置位,低电平有效;

        D  : in std_logic_vector(3 downto 0); --4位的输入;    

        Q  : out std_logic_vector(3 downto 0); --4位输出;                          

        BO : out std_logic);   --借位输出;                  

End sub_counter;                                           

--*-------------------END-----------------------------*--

--*---------------结构体描述---------------------------*--

ARCHITECTURE arch OF sub_counter IS

   signal i_cnt : std_logic_vector(3 downto 0); --用于暂时存储输出的信号

begin

   P1 : process(clk,clr)

begin

  if clr='0' then --因为是减法计数器,所以,清零后输出=1001;

i_cnt <= "1001";

BO <= '0';

        elsif clk'event and clk='0' then

if preset='0' then

      i_cnt <= D;

elsif preset='1' then

      i_cnt <= i_cnt-1;  --减法计数;

   if i_cnt="0000" then

                              BO<= '1';

                              i_cut <= "1001";

     else

                              BO<= '0';

    end if;

              end if;

  end if;

   end process P1;

--进程P2将输出信号赋予真正的输出;如果输出不单列一个进程,那么仿真会出现错

--误,因为计数阶段不能直接读取输出Q的值。

   P2 : process(i_cnt)               

   begin

      Q <= i_cnt;

   end process P2;

end arch;

--*-------------------------------------------------------*--

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-17
VHDL语言实现 十进制同步减法计数器(异步清零、同步预置、下降沿触发、带借位输出BO端)。原程序如下,改程序已经通过仿真,仿真结果见图,输入D的值设为3,同步置位后,输出Q=D=3,功能实现。
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--*------------------实体描述--------------------------*--
ENTITY sub_counter IS
PORT(clk : in std_logic; --输入时钟信号;
clr : in std_logic; --异步清零,低电平有效;
preset : in std_logic; --同步置位,低电平有效;
D : in std_logic_vector(3 downto 0); --4位的输入;
Q : out std_logic_vector(3 downto 0); --4位输出;
BO : out std_logic); --借位输出;
End sub_counter;
--*-------------------END-----------------------------*--
--*---------------结构体描述---------------------------*--
ARCHITECTURE arch OF sub_counter IS
signal i_cnt : std_logic_vector(3 downto 0); --用于暂时存储输出的信号
begin
P1 : process(clk,clr)
begin
if clr='0' then --因为是减法计数器,所以,清零后输出=1001;
i_cnt <= "1001";
gd elsif clk'event and clk='0' then
if preset='0' then
i_cnt <= D;
elsif preset='1' then
i_cnt <= i_cnt-1; --减法计数;
if i_cnt="0000" then
BO<= '1';
i_cut <= "1001";
else
BO<= '0';
end if;
end if;
end if;
end process P1;

--进程P2将输出信号赋予真正的输出;如果输出不单列一个进程,那么仿真会出现错
--误,因为计数阶段不能直接读取输出Q的值。

P2 : process(i_cnt)
begin
Q <= i_cnt;
end process P2;
end arch;
第2个回答  2011-12-20
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity shijinzhi is
port(clk,rst,en,up:in std_logic;
sum:out std_logic_vector(3 downto 0);
cout:out std_logic);
end entity;
architecture b of shijinzhi is
signal count:std_logic_vector(3 downto 0);
begin
process(clk,rst,en) is
begin
if clk'event and clk='1' then
if rst='1' then 把if改成elsif就成异步清零了
count<="0000";
elsif en='1' then
case up is
when '1'=>count<=count+1;
if count>"1000" then count<="0000";
end if;
when others=>count<=count-1;
if count<"0001" then count<="1001";
end if;
end case;
end if;
end if;
end process;
sum<=count;
cout<='1' when en='1' and((up='1' and count=9) or (up
='0' and count=0)) else '0';
end;
这个是同步清零的十进制计数器,改成异步的就行了