query related to verilog code

Guest #4564222
Rate this post
• ▲ useful
▼ not useful
1
module encoder(clk,rst,en,en1,data,decoded_data);
2
    input clk,rst,en,en1;
3
    input [7:0]data;
4
    output [7:0]decoded_data;
5
    wire [7:0]btg;
6
    reg [7:0]dec;
7
    reg [5:0] mem[0:255];   // ENCODED
8
    reg [5:0] mem1[0:255];  // DECODED
9
    reg [7:0] mem2[0:255];  // OUTPUT
10
    reg [7:0] mem3[0:255];  // BTG DATAS
11
    reg [7:0]count,count1,count2;
12
    integer fd;
13
  
14
 always @(!rst) begin
15
        mem[0]=6'b000000;  
16
        mem1[0]=6'b000000;
17
        mem2[0]=8'b00000000;
18
        mem3[0]=8'b00000000;
19
        count=8'b00000000;
20
        count1=8'b00000000;
21
        count2=8'b00000000;
22
        dec=8'b00000000;
23
    end
24
    
25
    
26
    
27
    //pseudo_random p1(clk,rst,data);
28
    binary_gray b1(data,btg);
29
    
30
    
31
    
32
    always @(data) begin
33
        fd=$fopen("outfile.txt");
34
        $fdisplay(fd,"%b",data);
35
    end
36
        
37
    
38
    
39
    always @(btg) begin
40
        if (btg[4] && btg[5] && en == 1) begin
41
            count=count+1;
42
            mem3[count]=btg;
43
            mem[count]=~({btg[7],btg[6],btg[3],btg[2],btg[1],btg[0]} ^ mem[count-1]);
44
            fd=$fopen("outfile1.txt");
45
            $fdisplay(fd,"%b",mem[count]);
46
        end else if (en == 1) begin
47
            count=count+1;
48
            mem3[count]=btg;
49
            mem[count]=({btg[7],btg[6],btg[3],btg[2],btg[1],btg[0]} ^ mem[count-1]);
50
            fd=$fopen("outfile1.txt");
51
            $fdisplay(fd,"%b",mem[count]);
52
        end
53
    end
54
    
55
    always @(btg) begin
56
        if ((btg[4] && btg[5]) && en1 == 0) begin
57
            count1=count1+1;
58
            mem1[count1]=~((mem[count-1]) ^ (mem[count]));
59
            dec={mem1[count1][5],mem1[count1][4],btg[5],btg[4],mem1[count1][3],mem1[count1][2],mem1[count1][1],mem1[count1][0]};
60
            fd=$fopen("outfile2.txt");
61
            $fdisplay(fd,"%b",mem1[count1]);
62
        end else if (en1 == 0) begin
63
            count1=count1+1;
64
            mem1[count1]=((mem[count-1]) ^ (mem[count]));
65
            dec={mem1[count1][5],mem1[count1][4],btg[5],btg[4],mem1[count1][3],mem1[count1][2],mem1[count1][1],mem1[count1][0]};
66
            fd=$fopen("outfile2.txt");
67
            $fdisplay(fd,"%b",mem1[count1]);
68
        end
69
    end
70
    
71
    
72
    gray_binary g1(dec,decoded_data);
73
    
74
    
75
    always @(btg) begin
76
        count2=count2+1;
77
        mem2[count2]=decoded_data;
78
        fd=$fopen("outfile3.txt");
79
        $fdisplay(fd,"%b",mem2[count2]);
80
    end
81
        
82
endmodule
83

84
module binary_gray(a,b);
85
    input [7:0]a;
86
    output [7:0]b;
87
    wire [7:0]b;
88
    assign b={a[7],a[7]^a[6],a[6]^a[5],a[5]^a[4],a[4]^a[3],a[3]^a[2],a[2]^a[1],a[1]^a[0]};
89
endmodule
90

91
module gray_binary(a,b);
92
    input [7:0]a;
93
    output [7:0]b;
94
    wire [7:0]b;
95
    assign b={a[7],a[7]^a[6],b[6]^a[5],b[5]^a[4],b[4]^a[3],b[3]^a[2],b[2]^a[1],b[1]^a[0]};
96
endmodule
97

98

99
module pseudo_random(clk,rst,s);
100
input clk,rst;
101
output [8:1]s;
102
reg [8:1]s;
103
wire s0;
104
// MODULO 2 ADDITION
105
assign s0 = s[2] ^ s[3] ^ s[4] ^ s[8];
106
// STATE MACHINE
107
always @ (posedge clk or rst) begin
108
// INITIAL STATE SHOULDN'T BE 000 => 100
109
if(!rst) begin
110
s[1] <= 0;
111
s[2] <= 0;
112
s[3] <= 0;
113
s[4] <= 0;
114
s[5] <= 0;
115
s[6] <= 0;
116
s[7] <= 0;
117
s[8] <= 1;
118
end else begin
119
s[1] <= s[2];
120
s[2] <= s[3];
121
s[3] <= s[4];
122
s[4] <= s[5];
123
s[5] <= s[6];
124
s[6] <= s[7];
125
s[7] <= s[8];
126
s[8] <= s0;
127
end
128
end
129
endmodule


line 15: Unexpected event in always block sensitivity list.
Attached files:
Moderator (Company: Titel) #4564255
Rate this post
• ▲ useful
▼ not useful
I don't know Verilog too much, but counters without a clock form 
combinatorial loops:
1
    ...
2
    always @(btg) begin
3
        if (btg[4] && btg[5] && en == 1) begin
4
            count=count+1;
5
    ...
6
    always @(btg) begin
7
        count2=count2+1;
8
    ...
And so forth.
Additionally to me it looks like some of those lists are incomplete:
In the qouted blocks above count and count2 are missing.

For the error message:
Try your code without the '!'.
A sensitivity list tells only to look for changes on the signals in 
it. So a negation sign is absolutely useless there. Think about that...


BTW: pls use [pre], [code] or [c] tags around your code.
Guest #4565364
Rate this post
• ▲ useful
▼ not useful
>
> For the error message:
> Try your code without the '!'.
> A sensitivity list tells only to look for changes on the signals in
> it. So a negation sign is absolutely useless there. Think about that...
>
Verilog allows expressions in the sensitivity list, but as with many 
constructs the synthesizer does not. However Lothar is right the ! does 
not do anything, a negated change is still a change.

Another problem with the code, is that the synthesizer does not allow 
assignments to a signal from multiple always blocks. Also legal in 
Verilog but not part of synthesizable subset.

I strongly suggest reading the coding style guide of the tool chain!

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.