Hello , this is a code for a counter which counts sequence 8,4,2,1,0(in binary1000,0100,0010,0001,0000) and the cycle repeats . if you give reset as ‘1’ then the sequence resets. You can try ring counter by using same logic. If any difficulty or any problem in execution you can mail me @ hariprasadmdg@gmail.com :)
Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity seq842 is
port(rst,clk:in std_logic;
y:out std_logic_vector(3 downto 0));
end seq842;
architecture arch of seq842 is
begin
process(rst,clk)
variable temp:std_logic_vector(3 downto 0):="1000";
begin
if(rst='1')then
temp:="1000";
elsif(rising_edge(clk))then
if(temp="0000")then
temp:="1000";
else
temp:='0'&temp(3 downto 1);
end if;
end if;
y<=temp;
end process;
end arch;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity seq842 is
port(rst,clk:in std_logic;
y:out std_logic_vector(3 downto 0));
end seq842;
architecture arch of seq842 is
begin
process(rst,clk)
variable temp:std_logic_vector(3 downto 0):="1000";
begin
if(rst='1')then
temp:="1000";
elsif(rising_edge(clk))then
if(temp="0000")then
temp:="1000";
else
temp:='0'&temp(3 downto 1);
end if;
end if;
y<=temp;
end process;
end arch;
output:
Comments
Post a Comment