Jump to content
    

Помогите сделать умножение на VHDL

Проблема в том что можно использовать только лог. операции и +, -. И только тип std_logic или std_logic_vector. Пробовал писать сам но что-то оно у меня вообще не работает. Выглядит моя писаниня примерно так:

 

entity F is

port(

RST: in std_logic;

CLK: in std_logic;

 

CX: in std_logic;

CY: in std_logic;

EZ: in std_logic;

 

DIO: inout std_logic_vector (7 downto 0);

RDY: out std_logic

);

end entity F;

 

СХ и СУ - сигналы позволения записи значения DIO в регистры соответственно RGX и RGY. Как раз эти значения и нужно умножить.

Далее вычисления я делаю так:

 

process (CLK)

begin

if rising_edge(CLK) then

 

-- write data to registers

if CX = '0' and calc = '0' then

RGX <= DIO;

elsif CY = '0' and calc = '0' then

RGY <= DIO;

end if;

 

-- do calculations if register is updated

if CX = '0' or CY = '0' or calc = '1' then

 

calc <= '1';

 

-- multiply X*Y using addition

-- check if counter == Y

if not count = RGY then

 

-- XY = XY + X

for i in 0 to 7 loop

if (XY(i)='0' and RGX(i)='0' and p(i)='1') or

(XY(i)='0' and RGX(i)='1' and p(i)='0') or

(XY(i)='1' and RGX(i)='0' and p(i)='0') or

(XY(i)='1' and RGX(i)='1' and p(i)='1')

then

XY(i) <= '1';

else

XY(i) <= '0';

end if;

 

if (XY(i)='0' and RGX(i)='1' and p(i)='1') or

(XY(i)='1' and RGX(i)='0' and p(i)='1') or

(XY(i)='1' and RGX(i)='1' and p(i)='0') or

(XY(i)='1' and RGX(i)='1' and p(i)='1')

then

p(i+1) <= '1';

else

p(i+1) <= '0';

end if;

end loop;

 

-- counter ++

-- add 1 to counter

for i in 0 to 7 loop

if (count(i)='0' and inc(i)='0' and cp(i)='1') or

(count(i)='0' and inc(i)='1' and cp(i)='0') or

(count(i)='1' and inc(i)='0' and cp(i)='0') or

(count(i)='1' and inc(i)='1' and cp(i)='1')

then

count(i) <= '1';

else

count(i) <= '0';

end if;

 

if (count(i)='0' and inc(i)='1' and cp(i)='1') or

(count(i)='1' and inc(i)='0' and cp(i)='1') or

(count(i)='1' and inc(i)='1' and cp(i)='0') or

(count(i)='1' and inc(i)='1' and cp(i)='1')

then

cp(i+1) <= '1';

else

cp(i+1) <= '0';

end if;

end loop;

else

RDY <= '1';

calc <= '0';

end if;

end if;

 

Вычисления я деляю за таким алгоритмом. Каждый такт я увиличиваю count на "00000001" тосле чего сравниваю с значением У. Если равны - не нужно продолжать. Если не равны считаю суму ХУ = ХУ + Х. И так далее.

Но тут возникает проблема. Я никак не могу записать значение в регистры - туда записываеться значение с Х вместо 1 поданых на вход. Почему так? И второе - мои вычисления вообще ничего не дают! Никакие сигнали не меняют свое знаение.

 

У кого есть какие-то идеи как сделать - ПОМОГИТЕ ПЛЗ!!!

Share this post


Link to post
Share on other sites

Почему не хотите ,как пример взять макрофункции которые есть в пакетах Altere , Xilings и др? Там есть примеры,которые можете посмотреть.

Share this post


Link to post
Share on other sites

Прежде всего здесь не видно структуры в описании системы. Разбей требуемый алгоритм на процессы, компоненты, назначь понятные имена сигналам и опиши с правильным синтаксисом. Сколько раз убеждался, что если с первого взгляда понять, что в этот код описывает, то он и не работает.

Share this post


Link to post
Share on other sites

У кого есть какие-то идеи как сделать - ПОМОГИТЕ ПЛЗ!!!

 

Ну идей-то море. Я вот пару секунд назад заказал в Active-HDL-е

мултиплаер 4x4 signed и вот что он мне родил:

 

--

-- Copyright © 2000 by Alatek. All rights reserved.

