EmbDev.net

Forum: FPGA, VHDL & Verilog I don't understand this


von Aldemaro G. (aldemguz)



Rate this post
useful
not useful
Hello everyone!. I have a problem!. I can't understand why do not work 
how i hope it..

I have 2 components "registro_16bits" and "decoEstado"

on Registro_16bits:
when rising_edge of clock and enable is 1: I can write on Z_out the X_in 
value; I don't have problem here.

the problem is when I connect decoEstado with registro_16bits.

decoEstado receives izq_in and der_in.
truth table:
izq_in | der_in  | z_out
     0          0      0
     0          1      0
     1          0      1
     1          1      0

my desing should to work:
when izq_in is 1 and der_in is 0 I should save x_in value and let get 
out that value on z_out.

 I use decoEstado to assign enable_in on registro_16bits.

I'm apologize, but i don't speak english very well.. I hope u can help 
me..
thanks


I attach the whole code and 2 TestBench Pictures!

---------------------------------------------------------------

-- Registro_16bits code
1
entity registro_16bits is
2
    Port ( x_in : in  STD_LOGIC_VECTOR (15 downto 0);
3
           enable_in : in  STD_LOGIC;
4
           reset_in : in  STD_LOGIC;
5
           clk : in  STD_LOGIC;
6
           z_out : out  STD_LOGIC_VECTOR (15 downto 0));
7
end registro_16bits;
8
9
architecture Behavioral of registro_16bits is
10
--signal temp: std_logic_vector(15 downto 0):=(others=>'0');
11
begin
12
13
process(clk,reset_in)
14
begin
15
if reset_in='1' then
16
  z_out<="0000000000000000";
17
  elsif(clk'event and clk='1') then
18
  if(enable_in='1') then
19
  z_out<=x_in;
20
  end if;
21
end if;
22
end process;
23
24
end Behavioral;
----------------------------------------------------------
----------------------------------------------------------
--deEstado Code
1
entity decoEstado is
2
    Port ( izq_in : in  STD_LOGIC;
3
           der_in : in  STD_LOGIC;
4
           z_out : out  STD_LOGIC);
5
end decoEstado;
6
7
architecture Behavioral of decoEstado is
8
9
begin
10
11
z_out<= izq_in and not(der_in);
12
end Behavioral;
--------------------------------------------------------
--------------------------------------------------------
1
-- neurona_simple code
2
3
4
entity neurona_simple is
5
    Port ( x_in : in  STD_LOGIC_VECTOR (15 downto 0);
6
           izq_in : in  STD_LOGIC;
7
           der_in : in  STD_LOGIC;
8
           reset_in : in  STD_LOGIC;
9
           clk : in  STD_LOGIC;
10
           z_out : out  STD_LOGIC_VECTOR (15 downto 0));
11
end neurona_simple;
12
13
architecture Behavioral of neurona_simple is
14
15
component registro_16bits
16
    Port ( x_in : in  STD_LOGIC_VECTOR (15 downto 0);
17
           enable_in : in  STD_LOGIC;
18
           reset_in : in  STD_LOGIC;
19
           clk : in  STD_LOGIC;
20
           z_out : out  STD_LOGIC_VECTOR (15 downto 0));
21
end component;
22
23
component decoEstado is
24
    Port ( izq_in : in  STD_LOGIC;
25
           der_in : in  STD_LOGIC;
26
           z_out : out  STD_LOGIC);
27
end component;
28
29
signal enable_sg : std_logic :='0';
30
begin
31
32
deco : decoEstado port map(izq_in,der_in,enable_sg);
33
reg : registro_16bits port map(x_in,enable_sg,reset_in,clk,z_out);
34
35
end Behavioral;
----------------------------------------------------------------------

von Aldemaro G. (aldemguz)


Rate this post
useful
not useful
I want to know why don't save the value "2" when the registro_16bits 
receives enable_in = 1 and x_in = 2 on neurona_simple's testbench. I've 
tested that on registro_16bits and all be ok!.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Congratiulations, you found the thing called "latency".

Aldemaro G. wrote:
> when the registro_16bits receives enable_in = 1 and x_in = 2 on
> neurona_simple's testbench.
On (or better before!) the rising egde of "clk" the "enable_in" is '0' 
and therefore "z_out" isn't changed. You see the very same behaviour at 
the moment, when the value '4' doesn't appear on "z_out".

BTW: why so much modules and wiring for a thing you could write in 
almost one line?
1
entity neurona_simple is
2
    Port ( x_in : in  STD_LOGIC_VECTOR (15 downto 0);
3
           izq_in : in  STD_LOGIC;
4
           der_in : in  STD_LOGIC;
5
           reset_in : in  STD_LOGIC;
6
           clk : in  STD_LOGIC;
7
           z_out : out  STD_LOGIC_VECTOR (15 downto 0));
8
end neurona_simple;
9
10
architecture Behavioral of neurona_simple is
11
12
signal enable_sg : std_logic :='0';
13
begin
14
15
  z_out <= (others=>'0') when reset_in='1'   else 
16
           x_in when rising_edge(clk) and izq_in and not(der_in);
17
18
end Behavioral;

: Edited by Moderator
von Aldemaro G. (aldemguz)


Rate this post
useful
not useful
> Congratiulations, you found the thing called "latency".

Thnks for the answer, but how can i calculate it?(can u recommend me a 
book?) Because when i see both testbench, I think those (tb) receives 
the same when rising_edge, :c

von Aldemaro G. (aldemguz)


Rate this post
useful
not useful
> BTW: why so much modules and wiring for a thing you could write in
> almost one line?entity neurona_simple is

I had thinked that. trust me.. but i want to know why don't they behave 
same.. if i want to be a "good designer" into VHDL. i must to know the 
difference between both. And how i can resolve it. I'm crazy.. i know 
^^u

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Aldemaro G. wrote:
> but i want to know why don't they behave same..
What doesn't behave the same?
My description of course behave like yours. I just wanted to show how to 
shorten your nearly hundred lines of code down to one line...

> And how i can resolve it.
You must assign the values to "izq_in" and "der_in" well before the 
next rising edge of "clk".
Or you must start to find the trick behind that "latency": at the rising 
edge of the "clk" the registers attached to it take the values that you 
see just before that edge. And if the enable signals are inactive just 
before the "clk" then the registers won't change at all. Thats what you 
see with your code, and thats the same with my code.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.