source: firmware/FTU/rs485/FTU_rs485_interface.vhd@ 18459

Last change on this file since 18459 was 10238, checked in by weitzel, 14 years ago
change in FTU rs485 module; FTUs answer now one BAUD period later
File size: 3.7 KB
Line 
1--
2-- VHDL Architecture FACT_FAD_lib.rs485_interface.beha
3--
4-- Created:
5-- by - Benjamin Krumm.UNKNOWN (EEPC8)
6-- at - 13:24:23 08.06.2010
7--
8-- using Mentor Graphics HDL Designer(TM) 2009.1 (Build 12)
9--
10--
11-- modified for FTU design by Q. Weitzel, 30 July 2010
12--
13
14LIBRARY ieee;
15USE ieee.std_logic_1164.all;
16USE ieee.std_logic_arith.all;
17
18library ftu_definitions;
19USE ftu_definitions.ftu_array_types.all;
20USE ftu_definitions.ftu_constants.all;
21
22ENTITY FTU_rs485_interface IS
23 GENERIC(
24 CLOCK_FREQUENCY : integer := INT_CLK_FREQUENCY;
25 BAUD_RATE : integer := RS485_BAUD_RATE
26 );
27 PORT(
28 clk : IN std_logic;
29 -- RS485
30 rx_d : IN std_logic;
31 rx_en : OUT std_logic;
32 tx_d : OUT std_logic;
33 tx_en : OUT std_logic;
34 -- FPGA
35 rx_data : OUT std_logic_vector (7 DOWNTO 0);
36 rx_busy : OUT std_logic := '0';
37 rx_valid : OUT std_logic := '0';
38 tx_data : IN std_logic_vector (7 DOWNTO 0);
39 tx_busy : OUT std_logic := '0';
40 tx_start : IN std_logic
41 );
42
43END FTU_rs485_interface;
44
45ARCHITECTURE beha OF FTU_rs485_interface IS
46
47 signal flow_ctrl : std_logic := '0'; -- '0' -> RX enable, '1' -> TX enable
48
49 --transmit
50 signal tx_start_f : std_logic := '0';
51 signal tx_sr : std_logic_vector(10 downto 0) := (others => '1'); -- start bit, 8 data bits, 2 stop bits
52 signal tx_bitcnt : integer range 0 to 11 := 11;
53 signal tx_cnt : integer range 0 to ((CLOCK_FREQUENCY / BAUD_RATE) - 1);
54
55 --receive
56 signal rx_dsr : std_logic_vector(3 downto 0) := (others => '1');
57 signal rx_sr : std_logic_vector(7 downto 0) := (others => '0');
58 signal rx_bitcnt : integer range 0 to 11 := 11;
59 signal rx_cnt : integer range 0 to ((CLOCK_FREQUENCY / BAUD_RATE) - 1);
60
61BEGIN
62
63 -- Senden
64 tx_data_proc: process(clk)
65 begin
66 if rising_edge(clk) then
67 tx_start_f <= tx_start;
68 if (tx_start = '1' or tx_bitcnt < 11) then
69 flow_ctrl <= '1';
70 else
71 flow_ctrl <= '0';
72 end if;
73 if (tx_start = '1' and tx_start_f = '0') then -- steigende Flanke, los gehts
74 tx_cnt <= 0; -- Zaehler initialisieren
75 tx_bitcnt <= 0;
76 tx_sr <= "11" & tx_data & '0'; -- 2 x Stopbit, 8 Datenbits, Startbit, rechts gehts los
77 else
78 if (tx_cnt < (CLOCK_FREQUENCY/BAUD_RATE) - 1) then
79 tx_cnt <= tx_cnt + 1;
80 else -- naechstes Bit ausgeben
81 if (tx_bitcnt < 11) then
82 tx_cnt <= 0;
83 tx_bitcnt <= tx_bitcnt + 1;
84 tx_sr <= '1' & tx_sr(tx_sr'left downto 1);
85 end if;
86 end if;
87 end if;
88 end if;
89 end process;
90
91 tx_en <= flow_ctrl;
92 tx_d <= tx_sr(0); -- LSB first
93 tx_busy <= '1' when (tx_start = '1' or tx_bitcnt < 11) else '0';
94
95 -- Empfangen
96 rx_data_proc: process(clk)
97 begin
98 if rising_edge(clk) then
99 rx_dsr <= rx_dsr(rx_dsr'left - 1 downto 0) & rx_d;
100 if (rx_bitcnt < 11) then -- Empfang laeuft
101 if (rx_cnt < (CLOCK_FREQUENCY/BAUD_RATE) - 1) then
102 rx_cnt <= rx_cnt + 1;
103 else
104 rx_cnt <= 0;
105 rx_bitcnt <= rx_bitcnt + 1;
106 if (rx_bitcnt < 9) then
107 rx_sr <= rx_dsr(rx_dsr'left - 1) & rx_sr(rx_sr'left downto 1); -- rechts schieben, weil LSB first
108 else
109 rx_valid <= '1';
110 end if;
111 end if;
112 else
113 if (rx_dsr(3 downto 2) = "10") then -- warten auf Start bit
114 rx_valid <= '0';
115 rx_cnt <= ((CLOCK_FREQUENCY / BAUD_RATE) - 1) / 2;
116 rx_bitcnt <= 0;
117 end if;
118 end if;
119 end if;
120 end process;
121
122 rx_en <= flow_ctrl;
123 rx_data <= rx_sr;
124 rx_busy <= '1' when (rx_bitcnt < 11) else '0';
125
126END ARCHITECTURE beha;
Note: See TracBrowser for help on using the repository browser.