Latch warning - Verilog code

Status
Not open for further replies.

d0lla

Newbie level 1
Joined
Jul 4, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
19
Hi there!
I'm trying to make a FSM for the Fibonacci string, but I'm getting some warnings during the synthesis and I can't figure out why.

This is the code :

Code Verilog - [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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    14:02:45 07/04/2014 
// Design Name: 
// Module Name:    Fibo 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
 
`define S0 3'b000
`define S1 3'b001
`define S2 3'b010
`define S3 3'b011
`define S4 3'b100
`define S5 3'b101
 
module Fibo(
    input clk, rst,
    input start,
     output [2:0] current_state,
    output integer outbus
    );
 
reg [2:0] state_nxt, state_reg;
integer fib_n=0, fib_n1=1, fib_n2=0;
integer n=5;
 
 
 
//segm secvential
always @(posedge clk or posedge rst)
begin
    if(rst)
    state_reg <= 0;
    else
    state_reg <= state_nxt;
end
 
//segm combinational
always @(state_reg, start, n, fib_n, fib_n1, fib_n2)
begin
    state_nxt=state_reg;
    
    case(state_reg)
        `S0: begin
                        if(start)
                            state_nxt=`S1;
                        else
                            state_nxt=`S0;
              end
    
        `S1: begin
                        fib_n=0;
                        fib_n1=1;
                        fib_n2=0;
                        if(n)
                            state_nxt = `S2;
                        else
                            state_nxt = `S5;
                end
        `S2: begin
                        fib_n = fib_n1 + fib_n2;
                        state_nxt = `S3;
              end
        `S3: begin
                        fib_n2 = fib_n1;
                        state_nxt = `S4;
              end
        `S4: begin
                        fib_n1 = fib_n;
                        n = n-1;
                        if(n)
                        state_nxt = `S2;
                        else
                        state_nxt = `S5;
              end
        `S5: begin
                        outbus = fib_n;
                        state_nxt = `S0;
              end
endcase
end
 
assign current_state=state_reg;
    
endmodule




And this are the warnings:
 
Last edited by a moderator:

Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems.
.

The error message is giving you a good hint. The value of outbus must be described in every single state. Likewise with any other signal that is on the left hand side of an assignment in that case statement.

r.b.
 

I would suggest using localparam for the state names instead of define. As the scope will only be in this file.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…