-
Notifications
You must be signed in to change notification settings - Fork 0
/
addr_counter.vhd
104 lines (93 loc) · 2.29 KB
/
addr_counter.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
------------------------------------------------------------------------
--
-- Copyright (C) 2018
-- All rights reserved
--
-- filename: addr_counter
--
-- created by Tyl at 2019-01-06 09:36:22
-- modified by Tyl at 2019-01-10 13:52:03
--
------------------------------------------------------------------------
-- Quartus II VHDL Template
-- Four-State Moore State Machine
-- A Moore machine's outputs are dependent only on the current state.
-- The output is written only when the state changes. (State
-- transitions are synchronous.)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity addr_counter is
port(
clk, reset: in std_logic;
RAMWCten: in std_logic;
--RAMRCten: in std_logic;
vga_R_addr: in std_logic_vector(11 downto 0);
RAMWaddress: out std_logic_vector(11 downto 0);
RAMWCO: out std_logic;
RAMRaddress: out std_logic_vector(11 downto 0);
RAMRCO: out std_logic
);
end addr_counter;
architecture rtl of addr_counter is
-- Build an enumerated type for the state machine
type state_type is (s0, s1);
-- Register to hold the current state
signal state : state_type;
signal RAMWcounter: std_logic_vector(11 downto 0);
signal RAMRcounter: std_logic_vector(11 downto 0);
begin
-- Logic to advance to the next state
process (clk, reset)
begin
if reset = '1' then
RAMWcounter <= (others => '0');
--RAMRcounter <= (others => '0');
state <= s0;
elsif (rising_edge(clk)) then
case state is
when s0=>
if RAMWCten = '1'then
state <= s1;
else
state <= s0;
end if;
when s1=>
RAMWcounter <= RAMWcounter + 1;
if RAMWCten = '0'then
state <= s0;
else
state <= s1;
end if;
end case;
end if;
end process;
-- Output depends solely on the current state
process (state)
begin
case state is
when s0 =>
RAMWCO <= '0';
when s1 =>
if RAMWcounter = X"FFF" then
RAMWCO <= '1';
else
RAMWCO <= '0';
end if;
end case;
end process;
--读地址计数
RAMRcounter <= vga_R_addr;
--地址输出模块
RAMWaddress <= RAMWcounter;
RAMRaddress <= RAMRcounter;
--读地址进位输出模块
process(RAMRcounter)
begin
if RAMRcounter = X"FFF" then
RAMRCO <= '1';
else
RAMRCO <= '0';
end if;
end process;
end rtl;