rashmi.imhsar
Junior Member level 2
- Joined
- Mar 13, 2014
- Messages
- 20
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1
- Activity points
- 270
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 -- unraveling the generate produces... p1_1: lfsr4 port map ( rstN => rstN_main, clk => clk_main, load => load_main, seed1 => seed, enable => enable_main, q => q_main ); p1_2: lfsr4 port map ( rstN => rstN_main, clk => clk_main, load => load_main, seed1 => seed, enable => enable_main, q => q_main ); -- ... p1_15: lfsr4 port map ( rstN => rstN_main, clk => clk_main, load => load_main, seed1 => seed, enable => enable_main, q => q_main ); p2_1: rxr4 port map ( rstN => rstN_main, clk => clk_main, q => q_main, led => led ); p2_2: rxr4 port map ( rstN => rstN_main, clk => clk_main, q => q_main, led => led ); -- ... p2_15: rxr4 port map ( rstN => rstN_main, clk => clk_main, q => q_main, led => led );
Sorry I understand its difficult to help without giving proper inputs.
How do I attach my code ?I could not find syntax tags icon anywhere !
Here is the code of the two components. Basically I want to send a 4 bits from a 4 bit lfsr and receive the 4 bits. A 4 bit lfsr is used at the receiver also to compare the last bit of the generated output (from rxr lfsr) and the received 4 bits.
After comparing, the control should be transferred to the Txr to send the next 4 bits to the RXr. This way, I want to compare 15 bits and so the iteration should be for 15 times.
The error value is displayed using LEDs after 15 iterations are over. So I do not need to store the LED values in an array.
See this for an explanation how to:rashmi.imhsar;1338862 said:How do I attach my code ?I could not find syntax tags icon anywhere !
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 -- A 4-bit Linear feedback shift-register (LFSR)-PRBS & BERT. -- -- ---------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; -- ---------------------------------------------------------------- entity lfsr4_txrrxr is port ( rstN : in std_logic; clk : in std_logic; -- Load the LFSR register load : in std_logic; -- transmitter LFSR seed value (eg, 0001) seed1 : in bit_vector(3 downto 0); -- receiver LFSR seed value (seed1 & seed2 are different to check for error) (eg, 1001) --seed2 : in bit_vector(3 downto 0); -- Enable the LFSR register enable : in std_logic; data : out bit_vector(3 downto 0); -- LFSR register (1-bit of this is the PRBS signal) led : out bit_vector(3 downto 0) ); end entity; -- ---------------------------------------------------------------- architecture basic of lfsr4_txrrxr is -- Internal LFSR register signal q : bit_vector(3 downto 0); signal p : bit_vector(3 downto 0); signal error,m,n:integer:=0; begin -- LFSR shift-register p1: process(clk, rstN) begin if (rstN = '0') then q <= (others => '1'); elsif rising_edge(clk) then if (load = '1') then q <= seed1; elsif (enable = '1') then q <= (q(1) xor q(0)) & q(3 downto 1); end if; end if; end process p1; -- Output data <= q; -- Receiver p2:process(clk,q) begin if rising_edge(clk) then n<=n+1; if n=0 and q= "0001" then p <= q ; elsif n=0 then p <= "0001"; else p <= ( p(1) xor p(0)) & p(3 downto 1); end if; end if; end process p2; -- checking for error p3: process (p) begin -- to display error using LEDs after 15 bits are checked if m=16 then case error is when 0 => led <= "0000"; when 1 => led <= "0001"; when 2 => led <= "0010"; when 3 => led <= "0011"; when 4 => led <= "0100"; when 5 => led <= "0101"; when 6 => led <= "0110"; when 7 => led <= "0111"; when 8 => led <= "1000"; when 9 => led <= "1001"; when 10 => led <= "1010"; when 11 => led <= "1011"; when 12 => led <= "1100"; when 13 => led <= "1101"; when 14 => led <= "1110"; when 15 => led <= "1111"; when others => led <= "0000"; end case; end if; if (p(0)/= q(0)) then error <= error + 1; end if; m<=m+1; end process p3; end architecture;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 library ieee; use ieee.std_logic_1164.all; -- ---------------------------------------------------------------- entity lfsr4_txrrxr is port ( rstN : in std_logic; clk : in std_logic; -- Load the LFSR register load : in std_logic; -- transmitter LFSR seed value (eg, 0001) seed1 : in bit_vector(3 downto 0); -- Enable the LFSR register enable : in std_logic; data : out bit_vector(3 downto 0); -- LFSR register (1-bit of this is the PRBS signal) led : out bit_vector(3 downto 0) ); end entity; -- ---------------------------------------------------------------- architecture basic of lfsr4_txrrxr is -- Internal LFSR register signal q : bit_vector(3 downto 0); signal p : bit_vector(3 downto 0); signal error,m,n:integer:=0; signal r,k: integer:= 0; begin -- LFSR shift-register p1: process(clk, rstN) begin if (rstN = '0') then q <= (others => '1'); elsif rising_edge(clk) then if (load = '1') then q <= seed1; elsif (enable = '1') then q <= (q(1) xor q(0)) & q(3 downto 1); end if; end if; end process p1; -- Output data <= q; -- Receiver p2:process(clk,q) begin if rising_edge(clk) then --k<=k-1; n<=n+1; if n=0 and q= "0001" then p <= q ; elsif n=0 then p <= "0001"; else p <= ( p(1) xor p(0)) & p(3 downto 1); end if; r<=2; end if; end process p2; -- checking for error p3: process (clk,p) begin -- to display error using LEDs after 15 bits are checked k<=r; if k=2 then if m=16 then case error is when 0 => led <= "0000"; when 1 => led <= "0001"; when 2 => led <= "0010"; when 3 => led <= "0011"; when 4 => led <= "0100"; when 5 => led <= "0101"; when 6 => led <= "0110"; when 7 => led <= "0111"; when 8 => led <= "1000"; when 9 => led <= "1001"; when 10 => led <= "1010"; when 11 => led <= "1011"; when 12 => led <= "1100"; when 13 => led <= "1101"; when 14 => led <= "1110"; when 15 => led <= "1111"; when others => led <= "0000"; end case; end if; if (p(0)/= q(0)) then error <= error + 1; end if; m<=m+1; k<=0; end if; end process p3; end architecture;
p2:process(clk,q)
p3: process (clk,p)
p2:process(clk)
p3: process (clk)
Code VHDL - [expand] 1 2 3 4 5 6 7 8 p3; process (clk) begin if rising_edge (clk) then --... --insert your code --... end if; end process p3;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 library ieee; use ieee.std_logic_1164.all; -- ---------------------------------------------------------------- entity lfsr4_txrrxr is port ( rstN : in std_logic; clk : in std_logic; -- Load the LFSR register load : in std_logic; -- transmitter LFSR seed value (eg, 0001) seed1 : in bit_vector(3 downto 0); -- Enable the LFSR register enable : in std_logic; data : out bit_vector(3 downto 0); -- LFSR register (1-bit of this is the PRBS signal) led : out bit_vector(3 downto 0) ); end entity; -- ---------------------------------------------------------------- architecture basic of lfsr4_txrrxr is -- Internal LFSR register signal q : bit_vector(3 downto 0); signal p : bit_vector(3 downto 0); signal error,m,n:integer:=0; signal r,k,c,a: integer:= 0; begin -- LFSR shift-register p1: process(clk, rstN) begin -- c<=0; if (rstN = '0') then q <= (others => '1'); elsif rising_edge(clk) then if (load = '1') then q <= seed1; elsif (enable = '1') then q <= (q(1) xor q(0)) & q(3 downto 1); end if; --c<=2; end if; end process p1; -- Output data <= q; -- Receiver p2:process(clk) begin if rising_edge(clk) then --a<=c; --if a=2 then n<=n+1; if n=0 and q= "0001" then p <= q ; elsif n=0 then p <= "0001"; else p <= ( p(1) xor p(0)) & p(3 downto 1); end if; r<=2; --a<=0; end if; --end if; end process p2; -- checking for error p3: process (clk) begin if rising_edge(clk) then -- to display error using LEDs after 15 bits are checked k<=r; if k=2 then if m=16 then case error is when 0 => led <= "0000"; when 1 => led <= "0001"; when 2 => led <= "0010"; when 3 => led <= "0011"; when 4 => led <= "0100"; when 5 => led <= "0101"; when 6 => led <= "0110"; when 7 => led <= "0111"; when 8 => led <= "1000"; when 9 => led <= "1001"; when 10 => led <= "1010"; when 11 => led <= "1011"; when 12 => led <= "1100"; when 13 => led <= "1101"; when 14 => led <= "1110"; when 15 => led <= "1111"; when others => led <= "0000"; end case; end if; if (p(0)/= q(0)) then error <= error + 1; end if; m<=m+1; k<=0; end if; end if; end process p3; end architecture;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 library ieee; use ieee.std_logic_1164.all; -- ---------------------------------------------------------------- entity lfsr4_txrrxr is port ( rstN : in std_logic; clk : in std_logic; -- Load the LFSR register load : in std_logic; -- Enable the LFSR register enable : in std_logic; data : out bit_vector(3 downto 0); -- To display the Error value using LEDs led : out bit_vector(3 downto 0); rxd_data : in bit_vector( 3 downto 0) ); end entity; -- ---------------------------------------------------------------- architecture basic of lfsr4_txrrxr is -- Internal LFSR register signal txd: bit_vector(3 downto 0); signal rxr_lfsr : bit_vector(3 downto 0); signal error,bits_tested,n,w:integer:=0; signal flag,flag_copy: integer:= 0; begin -- LFSR shift-register p1: process(clk, rstN) begin if (rstN = '1') then if rising_edge(clk) then w<=w+1; if (load = '1' and w=0) then txd <= "0001"; elsif (w/= 0) then txd <= (txd(1) xor txd(0)) & txd(3 downto 1); end if; end if; end if; end process p1; -- Output data --> DAC input pins data <= txd; -- data --> assigned to DAC pins -- DAC is enabled already -- analog output from DAC --> SMA connector --> input to ADC -- ADC output pins --> rxd_data -- Receiver p2:process(clk) begin if (rstN = '1') then if rising_edge(clk) then if (rxd_data /= "0000") then n<=n+1; if n=0 then rxr_lfsr <= "0001"; else rxr_lfsr <= (rxr_lfsr(1) xor rxr_lfsr(0)) & rxr_lfsr(3 downto 1); end if; flag<=2; end if; end if; end if; end process p2; -- checking for error p3: process (clk) begin if rising_edge(clk) then -- to display error using LEDs after 15 bits are checked flag_copy<=flag; if flag_copy=2 then if bits_tested=16 then case error is when 0 => led <= "0101"; when 1 => led <= "0001"; when 2 => led <= "0010"; when 3 => led <= "0011"; when 4 => led <= "0100"; when 5 => led <= "0101"; when 6 => led <= "0110"; when 7 => led <= "0111"; when 8 => led <= "1000"; when 9 => led <= "1001"; when 10 => led <= "1010"; when 11 => led <= "1011"; when 12 => led <= "1100"; when 13 => led <= "1101"; when 14 => led <= "1110"; when 15 => led <= "1111"; when others => led <= "1111"; end case; end if; if (rxr_lfsr(0)/= rxd_data(0)) then error <= error + 1; end if; bits_tested<=bits_tested+1; flag_copy<=0; end if; end if; end process p3; end architecture;
Yes I can understand.
I want to use a single FPGA to act as a PRBS generator and as a BERT. The data is to be passed through optic fibre medium.
Txr PRBS generator(FPGA)-->DAC-->SMA Connector-->electrical amplifier-->fiber-->electrical amp-->ADC-->Rxr(FPGA).
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 p1: process(clk, rstN) begin if (rstN = '1') then if rising_edge(clk) then w<=w+1; if (load = '1' and w=0) then txd <= "0001"; elsif (w/= 0) then txd <= (txd(1) xor txd(0)) & txd(3 downto 1); end if; end if; end if; end process p1;
I want the Rxr LFSR value and the rxd_data value to be compared only after data from the txd has been received by rxd_data.
Also,how do I make sure that the received data in rxd_data is the one that was transmitted or if it some junk value? I could not understand how a suffix could be added to the data sequence to check for this.
Yes you will likely have missed the erroneous bit in the first seed value of "0001", but that is inherent in the way the interface is designed with raw lfsr data. If you want to know where data starts/stops etc. then use some coding scheme like 8b10 and then you can use specific K-codes to define the start and stopping point of the data. Then your FSM only needs to monitor the stream for the correct start K-code and begin comparing from the next bits on.My doubt is, if the channel had produced erroneous bit during the first iteration itself, then the error will be missed .
Yes, it will error continuously, hence additional logic is required to detect that error and restart synchronization of the BERT with the rxd_data. If the channel is too noisy then it will likely never synchronize properly. If that is the case then channel should have error correction encoding added.In the second point: The rxr_lfsr is to be initialised with the rxd_data (the seed used at the txr lfsr) and the rxr_lfsr is compared with the rxd_data?
If the channel had changed the actual seed value used in the txr, the new erroneous value will be the seed to the rxr_lfsr right? then the subsequent values when compared will produce error always. This is what is confusing me
You have to keep repeatedly trying to synchronize every time the compares don't match continuously after you started. In a test platform I developed using a PRBS-23 sequence I used the seeding method as waiting for the PRBS-23 sequence to cycle could have taken 20 seconds or more with lowest data rate we needed to support. If the first seed value was incorrect the bit error count would increment continuously. If that condition was detected then the design would resync by reloading the PRBS-23 with a new seed from the received data.But my doubt is, the rxd data which matched with the Rxr lfsr seed value "1001" could have actually been transmitted as , say, "1000" at the txr.
In this case, once the Rxr lfsr is activated after matching, it will be comparing "1100"(rxr lfsr gen value following seed value of 1001) with "0100"(the actual value generated by the txr lfsr following the value 1000).
So I do not understand how this synchronization can be done using this kind of method.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?