-1

I am a fresh student and the assignment is to build 3 components with testbench and then to arrange them into one structure. All 3 components I have built work great but when I put them together one of the the outputs stays undefined. I tried to trace the signal called dat and it is fine, but probably I am not using correct syntax to assign the dat signal to data_out . The id_led_ind is the second output and it works fine but the data_out is undefined.

Here is the code (i think the problem is in lane 21 - "data_out <= dat")

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;

entity peak_detect is
  port(
    input      : in  std_logic_vector (7 downto 0);
    data_out   : out std_logic_vector (7 downto 0);
    reset      : in  std_logic;
    clock      : in  std_logic;
    enable     : in  std_logic;
    id_led_ind : out std_logic);
end peak_detect;

architecture dataflow of peak_detect is
  signal a_big_b : std_logic;
  signal en      : std_logic;
  signal dat     : std_logic_vector (7 downto 0);
begin
  en       <= (enable or a_big_b);
  data_out <= dat;
end dataflow;

architecture structure of peak_detect is
  signal a_big_b : std_logic;
  signal en      : std_logic;
  signal dat     : std_logic_vector (7 downto 0);

  component comp_8bit is
    port(
      A   : in  std_logic_vector (7 downto 0);
      B   : in  std_logic_vector (7 downto 0);
      res : out std_logic);
  end component;

  component dff is
    port (
      data  : in  std_logic_vector (7 downto 0);
      q     : out std_logic_vector (7 downto 0);
      clk   : in  std_logic;
      reset : in  std_logic;
      en    : in  std_logic);
  end component;

  component id_sens is
    port(
      data_in : in  std_logic_vector (7 downto 0);
      led     : out std_logic);
  end component;

begin
  reg  : dff port map (data => input, q => dat, clk => clock, reset => reset, en => enable);
  comp : comp_8bit port map (A => input, B => dat, res => a_big_b);
  sens : id_sens port map (data_in => dat, led => id_led_ind);
end structure;
Morten Zilmer
  • 15,586
  • 3
  • 30
  • 49
user2651144
  • 1
  • 1
  • 1
  • In the dataflow architecture, what drives "dat"? –  Aug 04 '13 at 21:34
  • 1
    Barring command line specification of the architecture and in the absence of a configuration specification the last analyzed architecture will be selected, which in this case would be the architecture structure of peak_detect. If dataflow offends thee, comment it out. –  Aug 04 '13 at 22:46

2 Answers2

1

There appears to be confusion over having two architectures (dataflow and structure) for the entity peak_detect. The two architectures are mutually exclusive, and the last one analyzed is the default in absence of other configuration specifying one of the architectures directly.

For purposes of evaluating how the components are interconnected and their port mapped connections relate to the port declarations of peak_detect, the first architecture could be commented out (dataflow).

When you disregard the architecture dataflow we find there is no driver for data_out in architecture structure.

You're missing an assignment to data_out using dat as a source in architecture structure, as found in architecture dataflow. Copy or replicate the concurrent signal assignment statement data_out <= dat; into architecture structure.

You can't simply connect data_out to q in the port map of dff because the output of dff is also used as an input to id_sense.

0

dat is driven by q of dff. That is not how you connect components. port map should be used to connect ports of different components/entities, not signals of any entity to the port of another entity.

shrm
  • 1,112
  • 2
  • 8
  • 20
  • 1
    dat is a declared signal in the architecture structure of peak_detect. It's perfectly okay to connect a signal as an actual to a formal in a port map when they are the same type with the same range (the subtypes match). What's missing in the connection from dat to data_out in the port declaration for entity peak_detect. –  Aug 04 '13 at 22:41
  • It might be "perfectly okay" for the compiler/simulator, but when it comes to humans trying to read, understand and debug, its far from perfect. Why not put all the logic in one entity then? Tools will be all right with that. – shrm Aug 05 '13 at 21:23
  • It appears you are trying to enforce style as opposed to specifying compliance with the VHDL standard. –  Aug 06 '13 at 05:58
  • Style doesn't necessarily exclude compliance. At least mine dosn't. – shrm Aug 06 '13 at 19:59
  • The standard doesn't embrace your style as required. Note "You can't simply connect data_out to q in the port map of dff because the output of dff is also used as an input to id_sense.", see IEEE Std 1076-2008, 6.5.2 Interface object declarations,Para 18 "- out. The value of the interface object is allowed to be updated and, provided it is not a signal parameter, read." peak_detect port signal data_out is declared mode out and can't be used as an actual in comp8bit association list formal port B mode in - signal parameter data_out can't be read (Para 15). See also -1993, 4.3.2 Para 12/10. –  Aug 06 '13 at 22:54
  • Agreed. I was confused with there being two architectures: dataflow and structure, both declaring dat signal, until I read your answer. Go ahead and down-vote. – shrm Aug 06 '13 at 23:15