วันอาทิตย์ที่ 5 เมษายน พ.ศ. 2558

การทดลองที่ 4

การทดลองที่ 4
สร้างวงจรดิจิทัลเพื่ออ่านค่าจาก 4x4 keypad แล้วแสดงผลด้วย LEDs

จุดประสงค์
1.เพื่อให้เข้าใจหลักการทำงานของ 4x4 Keypad และสามารถนำมาสร้างเป็นวงจรได้
2.เพื่อให้เข้าใจฟังก์ชั่นการทำงานของ FPGA ขึ้น
3.เพื่อสามารถนำความรุ็ที่ได้จากการทดลองนี้มาประยุกต์ใช้กับวงจรอื่นๆได้อย่างเหมาะสม

โจทย์คำสั่ง
เขียน VHDL ที่ใช้ควบคุมการอ่านค่าจาก 4x4 Keypad เพื่อมาแสดงผลที่ LED ทั้ง 8 ดวง บน FPGA โดยที่แสดงผลเป็นเลขฐานสองของค่าเลขฐานสิบที่อ่านได้จากปุ่มกดแต่ละปุ่ม

อุปกรณ์
1.บอร์ด FPGA CYCLOne 3 ชิปหมายเลข EP3C10E144C8 1 บอร์ด


2. ออสซิโลสโคป 1 เครื่อง

3. สายไฟ

4. คอมพิวเตอร์ที่มีโปรแกรม Altera 10.1d (Quartus II 13.1)

5. 4x4 keypad 1 อัน
















โค้ด
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;

entity Botton is
port( PB_colum : in std_logic_vector (3 downto 0);
PB : out std_logic_vector (3 downto 0);
clk : in std_logic;
Response_LED:out std_logic_vector (7 downto 0);
Buzzer : out std_logic :='0');
end Botton;

architecture bahavioral of Botton is 
type state is (s0,s1,s2,s3);
signal stateCheck : state :=s0;
signal time_check : integer := 0;

begin 
process(clk,PB_colum)
begin

if rising_edge (clk) then
time_check <= time_check + 1;
if ((time_check > 20000) and (time_check < 30000)) then
stateCheck <= s0;
elsif ((time_check > 30000) and (time_check < 40000)) then
stateCheck <= s1;
elsif ((time_check > 40000) and (time_check < 50000)) then
stateCheck <= s2;
elsif ((time_check > 50000) and (time_check < 60000)) then
stateCheck <= s3;
time_check <= 0;
end if;

case stateCheck is
when s0 =>
PB <= "0111";
for i in 0 to 3 loop
if PB_colum(i) = '0' then
if i = 0 then
response_LED <= "00000001"; --1
Buzzer <= '1';
end if;
if i = 1 then
response_LED <= "00000101"; --5
Buzzer <= '1';
end if;
if i = 2 then
response_LED <= "00001001"; --9
Buzzer <= '1';
end if;
if i = 3 then
response_LED <= "00001101";  --13
Buzzer <= '1';
end if;
end if;
end loop;

when s1 =>
PB <= "1011";
for i in 0 to 3 loop
if PB_colum(i) = '0' then
if i = 0 then
response_LED <= "00000010"; --2
Buzzer <= '1';
end if;
if i = 1 then
response_LED <= "00000110"; --6
Buzzer <= '1';
end if;
if i = 2 then
response_LED <= "00001010"; --10
Buzzer <= '1';
end if;
if i = 3 then
response_LED <= "00001110";  --14
Buzzer <= '1';
end if;
end if;
end loop;

when s2 =>
PB <= "1101";
for i in 0 to 3 loop
if PB_colum(i) = '0' then
if i = 0 then
response_LED <= "00000011"; --3
Buzzer <= '1';
end if;
if i = 1 then
response_LED <= "00000111"; --7
Buzzer <= '1';
end if;
if i = 2 then
response_LED <= "00001011"; --11
Buzzer <= '1';
end if;
if i = 3 then
response_LED <= "00001111";  --15
Buzzer <= '1';
end if;
end if;
end loop;

when s3 =>
PB <= "1110";
for i in 0 to 3 loop
if PB_colum(i) = '0' then
if i = 0 then
response_LED <= "00000100"; --4
Buzzer <= '1';
end if;
if i = 1 then
response_LED <= "00001000"; --8
Buzzer <= '1';
end if;
if i = 2 then
response_LED <= "00001100"; --12
Buzzer <= '1';
end if;
if i = 3 then
response_LED <= "00010000";  --16
Buzzer <= '1';
end if;
end if;
end loop;
Buzzer <= '0';
end case;
end if;
end process;

end bahavioral;

ผลการจำลองการทำงานด้วยโปรแกรม Model Sim

ภาพการทดลอง



ภาพการต่อวงจร
 วิดีโอการทดลอง




ไม่มีความคิดเห็น:

แสดงความคิดเห็น