วันเสาร์ที่ 16 พฤษภาคม พ.ศ. 2558

LAB 3 component

LAB 3 component

อุปกรณ์

1. บอร์ด xilinx                                                                                                                             บอร์ด
2. สายดาวน์โหลด ByteBlaster II Cable หรือ สายดาวน์โหลดUSB Blaster Cable                ชุด
3. เครื่องคอมพิวเตอร์(Quatus II web edition)                                                                           1ชุด
4. ออสซิลโลสโคป                                                                                                                       1เครื่อง
5. WS2812 RGB LED                                                                                                               1ดวง


code


ส่วน comp

library ieee,work;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity comp is
port(
CLK ,PB ,RST_B  : in std_logic;
data : out std_logic
);
end comp ;

architecture behave of comp is
signal out0 :std_logic;
   signal out1 : std_logic_vector(0 to 23);
component push
port( CLK ,PB  : in std_logic;
OUTPB : out std_logic
 );
end component;

component state
port( CLK ,checkPB ,RST_B  : in std_logic;
OUTREG : out std_logic_vector(0 to 23)
 );
end component;
component outState
port( CLK : in std_logic;
     REGin : std_logic_vector(0 to 23);
  data : out std_logic 
 );
end component;
begin
   U0:push port map(CLK,PB, out0);
   U1:state port map(CLK ,out0 ,RST_B, out1 );
U2:outState port map(CLK, out1 ,data);
end behave;


    
ส่วน push

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity push is
port(
CLK ,PB   : in std_logic;
OUTPB : out std_logic
);
end push ;

architecture behave of push is
   signal Index ,countIndex,countGab : integer := 0;
signal SETPB,check : std_logic;
signal REG : std_logic_vector(23 downto 0) := x"000000";

begin

process(CLK,PB) begin



if rising_edge(CLK) then

     SETPB <= '0';
 
 if PB = '0' then
    check <= '1';
 else
    if PB = '1' and check = '1' then
      
 
   SETPB <= '1';
 
 end if;
 check <= '0';
end if;


end if;
end process;
    OUTPB <= SETPB ; 
end behave;
ส่วน state


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity state is
port(
CLK ,checkPB ,RST_B: in std_logic;
OUTREG : out std_logic_vector(23 downto 0) := x"000000"
);
end state ;

architecture behave of state is
   signal Index ,countIndex,countGab : integer := 0;
signal check, outPWM : std_logic;
signal REG : std_logic_vector(23 downto 0) := x"000000";

begin

process(CLK,RST_B) begin

if RST_B = '0' then
REG <= x"000000";
index <= 0;
check <= '0';
countIndex <= 0;

elsif rising_edge(CLK) then
 
 if checkPB = '1' then
      
if REG = x"000000" then
   REG <= x"0000FF";
elsif REG = x"0000FF" then
   REG <= x"00FF00";
elsif REG = x"00FF00" then
   REG <= x"FF0000";
elsif REG = x"FF0000" then
   REG <= x"000000";
 end if;
end if;


end if;
end process;
    OUTREG <= REG ; 
end behave;

ส่วน outState


 library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity outState is
port(
CLK : in std_logic;
REGin : in std_logic_vector(23 downto 0) := x"000000";
data : out std_logic
);
end outState ;

architecture behave of outState is
    signal Index ,countIndex,countGab : integer := 0;
signal check, outPWM : std_logic;
constant T0H : integer := 18;
constant T0L : integer := 57; 
constant T1H : integer := 35; 
constant T1L : integer := 65;
type state_type is (S0,S1,S2);
   signal state : state_type := S0;

begin

process(CLK) begin
 case state is
 when S0 => 
 
 if Index = 24 then
 if countGab < 1000 then
 countGab <= countGab + 1;
 
 else
 countIndex <= 0;
 Index <= 0;
 countGab <= 0;
 end if;
 data <= '0';
 
 else
  
if REGin(Index) = '0' then
state <= S1;
else
state <= S2;
end if;
--Index <= Index +1 ;
 
 end if;
 
 when S1 =>
 if countIndex <= T0H then
