реклама на сайте
подробности

 
 
> помогите разобраться с кодом
mcaffee
сообщение Sep 5 2015, 16:27
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 46
Регистрация: 9-10-12
Пользователь №: 73 873



Всем доброго времени суток!
Среди поисков алгоритмов dds нашел вот такой код.
Из этого кода все, что я понял, так это то, что 40 рязрядный сумматор разбит на десять 4-х разрядных сумматоров. Не могли бы Вы описать более подробную картину, что здесь происходит?)

CODE
long_code_here =
library ieee;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_arith.all;
entity Accumulator is
port (
clk : in std_logic;
rst : in std_logic;
wr : in std_logic;
D : in std_logic_vector (39 downto 0);
S : out std_logic_vector (39 downto 0)
);
end Accumulator;
architecture rtl of Accumulator is
component Adder_4bit is
port (
clk : in std_logic;
rst : in std_logic;
A : in std_logic_vector (3 downto 0);
B : in std_logic_vector (3 downto 0);
cin : in std_logic;
S : out std_logic_vector (3 downto 0);
cout : out std_logic
);
end component;
component my_reg is
generic (
size : integer range 1 to 255:=1;
W : integer range 1 to 32:=4
);
port (
clk : in std_logic;
rst : in std_logic;
wr : in std_logic;
D : in std_logic_vector (W-1 downto 0);
Q : out std_logic_vector (W-1 downto 0)
);
end component;
type result_type is array(9 downto 0) of std_logic_vector(3 downto 0);
signal res0, res1, res, input : result_type:=(others=>(others=>'0'));
signal carry_chain0, carry_chain1, carry_chain : std_logic_vector (9 downto 0):=(others=>'0');
begin
inputs : for i in 1 to 10 generate
reg_chain : my_reg
generic map (i, 4)
port map (clk, rst, D(4*i-1 downto 4*(i-1)), input(i-1));
end generate;

first_adder : Adder_4bit
port map (clk, rst, input(0), res(0), '0', res(0), carry_chain(0));
adders : for i in 1 to 9 generate
carry : Adder_4bit
port map (clk, rst, input(i), res(i), '1', res1(i), carry_chain1(i));
no_carry : Adder_4bit
port map (clk, rst, input(i), res(i), '0', res0(i), carry_chain0(i));
end generate;
sum_mux : for i in 1 to 9 generate
res(i)<=
res0(i) when carry_chain(i-1)='0' else
res1(i);
carry_chain(i)<=
carry_chain0(i) when carry_chain(i-1)='0' else
carry_chain1(i);
end generate;
output_assign : for i in 1 to 10 generate
S(4*i-1 downto 4*(i-1))<=res(i-1);
end generate;
end rtl;


Далее идет описание компонента Adder_4bit
CODE
long_code_here =
library ieee;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
USE IEEE.std_logic_arith.all;

entity Adder_4bit is
port (
clk : in std_logic;
rst : in std_logic;
A : in std_logic_vector (3 downto 0);
B : in std_logic_vector (3 downto 0);
cin : in std_logic;
S : out std_logic_vector (3 downto 0);
cout : out std_logic
);
end Adder_4bit;

