UOMOP

Down Conversion 본문

Wireless Comm./VHDL

Down Conversion

Happy PinGu 2022. 6. 30. 01:15

RTL code

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_signed.all;

entity downconv is
port(
	clk, nrst : in std_logic;
	pass_r, pass_i : in std_logic_vector(9 downto 0);
	
	base_r, base_i : out std_logic_vector(9 downto 0));
end entity;

architecture arch of downconv is

signal p_r, p_i, n_r, n_i : std_logic_vector(9 downto 0);
signal basing_r, basing_i     : std_logic_vector(9 downto 0);
signal state : std_logic_vector(1 downto 0);

begin

p_r <= pass_r;
p_i <= pass_i;
n_r <= not(pass_r) + "0000000001";
n_i <= not(pass_i) + "0000000001";


process(nrst,clk)
begin
if nrst = '0' then
	state <= "11";
elsif clk = '1' and clk'event then
	state <= state + "01";
end if;
end process;


process(nrst, clk)
begin
if nrst = '0' then
	basing_r <= "0000000000";
	basing_i <= "0000000000";
elsif clk = '1' and clk'event then
	if state = "00" then
		basing_r <= p_r;
		basing_i <= p_i;
	elsif state = "01" then
		basing_r <= p_i;
		basing_i <= n_r;
	elsif state = "10" then
		basing_r <= n_r;
		basing_i <= n_i;
	else
		basing_r <= n_i;
		basing_i <= p_r;
	end if;

end if;
end process;

base_r <= basing_r;
base_i <= basing_i;

end arch;

TestBench code

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;

entity tb_downconv is
end entity;

architecture behavior of tb_downconv is

component downconv is
port(
	clk, nrst : in std_logic;
	pass_r, pass_i : in std_logic_vector(9 downto 0);
	
	base_r, base_i : out std_logic_vector(9 downto 0));
end component;

signal nrst, clk : std_logic;
signal rin, iin : std_logic_vector(9 downto 0);
signal rout, iout : std_logic_vector(9 downto 0);

begin

idownconv : downconv port map(
	nrst => nrst,
	clk => clk,
	pass_r => rin,
	pass_i => iin,

	base_r => rout,
	base_i => iout);

clkp : process
begin
	clk <= '1';
	wait for 20 ns;
	clk <= '0';
	wait for 20 ns;
end process;

nrstp : process
begin
	nrst <= '0';
	wait for 100 ns;
	nrst <= '1';
	wait;
end process;

process(nrst, clk)
begin
if nrst = '0' then
	rin <= (others => '0');
	iin <= (others => '0');
elsif clk = '1' and clk'event then
	rin <= rin + '1';
	iin <= iin - '1';
end if;
end process;

end behavior;

Wave Capture

 

 

 

 

 

 

Comments