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;
|