architecture rtl of Adder_4bit is
signal sum : std_logic_vector (4 downto 0);
signal op1, op2 : std_logic_vector (3 downto 0);
begin
process (rst,clk)
begin
if (rst='1') then
sum<=(others=>'0');
elsif (clk'event and clk='1') then
sum <= ('0' & A)+('0' & B )+cin;
end if;
end process;
S <= sum(3 downto 0);
cout <= sum(4);
end rtl;


И компонента my_reg
CODE
long_code_here =
library ieee;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;

entity my_reg is
generic (
size : integer range 1 to 255:=1;
W : integer range 1 to 32:=4
);
port (
-- Системный интерфейс
clk : in std_logic;
rst : in std_logic;
wr : in std_logic;
D : in std_logic_vector (W-1 downto 0);
Q : out std_logic_vector (W-1 downto 0)
);
end my_reg;

architecture rtl of my_reg is
type reg_chain_type is array (size-1 downto 0) of std_logic_vector (W-1 downto 0);
signal reg_chain : reg_chain_type;
signal ena_chain : std_logic_vector (size-1 downto 0);
begin
process (clk, rst)
begin
if (rst='1') then
ena_chain<=(others=>'0');
elsif (clk'event and clk='1') then
ena_chain(0)<='1';
if (size>1) then
for i in 1 to size-1 loop
ena_chain(i)<=ena_chain(i-1);
end loop;
end if;
end if;
end process;

process (rst, clk)
begin
if (rst='1') then
reg_chain<=(others=>(others=>'0'));
elsif (clk'event and clk='1') then
if (ena_chain(0)='1') then
reg_chain(0)<=D;
end if;
if (size>1) then
for i in 1 to size-1 loop
if (ena_chain(i)='1') then
reg_chain(i)<=reg_chain(i-1);
end if;
end loop;
end if;
end if;
end process;
Q<=reg_chain(size-1);
end rtl;


Здесь, в таких тонкостях, еще хуже. … не понятно, как это функционирует все вместе…
Подскажите, поделитесь своими мыслями!)
Хочу разобраться для начала с этим, поскольку дальше еще используется перекодировка с таблицей синусов.
Заранее большое спасибо всем откликнувшимся!)

Go to the top of the page
 
+Quote Post

Сообщений в этой теме
- mcaffee   помогите разобраться с кодом   Sep 5 2015, 16:27
- - Krys   Предлагаю для начала ознакомиться с готовыми реали...   Sep 8 2015, 03:47
- - Artemius_tv   Сумматор разбит на 10 маленьких для организации ко...   Sep 8 2015, 06:07
- - mcaffee   В продолжении обсуждения вопроса про dds. С выход...   Sep 21 2015, 10:34
- - Krys   Вобщем, здесь тоже разбито на 2 стадии. Вся таблиц...   Sep 21 2015, 11:00
|- - mcaffee   Цитата(Krys @ Sep 21 2015, 15:00) Вобщем,...   Sep 21 2015, 11:54
- - Artemius_tv   Самый старший (12-й) бит будет отвечать за знак, а...   Sep 21 2015, 13:16
|- - mcaffee   Цитата(Artemius_tv @ Sep 21 2015, 17:16) ...   Sep 21 2015, 21:37
|- - Artemius_tv   Цитата(mcaffee @ Sep 22 2015, 00:37) Подс...   Sep 22 2015, 06:58
- - Krys   А какой ЦАП? Надо на него доку читануть, из неё ст...   Sep 22 2015, 05:06
|- - mcaffee   Цитата(Krys @ Sep 22 2015, 09:06) А какой...   Sep 22 2015, 05:38
|- - Krys   Цитата(mcaffee @ Sep 22 2015, 04:37) А ес...   Sep 22 2015, 11:11
- - Krys   А ПЛИС какая, что ресурсов на таблицу не хватит? Б...   Sep 22 2015, 07:21
- - Golikov A.   ЦитатаКстати, насколько я помню, количество исполь...   Sep 22 2015, 07:33
- - Krys   Тем более, что это всё в теории описано в том доку...   Sep 22 2015, 07:35
- - Krys   ТС, Вы куда исчезаете так надолго? Потом приходитс...   Sep 24 2015, 04:07
- - Corner   Для ускорения аккумулятора больше 4 счетчиков избы...   Sep 28 2015, 19:38
- - Krys   Не очень понятно, про какие 4 счётчика идёт речь?   Sep 29 2015, 04:30
- - Krys   И как пользоваться поправочной табличкой? Может, д...   Sep 29 2015, 06:49
- - Golikov A.   ну как так? аккумулятор - аккумулирует а сумматор ...   Sep 29 2015, 07:10
- - Krys   иногда просто под аккумулятором понимается суммато...   Sep 29 2015, 09:02
- - Golikov A.   аккумулятор - это хранение и сумма сумматор - это ...   Sep 29 2015, 12:33
- - Krys   Ааа, тогда вопросов нет, спасибо. Точнее остаются...   Sep 30 2015, 08:13
- - Artemius_tv   Видимо эти 2 таблицы это таблица значений и таблиц...   Sep 30 2015, 09:05
- - Krys   Хорошо, допустим с таблицами понятно. Хотя тоже не...   Oct 12 2015, 07:46
- - Artemius_tv   Ну, я это вариант не предлагал, а только написал с...   Oct 12 2015, 08:25
- - Krys   Цитата(Artemius_tv @ Oct 12 2015, 15:25) ...   Oct 12 2015, 11:19


Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 6th July 2025 - 20:37
Рейтинг@Mail.ru


Страница сгенерированна за 0.01398 секунд с 7
ELECTRONIX ©2004-2016