Professional Documents
Culture Documents
BI TP CHUYN (KTT)
ti: Thit k b truyn nhn UART
GVHD: Hunh Vit Thng
SVTH: L c Nhn
Lp: 11DT3
Vn Minh
Lp: 11DT2
H Vit Thnh
Lp: 11DT3
Nhm: 7
Trong :
Idle
Idle
tx_enable=1
tx_count=1001
and tx_clken
Load_tx
s
Shift_data
Trong :
reset: tn hiu reset h thng.
uart_en: tn hiu cho php h thng lm vic.
tx_enable: tn hiu cho php b truyn lm vic.
tx_count: tn hiu m s bit c truyn i.
tx_clken: xung cho php dch tng bit d liu khi b truyn hot ng.
iu kin
Idle
Load_txs
Load_txs
Shift_data
Shift_data
d liu
rx_count=1010
uart_rx_sync=1
and samp_count=0111
Check_start_
Receive_dat
bit
a
uart_rx_sync=0 and samp_count=0111
Hnh 5: My trng thi hu hn ca b nhn
-
Trong :
Reset: tn hiu reset h thng.
Uart_en: tn hiu cho php h thng lm vic.
Uart_rx_sync: tn hiu ly mu c c.
Samp_count: tn hiu m s ln ly mu trong tng xung vo.
Rx_count: tn hiu m xung vo.
M t
iu kin
Idle
uart_rx_sync=0
Check_start_bit
ng
Check_start_bit
Trng thi ly mu v
kim tra bit start
samp_count=0111
v uart_rx_sync=1
samp_count=0111
Idle
Receive_data
v uart_rx_sync=0
Receive_data
Trng thi ly mu cc
bit d liu trn ng
nhn
rx_count=1010
Idle
Khi BAUD_RATE
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
--use UNISIM.VComponents.all;
entity baud_rate is
port (
clk : in std_logic;
);
end baud_rate;
begin
process(clk)
-- tao xung dich du lieu o bo phat
begin
if rising_edge(clk) then
if ((reset='0') or (tx_clken_temp='1') or (uart_en='0'))
then
process(clk)
-- tao xung lay mau du lieu o bo nhan
begin
if rising_edge(clk) then
if ((reset='0') or (rx_clken_temp='1') or (uart_en='0'))
then
rx_count <= (others => '0');
else
rx_count <= (rx_count + 1);
end if;
end if;
end process;
Khi CONTROL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
--use UNISIM.VComponents.all;
entity control is
port(
clk : in std_logic;
-- gia tri
-- gia tri
dong
end control;
Khi UART_TRANSMITTER
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.NUMERIC_STD.ALL;
entity uart_transmitter is
port (
clk : in std_logic;
hoat dong
tx_clken : in std_logic;
du lieu khi bo truyen hoat dong
uart_tx : out std_logic
bo
);
end uart_transmitter;
load_txs;
end if;
when load_txs =>
state <= shift_data;
when shift_data =>
if ((tx_count="1001") and (tx_clken='1'))
then -- dem den 10 vi khung truyen co 10 bit du lieu
state <= idle;
end if;
when others =>
state <= idle;
end case;
end if;
1
end if;
end process;
-- dau ra may trang thai huu han
process(clk)
begin
if rising_edge(clk) then
if ((reset='0') or (uart_en='0')) then
tsr <= "0000000000";
uart_tx <= '1';
tx_count <= "0000";
else
case state is
when idle =>
tsr <= "0000000000";
uart_tx <= '1';
tx_count <= "0000";
when load_txs =>
tsr <= ('1' & data_in & '0');
bit 0 la bit start, bit 1 la bit stop vao khung truyen
-- gan
-- gan du lieu
--
dich du lieu
tx_count <= tx_count + 1;
-- bo
dem truyen
end if;
when others =>
Khi UART_RECEIVER
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity uart_receiver is
port (
clk : in std_logic;
rx_clken : in std_logic;
tri lay mau du lieu o bo nhan
uart_rx : in std_logic;
nhan duoc
end uart_receiver;
-- tin hieu
-- lay
-- dem den
"11111111";
--
if (rx_clken='1') then
samp_count <= samp_count + 1;
if (samp_count="0111") then
rx_count <= rx_count + 1;
if(rx_count<"1001") then
-chi dem den xung thu 9, loai bo bit start va stop ra du lieu nhan
duoc
rsr <= (uart_rx_sync &
rsr(7 downto 1));
-- dich du lieu
end if;
end if;
end if;
when others =>
rx_count <= "0000";
samp_count <= "0000";
end case;
end if;
end if;
end process;
rev_data <= rsr;
end Behavioral;
ENTITY test_uart IS
END test_uart;
COMPONENT full_uart
PORT(
clk : IN
std_logic;
reset : IN
std_logic;
uart_en : IN
Tich cuc muc cao
std_logic;
data_in : IN
lieu ngo vao
tx_in : IN std_logic;
vao bo truyen. Tich cuc muc cao
uart_rx : IN
std_logic;
-- gia tri
-- gia tri
uart_tx : OUT
std_logic
bo
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal reset : std_logic := '0';
signal uart_en : std_logic := '0';
signal data_in : std_logic_vector(7 downto 0) := (others => '0');
signal tx_in : std_logic := '0';
signal uart_rx : std_logic := '0';
--Outputs
signal led_0 : std_logic_vector(3 downto 0);
signal led_1 : std_logic_vector(3 downto 0);
signal uart_tx : std_logic;
clock: process
-- tao xung tan so 50 MHz
begin
clk <= '1';
wait for 10 ns;
clk <= '0';
wait for 10 ns;
end process;
-- Stimulus process
stim_proc1: process
begin
reset <= '0';
wait for 20 ps;
-- tao du lieu vao
tx_in <= '1';
3.3. Kt qu m phng:
Hnh 6: thi im uart_tx nhn gi tr bit start v ghi vo trong bit MSB ca led_1
Hnh 7: thi im uart_tx nhn gi tr bit LSB ca data_in v tip tc ghi vo led_1