vga_controller_example

Config File:
1[global]
2clk_pin = E3
3reset_pin = U9
4sys_clk_freq = 100E6
5reset_polarity = '1'
6data_width = 32
7control_width = 32
8default_signal_polarity = '1'
9default_voltage_standard = 3.3V
10pinout_filename = PINOUT.xdc
11default_time_units = ms
12alias srr is state_reg_rec(0);
13alias state_reg : integer is state_reg_rec(0).state_reg;
14
15[vga_controller]
16output blue(4) = B7, C7, D7, D8
17output green(4) = C6, A5, B6, A6
18output h_sync = B11
19output red(4) = A3, B4, C5, A4
20output v_sync = B12
21
VHDL Code:
1library ieee; -- version: beta
2use ieee.std_logic_1164.all; -- lic: non-commercial
3use ieee.numeric_std.all; -- user: local
4use ieee.std_logic_unsigned.all;
5use work.user_defs_pkg.all;
6use work.speakhdl_api_pkg.all;
7
8--==============================================================================================
9entity vga_controller is
10
11 generic (this_sm : integer := -1);
12 port (
13 clk : in std_logic; -- clock: E3, 100MHz
14 reset : in std_logic; -- reset: U9, '1'
15 sm_input : in std_logic_vector(-1 downto 0); -- num inputs: 0
16 sm_output : out std_logic_vector(13 downto 0); -- num outputs: 14
17 sm_io : inout std_logic_vector(-1 downto 0); -- num io: 0
18 next_state_rec : out nsr_array(0 to 0);
19 state_reg_rec : in srr_array(0 to 0) -- num rsc: 1
20 );
21
22end entity vga_controller;
23--==============================================================================================
24
25architecture arch of vga_controller is
26
27 alias blue : std_logic_vector(3 downto 0) is sm_output(3 downto 0); -- output B7,C7,..
28 alias green : std_logic_vector(3 downto 0) is sm_output(7 downto 4); -- output C6,A5,..
29 alias h_sync : std_logic is sm_output(8); -- output B11
30 alias red : std_logic_vector(3 downto 0) is sm_output(12 downto 9); -- output A3,B4,..
31 alias v_sync : std_logic is sm_output(13); -- output B12
32 alias srr is state_reg_rec(0); -- alias (global)
33 alias state_reg : integer is state_reg_rec(0).state_reg; -- alias (global)
34 signal h_enable : std_logic;
35 signal v_enable : std_logic;
36 signal video_on : std_logic;
37
38begin
39--==============================================================================================
40 -- output signals
41 blue(3 downto 0) <= (others => '0');
42
43 green(3 downto 0) <= (others => '0') when (video_on = '0') else
44 (others => '1') when (to_unsigned(srr.counter(1).value, 7)(6) = '0') else
45 (others => '0');
46
47 h_sync <= '0' when (srr.counter(0).value < us(5.12)) else
48 '1';
49
50 red(3 downto 0) <= (others => '0') when (video_on = '0') else
51 (others => '1') when (to_unsigned(srr.counter(1).value, 7)(6) = '1') else
52 (others => '0');
53
54 v_sync <= '0' when (srr.counter(1).value < ms(0.064)) else
55 '1';
56
57--==============================================================================================
58 -- local signals
59 h_enable <= '0' when (srr.counter(0).value < us(5.76)) else
60 '0' when (srr.counter(0).value > us(31.36)) else
61 '1';
62
63 v_enable <= '0' when (srr.counter(1).value < ms(0.992)) else
64 '0' when (srr.counter(1).value > ms(16.352)) else
65 '1';
66
67 video_on <= '1' when (h_enable = '1' and v_enable = '1') else
68 '0';
69
70--==============================================================================================
71 -- units: ms, '1'
72process(state_reg_rec) -- hotkey only
73
74begin -- Log Status: OK
75
76 --------------------------------------------------------------------------------------------
77 ---------------------------sys_clk 100MHz active resource 0 state -1------------------------
78 --------------------------------------------------------------------------------------------
79 RESOURCE_SELECT( sys_clk, next_state_rec, state_reg_rec );
80 --------------------------------------------------------------------------------------------
81 CONFIGURE_COUNTER( 0, us(32.0), no_trans, next_state_rec, state_reg_rec );
82 CONFIGURE_COUNTER( 1, ms(16.672), no_trans, next_state_rec, state_reg_rec );
83
84end process;
85
86end architecture arch;
87--==============================================================================================
88
See also
led_blink_example
sseg_display_example
uart_loopback_example