--

--------------------------------------------------------------------------------/

-- DESCRIPTION : Component was generated by Alatek IP Core generator

-- Details:

-- Signed mulitplier:

-- A (A) input width : 4

-- B (B) input width : 4

-- Q (Q) output width : 7

-- CREATED : 2004-12-7, 15:32:15

-- VERSION : 2.0

--------------------------------------------------------------------------------/

 

library IEEE;

use IEEE.std_logic_1164.all;

 

entity one_bit_adder is

port (

A: in STD_LOGIC;

B: in STD_LOGIC;

C_in: in STD_LOGIC;

S: out STD_LOGIC;

C_out: out STD_LOGIC

);

end one_bit_adder;

 

architecture one_bit_adder of one_bit_adder is

begin

 

S <= A xor B xor C_in;

C_out <= (A and B) or (C_in and (A xor B));

 

end one_bit_adder;

 

library IEEE;

use IEEE.std_logic_1164.all;

 

entity MULTI is

port (

A: in STD_LOGIC_VECTOR (3 downto 0);

B: in STD_LOGIC_VECTOR (3 downto 0);

Q: out STD_LOGIC_VECTOR (6 downto 0)

);

end MULTI;

 

architecture MULTI_arch of MULTI is

signal A_MULT_B0: STD_LOGIC_VECTOR (2 downto 0);

signal A_MULT_B1: STD_LOGIC_VECTOR (2 downto 0);

signal A_MULT_B2: STD_LOGIC_VECTOR (2 downto 0);

 

signal S_TEMP1: STD_LOGIC_VECTOR (1 downto 0);

signal S_TEMP2: STD_LOGIC_VECTOR (1 downto 0);

 

signal C_TEMP : STD_LOGIC_VECTOR (6 downto 0);

 

signal C0_out_B0, C1_out_B0, C2_out_B0 : STD_LOGIC;

signal C0_out_B1, C1_out_B1, C2_out_B1 : STD_LOGIC;

 

signal ZERO: STD_LOGIC;

 

component one_bit_adder

port (

A: in STD_LOGIC;

B: in STD_LOGIC;

C_in: in STD_LOGIC;

S: out STD_LOGIC;

C_out: out STD_LOGIC

);

end component;

begin

U_0_0 : one_bit_adder port map (A => A_MULT_B0(1), B => A_MULT_B1(0), C_in => ZERO, S => C_TEMP(1), C_out => C0_out_B0);

U_0_1 : one_bit_adder port map (A => A_MULT_B0(2), B => A_MULT_B1(1), C_in => C0_out_B0, S => S_TEMP1(0), C_out => C1_out_B0);

U_0_2 : one_bit_adder port map (A => ZERO, B => A_MULT_B1(2), C_in => C1_out_B0, S => S_TEMP1(1), C_out => C2_out_B0);

 

U_1_0 : one_bit_adder port map (A => A_MULT_B2(0), B => S_TEMP1(0), C_in => ZERO, S => C_TEMP(2), C_out => C0_out_B1);

U_1_1 : one_bit_adder port map (A => A_MULT_B2(1), B => S_TEMP1(1), C_in => C0_out_B1, S => S_TEMP2(0), C_out => C1_out_B1);

U_1_2 : one_bit_adder port map (A => A_MULT_B2(2), B => C2_out_B0, C_in => C1_out_B1, S => S_TEMP2(1), C_out => C2_out_B1);

 

A_MULT_B0(0) <= A (0) and B (0);

A_MULT_B0(1) <= A (1) and B (0);

A_MULT_B0(2) <= A (2) and B (0);

 

A_MULT_B1(0) <= A (0) and B (1);

A_MULT_B1(1) <= A (1) and B (1);

A_MULT_B1(2) <= A (2) and B (1);

 

A_MULT_B2(0) <= A (0) and B (2);

A_MULT_B2(1) <= A (1) and B (2);

A_MULT_B2(2) <= A (2) and B (2);

 

ZERO <= '0';

C_TEMP(0) <= A_MULT_B0(0);

C_TEMP(4 downto 3) <= S_TEMP2(1 downto 0);

C_TEMP(5) <= C2_out_B1;

 

C_TEMP(6) <= A(3) xor B(3);

 

Q <= C_TEMP;

 

end MULTI_arch;

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...