@[email protected] asked
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity my_code is
generic(
WIDTH : integer := 640;
HEIGHT : integer := 480;
CONSOLE_COLUMNS : integer := WIDTH / 8;
CONSOLE_ROWS : integer := HEIGHT / 8
);
port(
clk : in std_logic;
rst : in std_logic;
px : in integer range 0 to WIDTH - 1;
py : in integer range 0 to HEIGHT - 1;
hsync : in std_logic;
vsync : in std_logic;
col : in integer range 0 to CONSOLE_COLUMNS - 1;
row : in integer range 0 to CONSOLE_ROWS - 1;
char : out integer range 0 to 127 := 0;
foreground_color : out std_logic_vector(23 downto 0) := (others => '0');
background_color : out std_logic_vector(23 downto 0) := (others => '1');
uart_data : out std_logic_vector(7 downto 0) := (others => '0');
uart_ready : in std_logic;
uart_valid : out std_logic := '0'
);
end my_code;
architecture rtl of my_code is
alias red : std_logic_vector(7 downto 0) is background_color(23 downto 16);
alias green : std_logic_vector(7 downto 0) is background_color(15 downto 8);
alias blue : std_logic_vector(7 downto 0) is background_color(7 downto 0);
signal frame_counter : unsigned(31 downto 0) := (others => '0');
signal example_text : string(1 to 13) := "temp = ???? C";
constant example_text_row : integer := 15;
constant example_text_col : integer := 15;
type temperature_map_t is array (0 to 63) of string(1 to 4);
constant temperature_map : temperature_map_t := (
0 => " -58",
1 => " -56",
2 => " -54",
3 => " -52",
4 => " -45",
5 => " -44",
6 => " -43",
7 => " -42",
8 => " -41",
9 => " -40",
10 => "- 39",
11 => "- 38",
12 => "- 37",
13 => "- 36",
14 => "- 30",
15 => "- 20",
16 => "- 10",
17 => "- 4",
18 => " 0",
19 => "+ 4",
20 => "+ 10",
21 => "+ 21",
22 => "+ 22",
23 => "+ 23",
24 => "+ 24",
25 => "+ 25",
26 => "+ 26",
27 => "+ 27",
28 => "+ 28",
29 => "+ 29",
30 => "+ 40",
31 => "+ 50",
32 => "+ 60",
33 => "+ 70",
34 => "+ 76",
35 => "+ 80",
36 => "+ 81",
37 => "+ 82",
38 => "+ 83",
39 => "+ 84",
40 => "+ 85",
41 => "+ 86",
42 => "+ 87",
43 => "+ 88",
44 => "+ 89",
45 => "+ 95",
46 => "+ 96",
47 => "+ 97",
48 => "+ 98",
49 => "+ 99",
50 => "+100",
51 => "+101",
52 => "+102",
53 => "+103",
54 => "+104",
55 => "+105",
56 => "+106",
57 => "+107",
58 => "+108",
59 => "+116",
60 => "+120",
61 => "+124",
62 => "+128",
63 => "+132"
);
component DTR is
port (
STARTPULSE : in std_logic;
DTROUT7 : out std_logic;
DTROUT6 : out std_logic;
DTROUT5 : out std_logic;
DTROUT4 : out std_logic;
DTROUT3 : out std_logic;
DTROUT2 : out std_logic;
DTROUT1 : out std_logic;
DTROUT0 : out std_logic
);
end component;
signal temp : unsigned(5 downto 0) := (others => '0');
signal startpulse : std_logic := '0';
begin
char <= character'pos(example_text(col + 1 - example_text_col))
when col >= example_text_col and col < example_text'length + example_text_col and row = example_text_row else 0;
red <= std_logic_vector(to_unsigned(col*4, 8));
green <= std_logic_vector(to_unsigned(py, 8));
blue <= std_logic_vector(resize(frame_counter, 8));
foreground_color <= (others => '1');
dtr_inst: DTR
port map (
STARTPULSE => startpulse,
DTROUT7 => open,
DTROUT6 => open,
DTROUT5 => temp(5),
DTROUT4 => temp(4),
DTROUT3 => temp(3),
DTROUT2 => temp(2),
DTROUT1 => temp(1),
DTROUT0 => temp(0)
);
example_text(8 to 11) <= temperature_map(to_integer(temp));
process(clk)
variable old_vsync : std_logic := '0';
begin
if rising_edge(clk) then
startpulse <= '0';
if vsync = '0' and old_vsync = '1' then
frame_counter <= frame_counter + 1;
startpulse <= '1';
end if;
old_vsync := vsync;
end if;
end process;
end architecture;
Success!
UART Output
UtilizationCellUsedAvailableUsage
DCCA2563.6%
DTR11100.0%
EHXPLLL1250.0%
TRELLIS_COMB1238242885.1%
TRELLIS_FF158242880.7%
TRELLIS_IO111975.6%
TimingClockAchievedConstraint
$glbnet$clkp40.71 MHz25 MHz
$glbnet$clkt319.69 MHz250 MHz
Code
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity my_code is
generic(
WIDTH : integer := 640;
HEIGHT : integer := 480;
CONSOLE_COLUMNS : integer := WIDTH / 8;
CONSOLE_ROWS : integer := HEIGHT / 8
);
port(
clk : in std_logic;
rst : in std_logic;
px : in integer range 0 to WIDTH - 1;
py : in integer range 0 to HEIGHT - 1;
hsync : in std_logic;
vsync : in std_logic;
col : in integer range 0 to CONSOLE_COLUMNS - 1;
row : in integer range 0 to CONSOLE_ROWS - 1;
char : out integer range 0 to 127 := 0;
foreground_color : out std_logic_vector(23 downto 0) := (others => '0');
background_color : out std_logic_vector(23 downto 0) := (others => '1');
uart_data : out std_logic_vector(7 downto 0) := (others => '0');
uart_ready : in std_logic;
uart_valid : out std_logic := '0'
);
end my_code;
architecture rtl of my_code is
alias red : std_logic_vector(7 downto 0) is background_color(23 downto 16);
alias green : std_logic_vector(7 downto 0) is background_color(15 downto 8);
alias blue : std_logic_vector(7 downto 0) is background_color(7 downto 0);
signal frame_counter : unsigned(31 downto 0) := (others => '0');
signal example_text : string(1 to 13) := "temp = ???? C";
constant example_text_row : integer := 15;
constant example_text_col : integer := 15;
type temperature_map_t is array (0 to 63) of string(1 to 4);
constant temperature_map : temperature_map_t := (
0 => " -58",
1 => " -56",
2 => " -54",
3 => " -52",
4 => " -45",
5 => " -44",
6 => " -43",
7 => " -42",
8 => " -41",
9 => " -40",
10 => "- 39",
11 => "- 38",
12 => "- 37",
13 => "- 36",
14 => "- 30",
15 => "- 20",
16 => "- 10",
17 => "- 4",
18 => " 0",
19 => "+ 4",
20 => "+ 10",
21 => "+ 21",
22 => "+ 22",
23 => "+ 23",
24 => "+ 24",
25 => "+ 25",
26 => "+ 26",
27 => "+ 27",
28 => "+ 28",
29 => "+ 29",
30 => "+ 40",
31 => "+ 50",
32 => "+ 60",
33 => "+ 70",
34 => "+ 76",
35 => "+ 80",
36 => "+ 81",
37 => "+ 82",
38 => "+ 83",
39 => "+ 84",
40 => "+ 85",
41 => "+ 86",
42 => "+ 87",
43 => "+ 88",
44 => "+ 89",
45 => "+ 95",
46 => "+ 96",
47 => "+ 97",
48 => "+ 98",
49 => "+ 99",
50 => "+100",
51 => "+101",
52 => "+102",
53 => "+103",
54 => "+104",
55 => "+105",
56 => "+106",
57 => "+107",
58 => "+108",
59 => "+116",
60 => "+120",
61 => "+124",
62 => "+128",
63 => "+132"
);
component DTR is
port (
STARTPULSE : in std_logic;
DTROUT7 : out std_logic;
DTROUT6 : out std_logic;
DTROUT5 : out std_logic;
DTROUT4 : out std_logic;
DTROUT3 : out std_logic;
DTROUT2 : out std_logic;
DTROUT1 : out std_logic;
DTROUT0 : out std_logic
);
end component;
signal temp : unsigned(5 downto 0) := (others => '0');
signal startpulse : std_logic := '0';
begin
char <= character'pos(example_text(col + 1 - example_text_col))
when col >= example_text_col and col < example_text'length + example_text_col and row = example_text_row else 0;
red <= std_logic_vector(to_unsigned(col*4, 8));
green <= std_logic_vector(to_unsigned(py, 8));
blue <= std_logic_vector(resize(frame_counter, 8));
foreground_color <= (others => '1');
dtr_inst: DTR
port map (
STARTPULSE => startpulse,
DTROUT7 => open,
DTROUT6 => open,
DTROUT5 => temp(5),
DTROUT4 => temp(4),
DTROUT3 => temp(3),
DTROUT2 => temp(2),
DTROUT1 => temp(1),
DTROUT0 => temp(0)
);
example_text(8 to 11) <= temperature_map(to_integer(temp));
process(clk)
variable old_vsync : std_logic := '0';
begin
if rising_edge(clk) then
startpulse <= '0';
if vsync = '0' and old_vsync = '1' then
frame_counter <= frame_counter + 1;
startpulse <= '1';
end if;
old_vsync := vsync;
end if;
end process;
end architecture;
#FPGA #Icepi-Zero #HDL #VHDL