1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | use IEEE.STD_LOGIC_ARITH.ALL;
|
4 | use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
5 |
|
6 | entity top_module is
|
7 | Port ( led : out STD_LOGIC_VECTOR (7 downto 0);
|
8 | sw : in STD_LOGIC_VECTOR (3 downto 0);
|
9 | ERROR_LED : out std_logic;
|
10 | clk : in STD_LOGIC);
|
11 | end top_module;
|
12 |
|
13 | architecture DigitalMess of top_module is
|
14 | COMPONENT embedded_kcpsm3
|
15 | PORT(
|
16 | in_port : IN std_logic_vector(7 downto 0);
|
17 | interrupt : IN std_logic;
|
18 | reset : IN std_logic;
|
19 | clk : IN std_logic;
|
20 | port_id : OUT std_logic_vector(7 downto 0);
|
21 | write_strobe : OUT std_logic;
|
22 | read_strobe : OUT std_logic;
|
23 | out_port : OUT std_logic_vector(7 downto 0);
|
24 | interrupt_ack : OUT std_logic
|
25 | );
|
26 | END COMPONENT;
|
27 |
|
28 | signal input_port : std_logic_vector(7 downto 0);
|
29 | signal output_port : std_logic_vector(7 downto 0);
|
30 | signal id_port : std_logic_vector(7 downto 0);
|
31 | signal wr : std_logic;
|
32 | signal int : std_logic;
|
33 | signal ledstate : std_logic := '0';
|
34 | signal oneSecond : integer range 0 to 25000000 := 0;
|
35 |
|
36 |
|
37 |
|
38 | begin
|
39 | uC: embedded_kcpsm3 PORT MAP(
|
40 | port_id => id_port,
|
41 | write_strobe => wr,
|
42 | read_strobe => open,
|
43 | out_port => output_port,
|
44 | in_port => input_port,
|
45 | interrupt => int,
|
46 | interrupt_ack => open,
|
47 | reset => '0',
|
48 | clk => CLK
|
49 | );
|
50 |
|
51 | leddriver: process
|
52 | begin
|
53 | wait until rising_edge(clk);
|
54 | if wr = '1' then
|
55 | case id_port is
|
56 | when x"00" =>
|
57 | led <= output_port;
|
58 | when x"01" =>
|
59 | pwm_compare <= output_port;
|
60 | when others => null;
|
61 | end case;
|
62 | end if;
|
63 | end process;
|
64 |
|
65 | input_port(3 downto 0) <= sw;
|
66 |
|
67 | second_timer: process(clk)
|
68 | begin
|
69 | if rising_edge(clk) then
|
70 | if(oneSecond = 25000000) then
|
71 | oneSecond <= 0;
|
72 | int <= '1';
|
73 | else
|
74 | oneSecond <= oneSecond + 1;
|
75 | int <= '0';
|
76 | end if;
|
77 | end if;
|
78 | end process;
|
79 |
|
80 | pwm_timer: process
|
81 | begin
|
82 | wait until rising_edge(clk);
|
83 | if oneMs = 2500 then
|
84 | if counter < pwm_compare then
|
85 | ledstate <= '1';
|
86 | else
|
87 | ledstate <= '0';
|
88 | end if;
|
89 | counter <= counter + 1;
|
90 | oneMs <= 0;
|
91 | else
|
92 | oneMs <= oneMs + 1;
|
93 | end if;
|
94 | end process;
|
95 |
|
96 | ERROR_LED <= ledstate;
|
97 |
|
98 | end DigitalMess;
|