Abstrak
Abstrak mempelajari penggunaan register, FSM, dan
komunikasi serial. Bahasa VHDL yang digunakan
menjurus pada implementasi sequential circuit, shift register, ,
UART serta clock divider. Praktikum dilakukan dengan
bantuan software quartus prime, Modelsim dan Altera
Cyclone untuk membantu pemahaman terhadap praktikum.
Setelah praktikum didapat hasil sesuai spesifikasi serta
ketentuan yang diinginkan.
Kata kunci: VHDL, sequential circuit, UART, clock
divider, Praktikum.
1. PENDAHULUAN
Percobaan pada praktikum ini terbagi menjadi 3 Gambar 2-1 Flowchart perancangan FPGA
sub-modul. Sub-modul pertama memberikan 2.2. BCD Decoder
pemahaman tentang register serta implementasi
pada FPGA dengan menampilkan NIM pada seven BCD Decoder merupakan sebuah rangkaian
segment secara bergantian. Sub-modul kedua logika yang digunakan untuk ’mentranslate’
memberikan pemahaman tentang perbedaan FSM kode biner menjadi bilangan desimal. BCD
jika dibuat menggunakan dua level abstraksi yang Decoder sendiri tergolong rangkaian logika
berbeda. Sub-modul ketiga memberikan yang kombinasional, berarti output yang
pemahaman mendasar tentang protokol dikeluarkan bergantung dengan input yang
komunikasi UART serta penerapannya pada FPGA dimasukkan(tidak ada penyimpanan
dengan laptop. sementara).
2. STUDI PUSTAKA
2.1. FPGA
Field Progammable Gate Array (FPGA)
merupakan sebuah IC digital yang digunakan
untuk mengimplementasikan rangkaian
digital. FPGA sendiri terdiri dari 2 komponen
utama yaitu programmable logic dan
interkoneksi (sambungan terprogram) .
Programmable logic biasanya meliputi jenis
gerbang logika biasa (AND, OR, NOT). FPGA
biasa digunakan untuk meningkatkan
efisiensi rancangan rangkaian dengan Gambar 2-2 BCD to 7-Segment Decoder
mengurangi pemakaian software. Secara
2.3. Delay Flip-Flop
umum alur dari FPGA sebagai berikut.
Delay flip-flop merupakan sebuah rangkaian
elektronik flip-flop(menyimpan sebuah data)
yang digunakan untuk menghambat
perubahan pernyataan keluaran sinyal dari
rangkaian sampai munculnya rising edge dari
sebuah periode clock masukan sinyal.
3. METODOLOGI
Alat dan komponen yang digunakan pada modul
ini adalah:
1. Komputer yang terinstal program Quartus
Prime Lite serta ModelSim Altera
2. FPGA board tipe Cyclone IV E serial
EP4CE6E22C8 lengkap dengan kabel
penyambung serta kabel supply power
Langkah pada praktikum modul 3 kali ini dapat
dilihat sebagai berikut.
Present Next
Input State State Output
X1 X0 A1 A0 B1 B0 Y
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 1 0 0 0 0
0 0 1 1 x x x
0 1 0 0 0 1 0
0 1 0 1 0 1 0
0 1 1 0 0 1 1 Gambar 4-4 Hasil implementasi alat FPGA
0 1 1 1 x x x Percobaan empat mengenalkan kita pada UART.
1 0 0 0 1 0 0 UART sendiri merupakan sebuah protocol
1 0 0 1 1 0 1 komunikasi serial sederhana. Dalam percobaan ini
1 0 1 0 1 0 0 UART diterapkan antara FPGA dengan laptop.
UART sendiri bekerja seperti walky-talky anak
1 0 1 1 1 0 x
kecil yaitu secara 2 arah dan tertutup.
1 1 0 0 0 0 0
1 1 0 1 0 0 0 Pada percobaan empat ini saya kesulitan untuk
membuat angka yang bagus terkadang
1 1 1 0 0 0 0 mengeluarkan suatu symbol random. Hal ini
1 1 1 1 x x x mungkin terjadi karena setting dari termite.
Tabel 4-2 K-Map
5. KESIMPULAN
input
00 01 11 10 Dari percobaan yang dilakukan dapat disimpulkan
next state
entity sevensegnim is
port (
std_clock : in std_logic;
reset : in std_logic;
digit : out std_logic_vector (3 downto 0);
seven_segment : out std_logic_vector (6 downto 0)
);
end sevensegnim;
begin
dig_3 <= "0001111";
dig_2 <= "0100100";
dig_1 <= "0000001";
dig_0 <= "0000001";
clockdivider : process(reset,std_clock)
begin
if(reset='0') then
clockdiv <= (others => '0');
elsif (rising_edge(std_clock)) then
clockdiv <= clockdiv+1;
end if;
end process clockdivider;
sekuential : process(clock_out,reset)
begin
if reset = '0' then
selector <= "0111";
elsif rising_edge(clock_out) then
selector(1) <= selector (0);
selector(2) <= selector (1);
selector(3) <= selector (2);
selektor : process(selector)
begin
digit <= selector;
case selector is
when "0111" => seven_segment <= dig_0;--0
when "1011" => seven_segment <= dig_1;--0
when "1101" => seven_segment <= dig_2;--5
when "1110" => seven_segment <= dig_3;--7
when others => seven_segment <= "1111111";--null
end case;
end process selektor;
end rtl;
entity fsm_gate is
port(
std_clock : in std_logic;
reset : in std_logic;
p : in std_logic_vector(1 downto 0);
q : out std_logic
);
end entity;
--logic next
next_state(0) <= (not(p(1)) and p(0));
next_state(1) <= (p(1) and not (p(0)));
--logic output
q <= ((next_state(1) and current_state(0)) or (next_state(0) and current_stat
e(1)));
• Variasi RTL
library ieee;
use ieee.std_logic_1164.all;
entity fsm_rtl is
port(
std_clock : in std_logic;
reset : in std_logic;
p : in std_logic_vector(1 downto 0);
q : out std_logic
);
end entity;
--logic next
process (current_state, p, y)
begin
next_state <= current_state;
case current_state is
when a =>
y <= '0';
if p = "01" then
next_state <= b;
elsif p = "10" then
next_state <= c;
else
next_state <= a;
end if;
when b =>
if p = "01" then
next_state <= b;
Laporan Praktikum - Laboratorium Dasar Teknik Elektro – STEI ITB 7
y <= '0';
elsif p = "10" then
next_state <= c;
y <= '1';
else
next_state <= a;
y <= '0';
end if;
when c =>
if p = "01" then
next_state <= b;
y <= '1';
elsif p = "10" then
next_state <= c;
y <= '0';
else
next_state <= a;
y <= '0';
end if;
end case;
end process;
--logic output
q <= y;
end rtl;
-- entity
entity ContohUART is
port(
clk : in std_logic;
rst_n : in std_logic;
-- paralel part
button : in std_logic;
Seven_Segment : out std_logic_vector(7 downto 0) ;
Digit_SS : out std_logic_vector(3 downto 0) ;
-- serial part
rs232_rx : in std_logic;
rs232_tx : out std_logic
);
End entity;
begin
UART: my_uart_top
port map (
clk => clk,
rst_n => rst_n,
send => button,
send_data => send_data,
receive => receive,
receive_data=> receive_data,
rs232_rx => rs232_rx,
rs232_tx => rs232_tx
);
Process(clk)
begin
if ((clk = '1') and clk'event) then
receive_c <= receive;
if ((receive = '0') and (receive_c = '1'))then
-- if (receive = '1') then
seven_segment <= receive_data;
end if;
end if;
end process;
end architecture;
-- entity
entity my_uart_rx is
port(
clk: in std_logic;
rst_n: in std_logic;
rs232_rx: in std_logic;
clk_bps: in std_logic;
bps_start: out std_logic;
rx_data: out std_logic_vector(7 downto 0);
rx_int : out std_logic
);
end entity my_uart_rx;
begin
----------------------------------------------------------------
process(clk, rst_n)
begin
if (rst_n = '0') then
-- begin
rs232_rx0 <= '0';
rs232_rx1 <= '0';
rs232_rx2 <= '0';
rs232_rx3 <= '0';
-- end;
elsif (clk='1' and clk'event) then
Laporan Praktikum - Laboratorium Dasar Teknik Elektro – STEI ITB 10
-- begin
rs232_rx0 <= rs232_rx;
rs232_rx1 <= rs232_rx0;
rs232_rx2 <= rs232_rx1;
rs232_rx3 <= rs232_rx2;
-- end;
end if;
end process;
neg_rs232_rx <= rs232_rx3 and rs232_rx2 and (not rs232_rx1) and (not rs232_rx
0);
process(clk, rst_n)
begin
if (rst_n = '0') then
rx_temp_data <= "00000000";
num <= "0000";
rx_data_r <= "00000000";
elsif (clk = '1' and clk'event) then
if (rx_int_i = '1') then
if(clk_bps = '1') then
num <= num + "0001";
case num is
when "0001" => rx_temp_data(0) <= rs232_rx; -
-//0bit
when "0010" => rx_temp_data(1) <= rs232_rx; -
-//1bit
when "0011" => rx_temp_data(2) <= rs232_rx; -
-//2bit
when "0100" => rx_temp_data(3) <= rs232_rx; -
-//3bit
end architecture;
-- library
-- library IEEE;
library IEEE;
use IEEE.std_logic_1164.all;
-- Entity
Entity my_uart_top is
port(
clk : in std_logic;
rst_n : in std_logic;
-- paralel part
send : in std_logic;
send_data : in std_logic_vector(7 downto 0) ;
receive : out std_logic;
receive_data: out std_logic_vector(7 downto 0) ;
-- serial part
rs232_rx : in std_logic;
rs232_tx : out std_logic
);
end entity;
component my_uart_tx is
port(
clk,rst_n : in std_logic;
tx_data : in std_logic_vector(7 downto 0);
tx_int : in std_logic;
rs232_tx : out std_logic;
clk_bps : in std_logic;
bps_start : out std_logic
);
end component;
component my_uart_rx is
port(
clk : in std_logic;
rst_n : in std_logic;
rs232_rx : in std_logic;
clk_bps : in std_logic;
bps_start: out std_logic;
rx_data : out std_logic_vector(7 downto 0);
rx_int : out std_logic
);
end component;
component speed_select is
port(
clk : in std_logic;
rst_n : in std_logic;
bps_start : in std_logic;
clk_bps : out std_logic
);
end component ;
begin
speed_rx : speed_select
port map (
clk => clk,
rst_n => rst_n,
bps_start => bps_start_rx,
clk_bps => clk_bps_rx
);
receiver : my_uart_rx
port map (
clk => clk,
rst_n => rst_n,
rs232_rx => rs232_rx,
rx_data => receive_data,
rx_int => receive,
clk_bps => clk_bps_rx,
bps_start => bps_start_rx
);
transmitter : my_uart_tx
port map (
clk => clk,
rst_n => rst_n,
tx_data => send_data,
tx_int => send,
rs232_tx => rs232_tx,
clk_bps => clk_bps_tx,
bps_start => bps_start_tx
);
end architecture;
-- Arif Sasongko
-- library
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
-- entity
entity my_uart_tx is
port(
clk,rst_n : in std_logic;
tx_data : in std_logic_vector(7 downto 0);
tx_int : in std_logic;
rs232_tx : out std_logic;
clk_bps: in std_logic;
bps_start : out std_logic
--architecture
begin
-
- The process below is to ensure 'neg_rx_int' react to negative edge of rx interr
upt
process (clk,rst_n)
begin
if rst_n = '0' then
tx_int0 <='0';
tx_int1 <='0';
tx_int2 <='0';
elsif (clk = '1' and clk'event) then
tx_int0 <= tx_int;
tx_int1 <= tx_int0;
tx_int2 <= tx_int1;
end if;
end process;
-- The process below send the data through the rs232_tx_r when tx_en is '1':
-- --> take data from input (freeze the data)
-- --> generate bps_start_r signal
-- --> enable transmit signal (tx_en)
process(clk, rst_n)
begin
if (rst_n = '0') then
num <= "0000";
rs232_tx_r <= '1';
elsif (clk = '1' and clk'event) then
if(tx_en = '1') then
if(clk_bps = '1') then
num <= num + "0001";
case num is
when "0000" => rs232_tx_r <= '0' ;
when "0001" => rs232_tx_r <= tx_data_i(0);
when "0010" => rs232_tx_r <= tx_data_i(1);
when "0011" => rs232_tx_r <= tx_data_i(2);
when "0100" => rs232_tx_r <= tx_data_i(3);
when "0101" => rs232_tx_r <= tx_data_i(4);
when "0110" => rs232_tx_r <= tx_data_i(5);
when "0111" => rs232_tx_r <= tx_data_i(6);
when "1000" => rs232_tx_r <= tx_data_i(7);
when "1001" => rs232_tx_r <= '1';
when others => rs232_tx_r <= '1';
end case;
elsif(num= "1011") then
num <= "0000";
end if;
end if;
end if;
end process;
end architecture;
-- Library
-- entity
entity speed_select is
port(
clk : std_logic;
rst_n : std_logic;
bps_start : std_logic;
clk_bps : out std_logic
);
end entity;
--/*
--parameter bps9600 = 5207, //Ϊ9600bps
-- bps19200 = 2603, //Ϊ19200bps
-- bps38400 = 1301, //Ϊ38400bps
-- bps57600 = 867, //Ϊ57600bps
-- bps115200 = 433; //Ϊ115200bps
process(clk, rst_n)
begin
if (rst_n = '0') then cnt <= 0;
elsif (clk='1' and clk'event) then
if ((cnt = BPS_PARA) or (bps_start = '0')) then cnt <= 0; -- end if;
else cnt <= cnt + 1;
end if;
end if;
end process;
process(clk, rst_n)
begin
if (rst_n = '0') then clk_bps_r <= '0';
elsif (clk='1' and clk'event) then
Laporan Praktikum - Laboratorium Dasar Teknik Elektro – STEI ITB 17
if((cnt = BPS_PARA_2) and (bps_start='1')) then clk_bps_r <= '1';
else clk_bps_r <= '0';
end if;
end if;
end process;
end architecture;