1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 |
|
4 | -- Uncomment the following library declaration if using
|
5 | -- arithmetic functions with Signed or Unsigned values
|
6 | use IEEE.NUMERIC_STD.ALL;
|
7 | use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
8 |
|
9 | -- Uncomment the following library declaration if instantiating
|
10 | -- any Xilinx primitives in this code.
|
11 | --library UNISIM;
|
12 | --use UNISIM.VComponents.all;
|
13 |
|
14 | entity uart_transmitter is
|
15 | Port ( clk_i : in STD_LOGIC;
|
16 | rst_i : in STD_LOGIC := '0';
|
17 | ld_i : in STD_LOGIC := '1';
|
18 | din_i : in STD_LOGIC_VECTOR (7 downto 0) := "01010101"; --test
|
19 | tx_o : out STD_LOGIC);
|
20 | end uart_transmitter;
|
21 |
|
22 | architecture Behavioral of uart_transmitter is
|
23 |
|
24 |
|
25 | type state_t is (idleState, startState, activeState, parityState);
|
26 |
|
27 | signal nextState : state_t := idleState;
|
28 |
|
29 | signal bitCount : std_logic_vector(3 downto 0) := (others => '0');
|
30 | signal counter : std_logic_vector(3 downto 0) := (others => '0');
|
31 |
|
32 | signal nrOnes : std_logic_vector(3 downto 0) := (others => '0');
|
33 | signal load : std_logic := '0';
|
34 | signal input : std_logic_vector(7 downto 0) := (others => '0');
|
35 |
|
36 | signal s_tx_o : std_logic := '1';
|
37 | signal s_tmp : std_logic_vector(7 downto 0);
|
38 | constant counterEnd : std_logic_vector(4 downto 0) := "10000"; --16
|
39 |
|
40 | begin
|
41 |
|
42 | pr_state_update: process(clk_i, rst_i)
|
43 | begin
|
44 | if rising_edge(clk_i) and clk_i = '1' then
|
45 | if rst_i = '1' then
|
46 |
|
47 | nextState <= idleState;
|
48 |
|
49 | end if;
|
50 |
|
51 | case nextState is
|
52 | when idleState =>
|
53 |
|
54 | bitCount <= (others => '0');
|
55 | counter <= (others => '0');
|
56 | nrOnes <= (others => '0');
|
57 | s_tx_o <= '1';
|
58 | if load = '1' then
|
59 | input <= din_i;
|
60 | nextState <= startState;
|
61 | else
|
62 | nextState <= idleState;
|
63 | end if;
|
64 |
|
65 | when startState =>
|
66 | s_tx_o <= '0';
|
67 |
|
68 | if counter = (counterEnd-1) then
|
69 | counter <= (others => '0');
|
70 | nextState <= activeState;
|
71 | else
|
72 | counter <= counter + 1;
|
73 | nextState <= startState;
|
74 | end if;
|
75 |
|
76 | when activeState =>
|
77 | s_tx_o <= input(to_integer(unsigned(bitCount)));
|
78 |
|
79 | if counter = (counterEnd-1) then
|
80 | counter <= (others => '0');
|
81 | bitCount <= bitCount + 1;
|
82 |
|
83 | if input(to_integer(unsigned(bitCount))) = '1' then
|
84 | nrOnes <= nrOnes + 1;
|
85 | end if;
|
86 |
|
87 | if bitCount = "0111" then
|
88 | bitCount <= (others => '0');
|
89 |
|
90 | nextState <= parityState;
|
91 | else
|
92 | nextState <= activeState;
|
93 | end if;
|
94 | else
|
95 | counter <= counter + 1;
|
96 | nextState <= activeState;
|
97 | end if;
|
98 | when parityState =>
|
99 | counter <= (others => '0');
|
100 | if (nrOnes /= "0000") and (to_integer(unsigned(nrOnes)) mod 2 = 0) then
|
101 | s_tx_o <= '1';
|
102 | else
|
103 | s_tx_o <= '0';
|
104 | end if;
|
105 |
|
106 | if counter = (counterEnd-1) then
|
107 |
|
108 | nextState <= idleState;
|
109 | else
|
110 | counter <= counter + 1;
|
111 | nextState <= parityState;
|
112 | end if;
|
113 |
|
114 | when others =>
|
115 | nextState <= idleState;
|
116 | end case;
|
117 | end if;
|
118 | end process;
|
119 |
|
120 | load <= ld_i;
|
121 | tx_o <= s_tx_o;
|
122 | end Behavioral;
|
123 | ----------------------------UCF Datei:-------------------------------------
|
124 |
|
125 | net clk_i loc = a9 | CLOCK_DEDICATED_ROUTE = FALSE; # ohne diese Parameter bekkome ich eine Fehler bei der Syntheze.
|
126 | net tx_o loc = r7 | IOSTANDARD=LVTTL | DRIVE=24 | SLEW=SLOW;
|