分频部分
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity fenpin is
port(clk:in std_logic;
clk1hz:out std_logic;
clk10khz: out std_logic
);
end fenpin;
architecture behavior of fenpin is
signal count:std_logic_vector(24 downto 0);
signal count1:std_logic_vector(24 downto 0);
signal clk_temp:std_logic;
signal clk_temp1:std_logic;
begin
process(clk)
begin
if(clk'event and clk='1')then
if count=(25E2) then --25x10^2 10KHZ 周期 秒=1/hz
count<=(others=>'0');
clk_temp<=not clk_temp;
else
count<=count+1;
end if;
end if;
end process;
process(clk)
begin
if(clk'event and clk='1')then
if count1=(25E4) then --25x10^4 100HZ
count1<=(others=>'0');
clk_tem p1<=not clk_temp1;
else
count1<=count1+1;
end if;
end if;
end process;
clk1hz<=clk_temp;
clk10khz<=clk_temp1;
end behavior;
乘法器部分
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cfq is
port(a,b:in std_logic_vector(2 downto 0);
y:out std_logic_vector(5 downto 0);
c,d:out std_logic_vector(2 downto 0);
e,f:out std_logic_vector(2 downto 0)
);
end cfq;
architecture behavior of cfq is
begin
process(a,b)
variable sum,temp_a:std_logic_vector(5 downto 0); --移位相加
begin
sum:=(others=>'0');
for i in 0 to 2 loop
temp_a:=(others=>'0');
temp_a(i+2 downto i):=a;
if b(i)='1' then
sum:=sum + temp_a;
end if;
e