VHDL Pgms
VHDL Pgms
begin
process(clk,reset) -- Process definition
variable qtemp: std_logic_vector(3 downto 0); -- temporary variable
for output q[3..0]
begin
if reset='1' then
qtemp:="0000"; -- Reset asychroniously
else
if clk'event and clk='1' then -- Counting state
if qtemp<9 then
qtemp:=qtemp+1; -- Counter increase
else
qtemp:="0000"; -- Return the zero state
end if;
end if;
q<=qtemp; -- Output
end if;
end process; -- End Process
end Counter; -- End Architecture
VHDL Code
library ieee;
use ieee.std_logic_1164.all;
entity shift is
port(C, SI : in std_logic;
SO : out std_logic);
end shift;
architecture archi of shift is
signal tmp: std_logic_vector(7 downto 0);
begin
process (C)
begin
if (C'event and C='1') then
for i in 0 to 6 loop
tmp(i+1) = tmp(i);
end loop;
tmp(0) = SI;
end if;
end process;
SO = tmp(7);
end archi;
Verilog Code:
module shift (C, SI, SO);
input C,SI;
output SO;
reg [7:0] tmp;
always @(posedge C)
begin
tmp = tmp 1;
tmp[0] = SI;
end
assign SO = tmp[7];
endmodule