วันเสาร์ที่ 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;



 



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

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