การเขียน VHDL นำไปสร้างวงจรในชิป FPGA
วัตถุประสงค์
1.ศึกษาการทำงานของบอร์ด FPGA
2.สามารถออกแบบการทำงานของวงจรดิจิทัลได้
3. สายไฟ
4. คอมพิวเตอร์ที่มีโปรแกรม QuartUS
ข้อกำหนดในการทดลอง
จงออกแบบวงจรดิจิลัทโดยใช้ภาษา VHDL สำหรับนำไปสร้างเป็นวงจรในชิป FPGA โดยใช้บอร์ดที่มีอยู่ในห้องแล็ป
2.1) วงจรดิจิทัลมี I/O ดังนี้
- CLK (input) มีความถี่ 50MHz ใช้สำหรับกำหนดจังหวะการทำงานของวงจรทั้งหมด (เป็นการออกแบบวงจรดิจิทัลแบบ Synchronous Design)- RST_B (input) เป็นอินพุตสำหรับใช้รีเซตแบบ Asynchronous สำหรับการทำงานของวงจรโดยรวม (ทำงานแบบ Active-Low) ซึ่งได้จากวงจรปุ่มกด (Push Button)- PB (input) เป็นอินพุตจากปุ่มกด 1 ปุ่ม ทำงานแบบ Active-low เพื่อใช้ในการเปลี่ยนสีของ WS2812 RGB LED จำนวน 1 ดวง
- DATA (output) เป็นเอาต์พุตสำหรับนำไปควบคุมการทำงานของ WS2812 RGB LED เพียง 1 ดวง ซึ่งเป็นสัญญาณตามข้อกำหนดของชิป WS2812 เพื่อส่งข้อมูลจำนวน 24 บิต- DATA (output) เป็นเอาต์พุตสำหรับนำไปควบคุมการทำงานของ WS2812 RGB LED เพียง 1 ดวง ซึ่งเป็นสัญญาณตามข้อกำหนดของชิป WS2812 เพื่อส่งข้อมูลจำนวน 24 บิต
2.2) พฤติกรรมการทำงานเป็นดังนี้
- เมื่อเริ่มต้นหรือกดปุ่มรีเซต (RST_B) จะทำให้ค่าสีเป็น 0x000000 (24 บิต) และส่งออกไปยัง WS2812 RGB LED หนึ่งครั้ง
- เมื่อมีการกดปุ่ม PB แล้วปล่อยในแต่ละครั้ง จะมีการเปลี่ยนค่าสี 24 บิต แล้วส่งออกไปยัง RGB LED ใหม่หนึ่งครั้ง ตามลำดับดังนี้
0x000000 -> 0x0000FF -> 0x00FF00 -> 0xFF0000 แล้ววนซ้ำ
2.3) แนวทางการออกแบบและทดสอบ
- ออกแบบวงจรโดยใช้ภาษา VHDL
- เขียน VHDL Testbench เพื่อทดสอบการทำงาน และจำลองการทำงาน
- ทดสอบการทำงานในบอร์ด FPGA แล้ววัดสัญญาณโดยใช้ออสซิลโลสโคป
(ยังไม่ต้องต่อวงจร RGB LED จริง)
- บันทึกผลและเขียนรายงานการทดลอง
แนวทางการออกแบบ
ใช้การออกแบบวงจรแบบ state ดังนี้
Code VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.numeric_std.all;
entity labb2 is
port(clk,RST_B:in std_logic ;
PB : in std_logic;
Data: out std_logic
);
end labb2;
architecture behavioral of labb2 is
type state is(s0,s1,s2,s3);
signal statecheck :state := s0 ;
signal count_freq, count_botton, i,count_pwm: integer:=0;
signal duty : std_logic_vector(23 downto 0) := x"000000";
signal cheak : std_logic;
signal pwm : std_logic;
begin
process(clk, RST_B)
begin
if(RST_B='0')then --set to reset Asynchronus
statecheck <= s0;
i <= 0;
duty <= x"000000";
elsif rising_edge(clk)then
count_pwm<=count_pwm+1;
if (PB = '0')then --botton delay
count_botton <= count_botton+1;
elsif(PB ='1')then
if(count_botton > 100000)then --delay
count_botton <=0;
if duty = x"FF0000" then
duty <=x"000000";
elsif duty = x"000000" then
duty <=x"0000FF";
elsif duty = x"0000FF" then
duty <=x"00FF00";
elsif duty = x"00FF00" then
duty<=x"FF0000";
end if;
end if;
end if;
--check state
case statecheck is
when s0 => --check data
if i=24 then
statecheck <= s3;
else
if duty(i)='0' then -- logic '1'
statecheck <=s1;
else -- logic '0'
statecheck <=s2;
end if;
end if;
when s1 => -- output 40 + 18
if (count_pwm < 58) then
--count_pwm <= count_pwm + 1;
Data<='1';
if(count_pwm >18)then
Data <= '0';
end if;
count_pwm <= count_pwm + 1;
else
i <= i+1;
count_pwm <= 0;
statecheck <= s0;
end if ;
when s2 => --output 30+35
if (count_pwm < 65)then
Data <= '0';
if(count_pwm > 35)then
Data<='1';
end if ;
else
i <= i+1;
count_pwm <=0;
statecheck <= s0;
end if;
when s3 =>
if(count_pwm > 10000)then
statecheck <= s0;
count_pwm <= 0;
i<= 0;
else
count_pwm <= count_pwm+1;
Data <= '0';
end if;
end case;
end if;
end process;
end behavioral;
ผลการทดสอบโปรแกรมจากโปรแกรม model-sim
รูปคลื่นจากออสซิโลสโคป
กดปุ่มครั้งแรก (0x000000)
กดปุ่มครั้งที่สอง (0x0000FF)
กดปุ่มครั้งที่สาม (0x00FF00)
กดปุ่มครั้งที่สี่ (0xFF0000)
ข้อกำหนดในการทดลอง
จงออกแบบวงจรดิจิลัทโดยใช้ภาษา VHDL สำหรับนำไปสร้างเป็นวงจรในชิป FPGA โดยใช้บอร์ดที่มีอยู่ในห้องแล็ป
2.1) วงจรดิจิทัลมี I/O ดังนี้
- CLK (input) มีความถี่ 50MHz ใช้สำหรับกำหนดจังหวะการทำงานของวงจรทั้งหมด (เป็นการออกแบบวงจรดิจิทัลแบบ Synchronous Design)- RST_B (input) เป็นอินพุตสำหรับใช้รีเซตแบบ Asynchronous สำหรับการทำงานของวงจรโดยรวม (ทำงานแบบ Active-Low) ซึ่งได้จากวงจรปุ่มกด (Push Button)- PB (input) เป็นอินพุตจากปุ่มกด 1 ปุ่ม ทำงานแบบ Active-low เพื่อใช้ในการเปลี่ยนสีของ WS2812 RGB LED จำนวน 1 ดวง
- DATA (output) เป็นเอาต์พุตสำหรับนำไปควบคุมการทำงานของ WS2812 RGB LED เพียง 1 ดวง ซึ่งเป็นสัญญาณตามข้อกำหนดของชิป WS2812 เพื่อส่งข้อมูลจำนวน 24 บิต- DATA (output) เป็นเอาต์พุตสำหรับนำไปควบคุมการทำงานของ WS2812 RGB LED เพียง 1 ดวง ซึ่งเป็นสัญญาณตามข้อกำหนดของชิป WS2812 เพื่อส่งข้อมูลจำนวน 24 บิต
- CLK (input) มีความถี่ 50MHz ใช้สำหรับกำหนดจังหวะการทำงานของวงจรทั้งหมด (เป็นการออกแบบวงจรดิจิทัลแบบ Synchronous Design)- RST_B (input) เป็นอินพุตสำหรับใช้รีเซตแบบ Asynchronous สำหรับการทำงานของวงจรโดยรวม (ทำงานแบบ Active-Low) ซึ่งได้จากวงจรปุ่มกด (Push Button)- PB (input) เป็นอินพุตจากปุ่มกด 1 ปุ่ม ทำงานแบบ Active-low เพื่อใช้ในการเปลี่ยนสีของ WS2812 RGB LED จำนวน 1 ดวง
- DATA (output) เป็นเอาต์พุตสำหรับนำไปควบคุมการทำงานของ WS2812 RGB LED เพียง 1 ดวง ซึ่งเป็นสัญญาณตามข้อกำหนดของชิป WS2812 เพื่อส่งข้อมูลจำนวน 24 บิต- DATA (output) เป็นเอาต์พุตสำหรับนำไปควบคุมการทำงานของ WS2812 RGB LED เพียง 1 ดวง ซึ่งเป็นสัญญาณตามข้อกำหนดของชิป WS2812 เพื่อส่งข้อมูลจำนวน 24 บิต
2.2) พฤติกรรมการทำงานเป็นดังนี้
- เมื่อเริ่มต้นหรือกดปุ่มรีเซต (RST_B) จะทำให้ค่าสีเป็น 0x000000 (24 บิต) และส่งออกไปยัง WS2812 RGB LED หนึ่งครั้ง
- เมื่อมีการกดปุ่ม PB แล้วปล่อยในแต่ละครั้ง จะมีการเปลี่ยนค่าสี 24 บิต แล้วส่งออกไปยัง RGB LED ใหม่หนึ่งครั้ง ตามลำดับดังนี้
0x000000 -> 0x0000FF -> 0x00FF00 -> 0xFF0000 แล้ววนซ้ำ
- เมื่อมีการกดปุ่ม PB แล้วปล่อยในแต่ละครั้ง จะมีการเปลี่ยนค่าสี 24 บิต แล้วส่งออกไปยัง RGB LED ใหม่หนึ่งครั้ง ตามลำดับดังนี้
0x000000 -> 0x0000FF -> 0x00FF00 -> 0xFF0000 แล้ววนซ้ำ
2.3) แนวทางการออกแบบและทดสอบ
- ออกแบบวงจรโดยใช้ภาษา VHDL
- เขียน VHDL Testbench เพื่อทดสอบการทำงาน และจำลองการทำงาน
- เขียน VHDL Testbench เพื่อทดสอบการทำงาน และจำลองการทำงาน
- ทดสอบการทำงานในบอร์ด FPGA แล้ววัดสัญญาณโดยใช้ออสซิลโลสโคป
(ยังไม่ต้องต่อวงจร RGB LED จริง)
- บันทึกผลและเขียนรายงานการทดลอง
แนวทางการออกแบบ
ใช้การออกแบบวงจรแบบ state ดังนี้
Code VHDL
library ieee;use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.numeric_std.all;
entity labb2 is
port(clk,RST_B:in std_logic ;
PB : in std_logic;
Data: out std_logic
);
end labb2;
architecture behavioral of labb2 is
type state is(s0,s1,s2,s3);
signal statecheck :state := s0 ;
signal count_freq, count_botton, i,count_pwm: integer:=0;
signal duty : std_logic_vector(23 downto 0) := x"000000";
signal cheak : std_logic;
signal pwm : std_logic;
begin
process(clk, RST_B)
begin
if(RST_B='0')then --set to reset Asynchronus
statecheck <= s0;
i <= 0;
duty <= x"000000";
elsif rising_edge(clk)then
count_pwm<=count_pwm+1;
if (PB = '0')then --botton delay
count_botton <= count_botton+1;
elsif(PB ='1')then
if(count_botton > 100000)then --delay
count_botton <=0;
if duty = x"FF0000" then
duty <=x"000000";
elsif duty = x"000000" then
duty <=x"0000FF";
elsif duty = x"0000FF" then
duty <=x"00FF00";
elsif duty = x"00FF00" then
duty<=x"FF0000";
end if;
end if;
end if;
--check state
case statecheck is
when s0 => --check data
if i=24 then
statecheck <= s3;
else
if duty(i)='0' then -- logic '1'
statecheck <=s1;
else -- logic '0'
statecheck <=s2;
end if;
end if;
when s1 => -- output 40 + 18
if (count_pwm < 58) then
--count_pwm <= count_pwm + 1;
Data<='1';
if(count_pwm >18)then
Data <= '0';
end if;
count_pwm <= count_pwm + 1;
else
i <= i+1;
count_pwm <= 0;
statecheck <= s0;
end if ;
when s2 => --output 30+35
if (count_pwm < 65)then
Data <= '0';
if(count_pwm > 35)then
Data<='1';
end if ;
else
i <= i+1;
count_pwm <=0;
statecheck <= s0;
end if;
when s3 =>
if(count_pwm > 10000)then
statecheck <= s0;
count_pwm <= 0;
i<= 0;
else
count_pwm <= count_pwm+1;
Data <= '0';
end if;
end case;
end if;
end process;
end behavioral;
ผลการทดสอบโปรแกรมจากโปรแกรม model-sim
รูปคลื่นจากออสซิโลสโคป
กดปุ่มครั้งแรก (0x000000)
กดปุ่มครั้งที่สอง (0x0000FF)
กดปุ่มครั้งที่สาม (0x00FF00)
กดปุ่มครั้งที่สี่ (0xFF0000)





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