Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- -- Company: Tek15 Solutions
- -- Engineer: Matt Lewis
- --
- -- Create Date: 14:22:35 01/20/2018
- -- Design Name: V2FPGA Serial Module
- -- Module Name: Serial - Behavioral
- -- Project Name: Vermonster DRSSTC Controller
- -- Target Devices: -undetermined-
- -- Description: FPGA-based dual-resonant solid-state Tesla coil
- -- controller designed for the Vermonster DRSSTC
- -- Revision: 2
- ----------------------------------------------------------------------------------
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.NUMERIC_STD.ALL;
- entity Serial is
- port (
- CLK_50MHz: IN STD_LOGIC;
- RX: IN STD_LOGIC;
- TX: OUT STD_LOGIC
- );
- end Serial;
- architecture Behavioral of Serial is
- begin
- -- 9600 baud = 9600 bits/sec
- -- 1 bit time = 1000ms/9600 = 104.2us
- -- 1/2 bit time = 52.1us
- -- 1 tick = 1/50000000Hz = 20ns
- -- Ticks per bit: 104.2us/20ns = 5210 ticks
- -- Ticks per half bit: 52.1us/20ns = 2605 ticks
- -- Data Stream:
- -- BYTE0
- -- |BIT7|BIT6| BIT5| BIT4| BIT3| BIT2| BIT1| BIT0|
- -- |STRT|R/W ||_____________FEATURE______________|
- -- BYTE1
- -- |BIT7|BIT5| BIT5| BIT4| BIT3| BIT2| BIT1| BIT0|
- -- |________________VALUE (WRITE)________________|
- RxBytes: process(CLK_50MHz)
- variable RxByte0: STD_LOGIC_VECTOR(7 downto 0) := (others => '0'); -- Received byte 0
- variable RxByte1: STD_LOGIC_VECTOR(7 downto 0) := (others => '0'); -- Received byte 1
- variable RxBegun: STD_LOGIC := '0'; -- Receive sequence started
- variable RxFinished: STD_LOGIC := '1'; -- Receive sequence finished
- variable CurrentByte: INTEGER RANGE 0 TO 1; -- Current byte being received
- variable Counter: INTEGER RANGE 0 TO 7815; -- Counter for baud generator (1.5 bits max @ 50MHz)
- variable BitCount: INTEGER RANGE 0 TO 128; -- Counter for number of bits received. Should not exceed 16 per cmd string
- begin
- if (rising_edge(CLK_50MHz)) then -- If CLK_50MHz is rising
- if (RX = '0') then -- If RX input is low (start bit detected)
- if (RxBegun = '0') then -- If receive has not yet begun
- RxBegun := '1'; -- Begin receive
- RxFinished := '0'; -- Receive not yet finished
- -- Byte0 --
- BitCount := BitCount + 1; -- Increment number of bits received
- RxByte0(7) := '0'; -- Load '0' into Byte0 BIT7 (start bit)
- if (Counter < 7815) then -- Count 1.5 bit times to sample center of BIT6
- Counter := Counter + 1;
- else -- If ready for BIT6
- Counter := 0; -- Reset time counter
- RxByte0(6) := RX; -- Load value on RX pin into Byte0 BIT6 (R/W)
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT5
- Counter := Counter + 1;
- else -- If ready for BIT5
- Counter := 0; -- Reset time counter
- RxByte0(5) := RX; -- Load value on RX pin into Byte0 BIT5
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT4
- Counter := Counter + 1;
- else -- If ready for BIT4
- Counter := 0; -- Reset time counter
- RxByte0(4) := RX; -- Load value on RX pin into Byte0 BIT4
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT3
- Counter := Counter + 1;
- else -- If ready for BIT3
- Counter := 0; -- Reset time counter
- RxByte0(3) := RX; -- Load value on RX pin into Byte0 BIT3
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT2
- Counter := Counter + 1;
- else -- If ready for BIT2
- Counter := 0; -- Reset time counter
- RxByte0(2) := RX; -- Load value on RX pin into Byte0 BIT2
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT1
- Counter := Counter + 1;
- else -- If ready for BIT1
- Counter := 0; -- Reset time counter
- RxByte0(1) := RX; -- Load value on RX pin into Byte0 BIT1
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT0
- Counter := Counter + 1;
- else -- If ready for BIT0
- Counter := 0; -- Reset time counter
- RxByte0(0) := RX; -- Load value on RX pin into Byte0 BIT0
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- -- Byte1 --
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT7
- Counter := Counter + 1;
- else -- If ready for BIT7
- Counter := 0; -- Reset time counter
- RxByte1(7) := RX; -- Load value on RX pin into Byte1 BIT7
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT6
- Counter := Counter + 1;
- else -- If ready for BIT6
- Counter := 0; -- Reset time counter
- RxByte1(6) := RX; -- Load value on RX pin into Byte1 BIT6
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT5
- Counter := Counter + 1;
- else -- If ready for BIT5
- Counter := 0; -- Reset time counter
- RxByte1(5) := RX; -- Load value on RX pin into Byte1 BIT5
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT4
- Counter := Counter + 1;
- else -- If ready for BIT4
- Counter := 0; -- Reset time counter
- RxByte1(4) := RX; -- Load value on RX pin into Byte1 BIT4
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT3
- Counter := Counter + 1;
- else -- If ready for BIT3
- Counter := 0; -- Reset time counter
- RxByte1(3) := RX; -- Load value on RX pin into Byte1 BIT3
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT2
- Counter := Counter + 1;
- else -- If ready for BIT2
- Counter := 0; -- Reset time counter
- RxByte1(2) := RX; -- Load value on RX pin into Byte1 BIT2
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT1
- Counter := Counter + 1;
- else -- If ready for BIT1
- Counter := 0; -- Reset time counter
- RxByte1(1) := RX; -- Load value on RX pin into Byte1 BIT1
- BitCount := BitCount + 1; -- Increment number of bits received
- end if;
- if (Counter < 5210) then -- Count 1 bit time to sample center of BIT0
- Counter := Counter + 1;
- else -- If ready for BIT0
- Counter := 0; -- Reset time counter
- RxByte1(0) := RX; -- Load value on RX pin into Byte1 BIT0 (Stop bit)
- BitCount := BitCount + 1; -- Increment number of bits received
- RxBegun := '0'; -- Receive finished
- end if;
- -- Error check --
- if (BitCount /= 16) then -- If wrong number of bits detected
- RxByte0 := (others => '0'); -- Clear RxByte0
- RxByte1 := (others => '0'); -- Clear RxByte1
- else -- If data valid
- BitCount := 0; -- Reset bit counter
- RxFinished := '1'; -- Receive is finished
- end if;
- end if;
- end if;
- end if;
- end process RxBytes;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement