Guest
#6988594
Hello I would love your help
I designed a simple binary counter,
though if I do not put the single Q in the sensitivity list. The counter
updates falling_edge Why is that?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity Binary_Counter is
--generic( n : positive:=24);
Port (
Clk : in STD_LOGIC;
-- the LTF(n) signal
Up_Down : in STD_LOGIC;
-- Up_Down ='1' the counter counts up
-- Up_Down ='0' the counter counts down
T_Gate : in STD_LOGIC;
-- Enable count
O : in integer range 0 to 10:=2;
-- The number of times the counter works
ResetS : in STD_LOGIC;
-- Asynchronously reset
Pe : in STD_LOGIC;
-- Asynchronously loads data on the Preset Inputs.
Pi : in STD_LOGIC_VECTOR(23 downto 0);
--Data on these inputs is loaded into the counter when PE is
taken high.
Q_Out : out STD_LOGIC_VECTOR(23 downto 0);
-- Binary data is present outputs
Carry_Out : out STD_LOGIC);
--used to indicate terminal count.
end Binary_Counter;
architecture Behavioral of Binary_Counter is
signal Q : STD_LOGIC_VECTOR(23 downto 0):=(others=>'0');
begin
process(Clk,ResetS,Pe,T_Gate,Up_Down)
variable CountQ : integer range 0 to 10:=O;
begin
if( ResetS = '1') then Q<=(others=>'0');
elsif(CountQ /=0 and T_Gate='1') then
if(rising_edge(clk)) then
if( pe='1' ) then Q<= pi;
elsif(Up_Down='1') then
if(Q=x"111111") then
Carry_Out<='1';
Q<=x"000000";
else
Q<=Q+1;
end if;
else
if(Q=x"000000") then
Carry_Out<='1';
Q<=x"111111";
else
Q<=Q-1;
end if;
end if;
end if;
end if;
Q_Out<=Q;
end process;
end Behavioral;