data <= '1';
countIndex <= countIndex + 1;
 elsif countIndex > T0H and countIndex <= T0L then
data <= '0';
countIndex <= countIndex+1;
 elsif countIndex > T0L then
Index <= Index + 1;
countIndex <= 0;
 end if;
 
 state <= S0;
 
 when S2 =>
if countIndex <= T1H then
     data <= '1';
countIndex <= countIndex + 1;
 elsif countIndex > T1H and countIndex <= T1L then
     data <= '0';
countIndex <= countIndex + 1;
 elsif countIndex > T1L then
     Index <= Index + 1;
          countIndex <= 0;
 end if; 
 
 state <= S0;
  end case;

end process;

end behave;



ผลการสังเคาะห์วงจร






    

วันเสาร์ที่ 25 เมษายน พ.ศ. 2558

การส่งข้อมูลแบบ Uart


การส่งข้อมูลแบบ UART 

  1.  คอมพิวเตอร์                                                                                                   1  เครื่อง
  2.  FPGA Board (Altera WARRIOR CYCLONE III EP3C10E144C8)               1  บอร์ด
  3.  Osciloscope                                                                                                 1  เครื่อง
  4.  สาย Digital Logic Analyzer                                                                            1  ชุด
  5.  USB Blaster                                                                                                 1  ชุด

การสื่อสารอนุกรมแบบ Asynchronous เป็นการส่งข้อมูลที่ไม่ต้องใช้สัญญาณ Clock มาเป็นตัวกำหนดจังหวะการรับส่งข้อมูลแต่ ใช้วิธีกำหนด รูปแบบ Format การรับส่งข้อมูลขึ้นมาแทน และ อาศัยการกำหนด ความเร็วของการรับ และ ส่ง ที่เท่ากันทั้งฝั่งรับและฝั่งส่ง ข้อดีของการใช้ Asynchronous คือสามารถสื่อสารแบบ Full Duplex รับ และ ส่งได้ในเวลาเดียวกัน แต่ Asynchronous มีโอกาสที่ข้อมูลจะสูญหายขณะรับส่งข้อมูล หรือ รับส่งข้อมูลผิดพลาดได้มากกว่าแบบ Synchronous  
สรุปกล่าวคือ UART (Universal Asynchronous Receiver Transmitter) หมายถึง รูปแบบการส่งข้อมูล ที่ถูกกำหนดขึ้นมาเพื่อใช้รับส่งข้อมูลแบบ Asynchronous โดยมีรูปแบบดังรูป

เริ่มต้นจาก Start Bit เป็น Logic 0 จากนั้นจะตามด้วย Data ที่เราส่ง แล้วจะถูกปิดด้วย STOP Bit เป็น Logic 1






ใช้ ออสซิโลสโคปวัดสัญญาณที่ส่งมา (ทดสอบ 00110011)


ทดลองส่งข้อมูลเป็น ascii code binary 10000010 ซึ่งก็คือตัว a




ที่มาข้อมูล http://www.thaieasyelec.com/article-wiki/basic-electronics/uart-ttl-rs232-max232-max3232.html


Code VHDL


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity Uart is
port(
CLK , PB : in std_logic;
OutData : out std_logic
);
end Uart ;

architecture behave of Uart is
   signal Data , state_pb : std_logic;
signal TStart , TStop , TSend ,i : integer := 0;
signal InData : std_logic_vector(0 to 7) := "10000010";
--signal check, outPWM : std_logic;
--signal REG : std_logic_vector(23 downto 0) := x"000000";


type state_type is (Idle, start_bit, send_data ,stop_bit);
   signal state : state_type := Idle;


begin

process(CLK,PB) begin

if rising_edge(CLK) then

case state is

 when Idle =>

 Data <= '1';
 if PB = '0' then
   state_pb <= '1';
 elsif PB = '1' and state_pb = '1' then
   state_pb <= '0';
