Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] VHDL LOOP IS NOT WORKING

Status
Not open for further replies.

Soh_bhat

Junior Member level 1
Junior Member level 1
Joined
Sep 1, 2022
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
22
Hi there,
I have tried to add and subtract to check the for loop using two equations. But, whenever I am using it, it is giving result of first step only and the loop is unrolling. What is the error in my code?
Code:
Behavioural:
package pk5 is
 type T is range 0.0 to 50.0;
 type T1 is array (0 to 3) of T;
end pk5;

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;
use work.pk5.all;

entity add is
   Port ( x : in T1 ;
          y : in T1;
          h : in T;
          x_o : out T1;
          y_o : out T1);
end add;

architecture Behavioral of add is

signal p, q : T1;

begin

process(x, y, h)
begin
x_o(0) <= 0.0;
y_o(0) <= 0.0;

addi: for i in 1 to 3 loop
x_o(i) <= x(i-1) + h;
y_o(i) <= y(i-1) - x(i-1);
end loop;

end Behavioural;

Test Bench:
library IEEE;

use IEEE.STD_LOGIC_1164.ALL;
use work.pk5.all;

entity add_TB is

end add_TB;

architecture Behavioral of add_TB is

component add is
Port ( x : in T1;
          y : in T1;
          h : in T;
          x_o : out T1;
          y_o : out T1);
end component;

signal x: T1;
signal y: T1;
signal h: T;
signal x_o: T1;
signal y_o: T1;

begin

uut: add port map (
x => x,
y => y,
h => h,
x_o => x_o,
y_o => y_o);

add_proc: process
begin
 x(0) <= 1.0;
   y(0) <= 10.0;
   h <= 0.1;
  wait for 5 ns;
 end process;

 end Behavioral;

It is giving the first output only.

PLease help!!!


Screenshot from 2022-08-31 19-01-00.png
 
Last edited by a moderator:

The error is in the assumption that the left-hand side of signal assignments would be instantly updated. This is not the case, the signals are updated at process exit. If you want to use the result of a previous assignment in the process flow, you have to refer to variables.
--- Updated ---

Consider also that the real subtype "range 0.0 to 50.0" isn't synthesizable, but it can be used in a simulation.
 

So, I have to use variable inside the loop and define the output outside the loop.That's what you are saying?
Could you please share a short syntax regarding this, then that would be pretty much helpful for me.Your time and consideration is really appreciated.
 

I I do this,
begin

Code:
process(x, y, h)
 variable p, q : T1;
begin
--x_o(0) <= 0.0;
--y_o(0) <= 0.0;

addi: for i in 1 to 3 loop
p(i) := x(i-1) + h;
q(i) := y(i-1) - x(i-1);
end loop;

x_o(3) <= p(3);
y_o(3) <= q(3);

end process;

Answer is not coming. Only the input value is showing, output shows as 0.
Please help.
 
Last edited by a moderator:

You want to do something like this
Code:
p(0) := x(0);
q(0) := y(0);
for i in 1 to 3 loop
   p(i) := p(i-1) + h;
   q(i) := q(i-1) - x(i-1);
end loop;
 
Thanks a lot. It's running. Thanks a ton for the help.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top