Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Need help with VHDL!!! =(

Hi everyone. I've been trying to fix this code but failed. Can anyone tell me what's wrong with it?

Also, what does this mean? What's the relation between them?

buf(serial_count) := serial_in_port;

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity MetroLRT is
port(
clk: in bit;
rst: in bit;
task: in bit_vector(1 downto 0);
stationed: in bit_vector(3 downto 0);
timeSTP: in bit;
serial_in_port: buffer std_logic;
serial_out_port: out bit;
gate_open_out: out bit
);
end MetroLRT;
architecture rtl of MetroLRT is
--signal
signal header1: std_logic_vector(3 downto 0);
signal balance1: std_logic_vector(6 downto 0);
signal t_stamp1: std_logic;
signal card_in1: std_logic_vector(15 downto 0);
signal station1: std_logic_vector(3 downto 0);
signal serial_count: bit;
signal buf: bit;
begin
process(clk, serial_in_port)
--variable
begin	
	if rst = '0' then
		serial_in_port <= '0';
	elsif 
		clk'event and clk = '1' then
			if	serial_in_port <= '1' then
				buf(serial_count) := serial_in_port;
				--store card info to all temporary variables
				card_in1 <= "0000000000000000";
				header1 <= "1010";
				t_stamp1 <= '1';
				station1 <= "0000";
			end if;
	end if;
end process;
enter_station: process(task)
begin
	if task = "00" then
		if header1 = "1010" then
			if balance1 >= "0001000" then
				if t_stamp1 = '1' then
					card_in1 <= "0000000";
					station1 <= "0000";
					gate_open_out <= '1';
				else
					card_in1 <= null;
					station1 <= null;
					gate_open_out <= '0';
				end if;
			end if;
		end if;
	end if;
end process;
end rtl;

Thankssss!!!!

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Jigalong,

    buf is a signal, you have to use <= to assign it a value. := is used for variable

    Then, buf is one bit long, you cannot select which bit to use!

    try :

     buf <= serial_in_port;

    Regards

    PS : your first process is kind of strange...

    At reset, you set serial_in_port to '0', then you test if serial_in_port is smaller than '1'. Of course it is!

    Is this the behaviour you're waiting for ?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello Jigalong; I have modified your code below to be a bit cleaner and address the issue that mazel mentioned above, as well as remove the "null" statements which are not valid & change to VHDL 2008. This is a good illustration of some of the basic constructs that make 2008 a bit cleaner. -James

    library ieee;

    use ieee.std_logic_1164.all;

    use ieee.numeric_std.all;

    entity MetroLRT is

    port(

    clk: in bit;

    rst: in bit;

    task: in bit_vector(1 downto 0);

    stationed: in bit_vector(3 downto 0);

    timeSTP: in bit;

    serial_in_port: buffer std_logic;

    serial_out_port: out bit;

    gate_open_out: out bit

    );

    end MetroLRT;

    architecture rtl of MetroLRT is

    --signal

    signal header1: std_logic_vector(3 downto 0);

    signal balance1: std_logic_vector(6 downto 0);

    signal t_stamp1: std_logic;

    signal card_in1: std_logic_vector(15 downto 0);

    signal station1: std_logic_vector(3 downto 0);

    signal serial_count: bit;

    signal buf: std_logic;

    begin

    process(all)

    --variable

    begin

    if not(rst) then

    serial_in_port <= '0';

    elsif rising_edge(clk) then

    if serial_in_port then

    buf <= serial_in_port;

    --store card info to all temporary variables

    card_in1 <= X"0000" ;

    header1 <= X"A";

    t_stamp1 <= '1';

    station1 <= X"0";

    end if;

    end if;

    end process;

    enter_station: process(all)

    begin

    if task = "00" then

    if header1 = "1010" then

    if balance1 >= "0001000" then

    if t_stamp1 = '1' then

    card_in1 <= X"0000";

    station1 <= "0000";

    gate_open_out <= '1';

    else

    gate_open_out <= '0';

    end if;

    end if;

    end if;

    end if;

    end process;

    end rtl;
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks Mazel and James Bonanno for your help.

    --- Quote Start ---

    buf is a signal, you have to use <= to assign it a value. := is used for variable

    --- Quote End ---

    Thanks! I always get confused with that.

    --- Quote Start ---

    Then, buf is one bit long, you cannot select which bit to use!

    --- Quote End ---

    I don't really get this. :confused:

    --- Quote Start ---

    PS : your first process is kind of strange...

    At reset, you set serial_in_port to '0', then you test if serial_in_port is smaller than '1'. Of course it is!

    Is this the behaviour you're waiting for ?

    --- Quote End ---

    Yea, it is strange lol. I'm kinda new at this. So it's kinda messed up. =s

    --- Quote Start ---

    card_in1 <= X"0000" ;

    header1 <= X"A";

    t_stamp1 <= '1';

    station1 <= X"0";

    --- Quote End ---

    What does the x mean?

    So, I changed all of the types to std_logic and there's an error saying that
    "rst" does not agree with its usage as "boolean" type.
    . Tried changing all the types to bit and still got the same error. How do I fix this?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Tried changing all the types to bit and still got the same error. How do I fix this?

    --- Quote End ---

    Thats because James use 2008 notation. Either change it to:

    if rst = '1' then

    or change project settings to use VHDL 2008
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    if serial_in_port then

    --- Quote End ---

    I tried running this code but there was an error saying

    error (10476): vhdl error at metro_lrt.vhd(52): type of identifier "serial_in_port" does not agree with its usage as "boolean" type

    Can anyone tell me what it means please? Thanks.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    boolean means it can only have 2 values : true or false.

    serial_in_port is a std_logic, so its possible values are '0' and '1'.

    You have to do as for the rst signal : if serial_in_port = '1' then