state <= start_bit;
 end if;

 when start_bit =>

if TStart < 5208 then
Data <= '0';
TStart <= TStart+1;
else
TStart <= 0;
state <= send_data;

end if;

 when send_data =>


if i < 8 then

if TSend < 5208 then
Data <= InData(i);
TSend <= TSend+1;
else
TSend <= 0;
i<=i+1;
end if;

else


state <= stop_bit;
i <= 0;
end if;

when stop_bit =>

Data <= '1';
if TStop < 5208 then
TStop <= TStop+1;
else
TStop <= 0;
state <= Idle;
end if;

 end case;

end if;
end process;
    OutData <= Data ;
end behave;



 



วันศุกร์ที่ 27 กุมภาพันธ์ พ.ศ. 2558

Keypad

4x4 Matrix Membrane Keypad


1. บอร์ด Altera FPGA (WARRIOR CYCLONE3 DEV) ชิปหมายเลข EP3C10E144C8                        1 บอร์ด
2. สายดาวน์โหลด ByteBlaster II Cable หรือ สายดาวน์โหลดUSB Blaster Cab                                  1 ชุด
3. เครื่องคอมพิวเตอร์                                                                                                                 1 ชุด
4. ออสซิลโลสโคป                                                                                                                      1 เครื่อง
5. Mini 4x4 Matrix Keyboard board                                                                                             1 อัน
6. ตัวต้านทาน 470 โอม                                                                                                              4 ตัว
7. สายไฟ                                                                                                                                   -  เส้น



http://www.parallax.com/sites/default/files/styles/full-size-product/public/27899.png?itok=zmmewvUT


http://images.elektroda.net/79_1296684161.gif


code


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity keypad is
port (  
dataout : out std_logic_vector(3 downto 0);
LEDin : in std_logic_vector(3 downto 0) := "0000";
LEDout : out std_logic_vector(3 downto 0) := "0000";
CLK : in std_logic

);
end keypad ;

architecture behav of keypad  is

  type state_type is (S0,S1,S2,S3);
  signal staterow : state_type := S0;
  signal count : integer :=0;
  signal data : std_logic_vector(3 downto 0);
  signal LEDdata : std_logic_vector(3 downto 0);


begin
process(CLK) begin

if rising_edge(CLK) then
   count<=count+1;

   case staterow is
     when S0 =>
data <= "1000";
  LEDdata <= LEDin;
if(count=500000) then
  staterow <= S1;
  count <=0;
end if;

when S1 =>
data <= "0100";
LEDdata <= LEDin;
if(count=500000) then
  staterow <= S2;
  count <=0;
end if;
when S2 =>
data <= "0010";
LEDdata <= LEDin;
if(count=500000) then
  staterow <= S3;
  count <=0;
end if;
when S3 =>
data <= "0001";
LEDdata <= LEDin;
if(count=500000) then
  staterow <= S0;
  count <=0;
end if;

end case;
end if;
dataout <= data;
LEDout <= LEDdata;
end process;
end behav;

ภาพการทดลอง



วันอังคารที่ 24 กุมภาพันธ์ พ.ศ. 2558

LAB 2 จงออกแบบวงจรดิจิลัทโดยใช้ภาษา VHDL สำหรับนำไปสร้างเป็นวงจรในชิป FPGA โดยใช้บอร์ดที่มีอยู่ในห้องแล็ป

LAB 2

 จงออกแบบวงจรดิจิลัทโดยใช้ภาษา VHDL สำหรับนำไปสร้างเป็นวงจรในชิป FPGA โดยใช้บอร์ดที่มีอยู่ในห้องแล็ป


อุปกรณ์การทดลอง

  1.  คอมพิวเตอร์                                                                                                   1  เครื่อง
  2.  FPGA Board (Altera WARRIOR CYCLONE III EP3C10E144C8)               1  บอร์ด
  3.  Osciloscope                                                                                                 1  เครื่อง
  4.  WS2812 RGB LED                                                                                         1 ดวง

  5.  USB Blaster                                                                                                 1  ชุด


