EmbDev.net

Forum: FPGA, VHDL & Verilog VHDL: Port map with std_logic_vector


von LiZhen L. (Guest)


Rate this post
useful
not useful
I'm trying to simulate a ring oscillator driving a 6-bit counter. The 
counter works fine. I've declared a new signal to store the output from 
the counter, but I'm not so sure about the port map for the counter when 
I included it as a part of the ring oscillator.
1
--6 BIT COUNTER (works fine)
2
3
LIBRARY IEEE;
4
USE IEEE.STD_LOGIC_1164.ALL;
5
USE IEEE.STD_LOGIC_ARITH.All;
6
USE IEEE.STD_LOGIC_SIGNED.ALL;
7
8
ENTITY counter_vhdl IS
9
PORT (clock,reset     : IN std_logic;
10
      output          : OUT std_logic_vector(0 TO 5));
11
END counter_vhdl;
12
13
ARCHITECTURE behav OF counter_vhdl IS 
14
CONSTANT Tdelay  : time := 10 ns; -- Typical delay
15
16
BEGIN
17
18
check_clock : PROCESS(clock, reset)
19
VARIABLE count  : std_logic_vector(0 TO 5) := "000000";
20
BEGIN
21
            
22
IF ( reset = '0') THEN
23
  count := "000000";
24
  ELSIF ( clock'event and clock = '1') THEN
25
    IF (count = "111111") THEN
26
      count := "000000";
27
    ELSE
28
      count :=  count + "000001";
29
    END IF;
30
END IF;
31
  output <= count AFTER Tdelay;
32
33
END PROCESS check_clock;
34
END behav;
35
36
37
--Ring oscillator with counter
38
39
LIBRARY IEEE;
40
USE IEEE.STD_LOGIC_1164.ALL;
41
USE IEEE.STD_LOGIC_ARITH.All;
42
USE IEEE.STD_LOGIC_SIGNED.ALL;
43
44
ENTITY ring_vhdl IS
45
PORT(  ring_osc_enb,reset   : IN std_logic;
46
       OUT1, OUT2    : OUT std_logic; 
47
       data_out      : OUT std_logic_vector(0 TO 5));
48
END ring_vhdl;
49
50
ARCHITECTURE struct OF ring_vhdl IS
51
  COMPONENT OSCILLATOR
52
    PORT (ENB: IN std_logic; OUT1, OUT2 : OUT std_logic);
53
  END COMPONENT;
54
  
55
  COMPONENT COUNTER 
56
               PORT(clock,reset: IN std_logic;
57
                    data_out   : OUT std_logic_vector(0 TO 5));
58
        END COMPONENT;
59
60
  signal osc1, osc2  : std_logic;
61
  signal count6     : std_logic_vector(0 TO 5);  
62
63
  FOR u1: OSCILLATOR USE ENTITY WORK.ring_oscillator_vhdl(struct);
64
  FOR u2: COUNTER USE ENTITY WORK.counter_vhdl(behav);
65
  
66
  BEGIN
67
68
    u1:OSCILLATOR PORT MAP(ring_osc_enb,osc1,osc2);
69
    u2:COUNTER PORT MAP(osc1,reset,count6);    <-----
70
    
71
    OUT1 <= osc1;
72
    OUT2 <= osc2;
73
    data_out <= count6;
74
75
END struct;

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


Rate this post
useful
not useful
And what's the problem now?

LiZhen L. wrote:
> but I'm not so sure about the port map for the counter
Indeed: an ascending bit order is unusual for counters. In your counter 
bit 5 is the fastest toggling bit. In 99.9999% around the world always 
bit 0 is the lowest and fastest toggling bit.
In short words: I would declare a vector always with "downto". Billions 
of people expect it that way...

For the port map: do not use positional assignment. Better use explicit 
assignment:
1
   u2:COUNTER PORT MAP(clock=>osc1,reset=>reset,data_out=>count6);

BTW: did you find that about the [vhdl] formatting options tags?

: Edited by Moderator
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.