Hello, I am trying to make a FSM to measure distance with an Ultrasonic sensor, but I cant seem to get rid of this latches and make my design work, i would very much appreciate any help or comment you could give me about how to fix it, thanks
1 | library IEEE; |
2 | use IEEE.std_logic_1164.all; |
3 | use IEEE.numeric_std.all; |
4 | use IEEE.std_logic_unsigned.all; |
5 | use IEEE.std_logic_arith.all; |
6 | |
7 | entity Ultrasonic_Final is |
8 | Port ( Clk : in STD_LOGIC; |
9 | Rst : in STD_LOGIC; |
10 | Echo : in STD_LOGIC; |
11 | Trig : out STD_LOGIC; |
12 | LEDs : out STD_LOGIC_VECTOR (7 downto 0)); |
13 | end Ultrasonic_Final; |
14 | |
15 | architecture Ultrasonic_Final_Arch of Ultrasonic_Final is |
16 | -- Any name can be used for the states
|
17 | -- The state coding given below is binary, which is the default
|
18 | -- Other state codings could have been used.
|
19 | type state_values is (st_wait,st_trigger,st_hold,st_echo); |
20 | signal next_state, present_state : state_values; |
21 | |
22 | -- Signals used by the Frequency divider
|
23 | constant Fosc : integer := 100_000_000; -- Oscillator Frequency for Nexys3 board |
24 | constant Fdiv : integer := 1_000_000; -- Desired Timebase Frequency |
25 | constant CtaMax : integer := Fosc / Fdiv; -- Maximum count to obtain desired outputfreq |
26 | signal Cont : integer range 0 to CtaMax; -- Define the counter |
27 | signal Timebase : std_logic; -- Flag used to indicate that timebase has ellapsed |
28 | |
29 | -- Cosants and signals for Ultrasonic sensor
|
30 | constant twait : integer := 500_000; |
31 | constant ttrig : integer := 3; |
32 | signal tcount : integer range 0 to 18_500 := 0; |
33 | signal tstate : integer range 0 to 1000000 := 0; |
34 | signal duracion : integer := 0; |
35 | signal tiempo : integer range 0 to 18_500 := 0; |
36 | signal centim : STD_LOGIC_VECTOR(7 downto 0); |
37 | signal seg : integer; |
38 | |
39 | begin
|
40 | -- Frequency divider process to obtain a Timebase signal used by the FSM
|
41 | FreqDiv: process(Rst,Clk) |
42 | begin
|
43 | if Rst = '1' then |
44 | Cont <= 0; |
45 | elsif (rising_edge(Clk)) then |
46 | if Cont = CtaMax-1 then |
47 | Cont <= 0; |
48 | Timebase <= '1'; |
49 | else
|
50 | Cont <= Cont + 1; |
51 | Timebase <= '0'; |
52 | end if; |
53 | end if; |
54 | end process FreqDiv; |
55 | |
56 | -- State Register Process
|
57 | -- Holds the current state of the FSM
|
58 | statereg: process (Clk,Rst) |
59 | begin
|
60 | -- Asynchronous Reset
|
61 | if Rst = '1' then |
62 | present_state <= st_wait; |
63 | elsif rising_edge(Clk) then |
64 | if Timebase = '1' then |
65 | if duracion = tstate then |
66 | present_state <= next_state; |
67 | duracion <= 0; |
68 | else
|
69 | duracion <= duracion + 1; |
70 | end if; |
71 | end if; |
72 | end if; |
73 | end process statereg; |
74 | |
75 | -- Define the Next-State Logic Process
|
76 | -- Will obtain the next state based on the inputs and current state
|
77 | fsm: process (present_state, Echo, tcount) |
78 | begin
|
79 | case present_state is |
80 | when st_wait => |
81 | if (Echo = '0') then |
82 | next_state <= st_trigger; |
83 | tstate <= ttrig; |
84 | else
|
85 | next_state <= st_echo; |
86 | tstate <= 1; |
87 | end if; |
88 | when st_trigger => |
89 | if (Echo = '0') then |
90 | next_state <= st_hold; |
91 | tstate <= 1; |
92 | else
|
93 | next_state <= st_echo; |
94 | tstate <= 1; |
95 | end if; |
96 | when st_hold => |
97 | if (Echo = '0') then |
98 | next_state <= st_hold; |
99 | tstate <= 1; |
100 | elsif (Echo = '1') then |
101 | next_state <= st_echo; |
102 | tstate <= 1; |
103 | end if; |
104 | when st_echo => |
105 | if (Echo = '0') then |
106 | next_state <= st_wait; |
107 | tstate <= twait; |
108 | tcount <= 0; |
109 | elsif (Echo = '1') then |
110 | next_state <= st_echo; |
111 | tstate <= 1; |
112 | tcount <= tcount + 1; |
113 | end if; |
114 | when others => |
115 | next_state <= st_wait; |
116 | tstate <= twait; |
117 | tcount <= 0; |
118 | end case; |
119 | end process fsm; |
120 | |
121 | tiempo <= tcount; |
122 | seg <= (tiempo/(1*10**6)); |
123 | centim <= CONV_STD_LOGIC_VECTOR((34320*seg), 8); |
124 | |
125 | -- If implementing a Moore Machine use the following process
|
126 | -- The output of a Moore Machine is determined by the present_state only
|
127 | output: process (present_state, centim) |
128 | begin
|
129 | case present_state is |
130 | when st_wait => |
131 | Trig <= '0'; |
132 | LEDs <= centim; |
133 | when st_trigger => |
134 | Trig <= '1'; |
135 | LEDs <= centim; |
136 | when st_hold => |
137 | Trig <= '0'; |
138 | LEDs <= centim; |
139 | when st_echo => |
140 | Trig <= '0'; |
141 | LEDs <= centim; |
142 | when others => |
143 | Trig <= '0'; |
144 | LEDs <= "11111111"; |
145 | end case; |
146 | end process output; |
147 | |
148 | end Ultrasonic_Final_Arch; |
--WARNINGS-- WARNING:Xst:737 - Found 1-bit latch for signal <tcount<14>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<13>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<12>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<11>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<10>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<9>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<8>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<7>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<6>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<5>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<4>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<3>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<2>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<1>>. 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. WARNING:Xst:737 - Found 1-bit latch for signal <tcount<0>>. 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. WARNING:Xst:2677 - Node <tcount_12> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_13> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_9> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_11> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_10> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_8> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_7> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_4> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_6> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_5> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_3> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_2> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_1> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_0> of sequential type is unconnected in block <Ultrasonic_Final>. WARNING:Xst:2677 - Node <tcount_14> of sequential type is unconnected in block <Ultrasonic_Final>.