8bit UpCounter With Different Data Types
8bit UpCounter With Different Data Types
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity cnt8_std is
port( data: in std_logic_vector(7 downto 0);
greset,load,enable,clk: in std_logic;
cnt: out std_logic_vector(7 downto 0));
end cnt8_std;
begin
process(greset,clk)
variable count: std_logic_vector(7 downto 0);
begin
if greset='1' then
count:="00000000";
elsif clk'event and clk='1' then
if load='1' then
count:=data;
elsif enable='1' then
count:=count+1;
end if;
end if;
cnt<=count;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity cnt8_unsigned is
port( data: in unsigned(7 downto 0);
greset,load,enable,clk: in std_logic;
cnt: out std_logic_vector(7 downto 0));
end cnt8_unsigned;
begin
process(greset,clk)
variable count:unsigned(7 downto 0);
begin
if greset='1' then
count:="00000000";
elsif clk'event and clk='1' then
if load='1' then
count:=data;
elsif enable='1' then
count:=count+1;
end if;
end if;
cnt<=conv_std_logic_vector(count,8);
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity cnt8_signed is
port( data:in signed(7 downto 0);
greset,load,enable,clk:in std_logic;
cnt:out std_logic_vector(7 downto 0));
end cnt8_signed;
begin
process(greset,clk)
variable count:signed(7 downto 0);
begin
if greset='1' then
count:="00000000";
elsif clk'event and clk='1' then
if load='1' then
count:=data;
elsif enable='1' then
count:=count+1;
end if;
end if;
cnt<=conv_std_logic_vector(count,8);
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity cnt8_integer is
port( data:in std_logic_vector(7 downto 0);
greset,load,enable,clk:in std_logic;
cnt:out std_logic_vector(7 downto 0));
end cnt8_integer;