วิธีการทดลอง

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 บิต
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 จริง)
            -
บันทึกผลและเขียนรายงานการทดลอง




0x000000 


0x0000FF 


0x00FF00 


0xFF0000 



RLT


logic elements



วันจันทร์ที่ 9 กุมภาพันธ์ พ.ศ. 2558

Lab 1 จงออกแบบวงจรดิจิลัทโดยใช้ภาษา VHDL สำหรับนำไปสร้างเป็นวงจรในชิป FPGA

 Lab 1

    จงออกแบบวงจรดิจิลัทโดยใช้ภาษา VHDL สำหรับนำไปสร้างเป็นวงจรในชิป FPGA 

อุปกรณ์การทดลอง

  1.  คอมพิวเตอร์                                                                                                   1  เครื่อง
  2.  FPGA Board (Altera WARRIOR CYCLONE III EP3C10E144C8)               1  บอร์ด
  3.  Osciloscope                                                                                                 1  เครื่อง
  4.  สาย Digital Logic Analyzer                                                                            1  ชุด
  5.  USB Blaster                                                                                                 1  ชุด

วิธีการทดลอง

1.1) วงจรดิจิทัลมี I/O ดังนี้
- CLK (input) มีความถี่ 50MHz ใช้สำหรับกำหนดจังหวะการทำงานของวงจรทั้งหมด (เป็นการออกแบบวงจรดิจิทัลแบบ Synchronous Design)
- RST_B (input) เป็นอินพุตสำหรับใช้รีเซตแบบ Asynchronous สำหรับการทำงานของวงจรโดยรวม (ทำงานแบบ Active-Low) ซึ่งได้จากวงจรปุ่มกด (Push Button)
- PB[2:0] (input) เป็นอินพุตจากปุ่มกด 3 ปุ่ม ทำงานแบบ Active-low เพื่อใช้ในการเปลี่ยนค่า Duty Cycle โดยเพิ่มทีละ 10 ในช่วง 0 ถึง 100 สำหรับสัญญาณ PWM(2:0) ที่มี 3 ช่องสัญญาณ
- PWM[2:0] (output) เป็นเอาต์พุตสำหรับนำไปควบคุมการทำงานของ RGB LED จำนวน 1 ดวง

1.2) พฤติกรรมการทำงานเป็นดังนี้
- เมื่อเริ่มต้นหรือกดปุ่มรีเซต RST_B ค่า PWM[2:0] จะเป็นลอจิก 0 ทั้ง 3 ช่องสัญญาณ และมีค่า Duty Cycle สำหรับสัญญาณ PWM[i], i=0,1,2 เป็น 0
- เมื่อกดปุ่มใดๆ PB[i], i=0,1,2, แล้วปล่อยในแต่ละครั้ง จะเพิ่มค่า Duty Cycle ของสัญญาณ PWM สำหรับช่องสัญญาณ i ทีละ 10 แต่ถ้าถึง 100 จะกลับไปเริ่มต้นที 0 ใหม่
- สัญญาณ PWM แต่ละช่อง ต้องมีความถี่เท่ากันและคงที่ และสามารถเลือกใช้ความถี่ได้ในช่วง 500Hz ถึง 1kHz

1.3) แนวทางการออกแบบและทดสอบ
- ออกแบบวงจรโดยใช้ภาษา VHDL
- เขียน VHDL Testbench เพื่อทดสอบการทำงาน และจำลองการทำงาน
- ทดสอบการทำงานในบอร์ด FPGA แล้ววัดสัญญาณโดยใช้ออสซิลโลสโคป
(ไม่ต้องต่อวงจร RGB LED จริง)
- บันทึกผลและเขียนรายงานการทดลอง

VHDL CODE



compilation Report



ผลการสังเคราะห์วงจร



การจำลองการทำงานด้วย Modlesim

ผลการทดลอง



รูปที่ 1 รูปสัญญาณจาก Oscilloscope


รูปที่ 2 รูปการต่อวงจร