Problem mit 8 Bit LFSR

OP #7452416
Lesenswert?

Hallo zusammen!

Ich habe versucht, 8-Bit-LFSR mit den Taps 0, 3 und 7 zu implementieren. Aber jedes Mal, wenn ich eine andere Seed-Kombination als „00000001“, „10101010“ und die nicht erlaubten (aber trotzdem getesteten) „00000000“ und „11111111“ probiere, bekomme ich in meinem Testbench kein korrektes Ergebnis, obwohl ich den korrekten Hex-Wert der res_tb-Variable übergebe. Habe ich den Testbench nicht korrekt geschrieben oder liegt mein Problem in der LFSR-Implementierung?

My code:

1
library ieee;
2

3
use ieee.std_logic_1164.all;
4

5
use ieee.numeric_std.all;
6

7

8

9

10

11
entity lfsr is
12

13
port (
14

15
clk : in std_ulogic;
16

17
seed : in std_ulogic_vector(7 downto 0);
18

19
clear : in std_ulogic;
20

21
res : out std_ulogic_vector(7 downto 0)
22

23
);
24

25
end entity ; --lfsr
26

27

28

29
architecture lfsr_beh of lfsr is
30

31
signal current_state : std_ulogic_vector(7 downto 0);
32

33
signal next_state : std_ulogic_vector(7 downto 0);
34

35
signal feedback : std_ulogic;
36

37

38

39
begin
40

41
--Seed Assertion
42

43

44

45
--Reset Function
46

47
Shift_Reg : process (clk, clear)
48

49
begin
50

51
if (clear = '1') then
52

53
current_state <= seed;
54

55
elsif (clk = '1' and clk'event) then
56

57
current_state <= next_state;
58

59
end if;
60

61
end process;
62

63

64

65
--Loop
66

67
feedback <= current_state(7) xor current_state(3) xor current_state(0);
68

69
next_state <= feedback & current_state(7 downto 1);
70

71
res <= current_state;
72

73

74

75
end architecture ;

My test bench:

1
library ieee;
2

3
use ieee.std_logic_1164.all;
4

5

6

7
entity lfsr_tb is
8

9
end entity lfsr_tb;
10

11

12

13
architecture tb_arch of lfsr_tb is
14

15
-- Component declaration
16

17
component lfsr
18

19
port (
20

21
clk : in std_ulogic;
22

23
seed : in std_ulogic_vector(7 downto 0);
24

25
clear : in std_ulogic;
26

27
res : out std_ulogic_vector(7 downto 0)
28

29
);
30

31
end component;
32

33

34

35
-- Signal declarations
36

37
signal clk_tb : std_ulogic;
38

39
signal seed_tb : std_ulogic_vector(7 downto 0);
40

41
signal clear_tb : std_ulogic;
42

43
signal res_tb : std_ulogic_vector(7 downto 0);
44

45

46

47
begin
48

49
-- Component instantiation
50

51
DUT : lfsr
52

53
port map (
54

55
clk => clk_tb,
56

57
seed => seed_tb,
58

59
clear => clear_tb,
60

61
res => res_tb
62

63
);
64

65

66

67
-- Clock process
68

69
clk_process : process
70

71
begin
72

73
while now < 100 ns loop
74

75
clk_tb <= '0';
76

77
wait for 5 ns;
78

79
clk_tb <= '1';
80

81
wait for 5 ns;
82

83
end loop;
84

85
wait;
86

87
end process;
88

89

90

91
-- Stimulus process
92

93
stimulus_process : process
94

95
begin
96

97
seed_tb <= "00000001";
98

99
wait for 10 ns;
100

101
clear_tb <= '1'; -- Assert the clear signal
102

103
wait for 10 ns;
104

105
clear_tb <= '0'; -- Deassert the clear signal
106

107
for i in 0 To 4 loop
108

109
wait until clk_tb='1' and clk_tb'event;
110

111
end loop;
112

113

114

115
wait for 5 NS;
116

117
assert res_tb = X"F8" report "Failed Output";
118

119
report "Test Passed, output is correct";
120

121
wait for 10 ns;
122

123

124

125
end process;
126

127

128

129
end architecture tb_arch;

Ich freue mich auf Ihre Hilfe!

#7452511
Lesenswert?

Momentan setzt du das Feedback-Bit an die Position des höchstwertigen Bits (MSB) (7), gefolgt von den Bits 6 bis 1 aus dem aktuellen Zustand. Dadurch geht das Feedback-Bit beim Shiften verloren.

Ändere die Zeile next_state <= feedback & current_state(7 downto 1);

einmal in:

next_state <= current_state(6 downto 0) & feedback;

Dadurch werden die Bits 6 bis 0 des aktuellen Zustands an die Positionen 7 bis 1 des nächsten Zustands verschoben, und das Feedback-Bit wird an die Position 0 gesetzt.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren