Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Verilog compile error

Status
Not open for further replies.

EngAmira

Newbie level 6
Joined
Apr 21, 2015
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
183
Hello I 've some errors for the below verilog code for elevator control

------------------------------------------------------------------------------------



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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
module elevator_simple(clk,reset,call,requestedFloor,
elevatorLocation,moveDown,moveUp,stop,door_state);
 
input clk,reset,requestedFloor,elevatorFloor,call;
output moveDown,moveUp,stop;
inout door_state;
reg door_state;
parameter opened =0;
parameter closed=1;
typedef enum {opened=0,closed=1} door_state;
integer  reuestedFloor;   
integer  elevatorLocation;
wire  [4:0] call;
reg moveDown,moveUp,stop;
wire clk,reset;
//-----States aasignment---///
parameter F0_move=4'b0000,F0_open=4'b0001,F1_move=4'b0010,F1_open=4'b0011,F2_move=4'b0100,F2_open=4'b0101;
parameter F3_move=4'b0110,F3_open=4'b0111,F4_move=4'b1000,F4_open=4'b1001;
 
//F0_move :Elevator move toward GND floor
//F0_open:Elevator reached Gnd floor &door is open 
 
 
//-------------Internal Variables---------------------------
reg   [3:0]          state        ;
reg   [3:0]          next_state   ;
 
always @ (posedge clk or negedge reset)
begin 
if (reset == 1'b1) begin
    state <=  #1  F0_move;
             
end else begin
case (state)
    F0_move: if (door_state == closed) begin
            moveDown<=1;
         end else begin
            stop <=1;
                        #1
            state <=  F0_move;
         end
        if ((call==5'b01000) && (elevatorLocation==3)) begin // call from 3rd floor
                stop <=1;
            door_state <=opened;
             //#10;
            door_state <=closed;
            moveDown <=1;
        end  
        if ((call==5'b00100) && (elevatorLocation==2) ) begin
                stop <= 1 ;
            door_state <= opened;
            #10;
            door_state <= closed;
            moveDown <=1;
        end 
        if ((call==5'b00010) && (elevatorLocation==1)) begin
            stop <=1;
            door_state <=opened;
            #10;
            door_state <=closed;
            moveDown <=1;
        end 
         if(elevatorLocation==0)begin
            stop <=1;
            door_state <= opened;
            #10;
            state <=#1 F0_open;
        end else begin 
             #1 state <= F0_move;
        end
 
    F0_open:door_state <= closed;
            if ((requestedFloor ==0) || (call==5'b00001)) begin
            stop <=1;
            door_state=opened;
            #10;
            state <=#1 F0_open;
        end else if ((requestedFloor ==1) || (call==5'b00010))begin
            state <= #1 F1_move;
        end else if ((requestedFloor ==2) || (call==5'b00100))begin
            state <= #1 F2_move;
        end else if ((requestedFloor ==3) || (call==5'b01000))begin
            state <= #1 F3_move;
        end else if ((requestedFloor ==4) || (call==5'b10000))begin
            state <= #1 F4_move;
        end else begin state <= #1 F0_open;
        end
 
    
    F1_move: if (door_state ==closed) begin
            if (elevatorLocation >1)begin    //decide  move up or down
                moveDown <=1;
            end else begin
                moveUp <=1;
            end
        end else begin
            stop <=1;
            #1
            state<= F1_move;
        end
        if (moveDown ==1) begin
            if ((call==5'b01000) && (elevatorLocation==3)) begin // call from 3nd floor
                    stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveDown <=1;
            end  
            if ((call==5'b00100) && (elevatorLocation==2)) begin
                stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveDown <=1;
            end 
         end 
        if(elevatorLocation==1)begin
            stop <=1;
            door_state <= opened;
            #10;
            state <= F1_open;
        end else begin
            #1 
            state <= F1_move;
        end   
 
    
    F1_open:door_state <= closed;
            if ((requestedFloor ==1) || (call==5'b00010)) begin
            stop <=1;
            door_state <=opened;
            #10;
            state <= F1_open;
        end else if ((requestedFloor ==0) || (call==5'b00001))begin
             #1 state <=  F0_move;
        end else if ((requestedFloor ==2) || (call==5'b00100))begin
             #1 state <=  F2_move;
        end else if ((requestedFloor ==3) || (call==5'b01000))begin
             #1 state <=  F3_move;
        end else if ((requestedFloor ==4) || (call==5'b10000))begin
             #1 state <=  F4_move;
        end else begin 
             #1 state <=  F1_open;
        end     
    
 
 
    F2_move: if (door_state ==closed) begin
            if (elevatorLocation    >2)begin    //decide  move up or down
                moveDown <=1;
            end else begin
                moveUp <=1;
            end
        end else begin
            stop <=1;
            #1 state<= F2_move;
        end
        if (moveDown ==1) begin
            if ((call==5'b01000) && (elevatorLocation==3)) begin // call from 3rd floor
                    stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveDown <=1;
            end 
        end else begin 
            if ((call==5'b00010) && (elevatorLocation==1)) begin
                stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveUp <=1;
            end 
         end 
        if(elevatorLocation==2)begin
            stop <=1;
            door_state <= opened;
            #10;
            #1 state <= F2_open;
        end else begin 
            #1 state <= F2_move;
        end   
 
 
 
 
    F2_open:door_state = closed;
            if ((requestedFloor ==2) || (call==5'b00100)) begin
            stop <=1;
            door_state <=opened;
            #10;
            state <= F2_open;
        end else if ((requestedFloor ==0) || (call==5'b00001))begin
            #1 state <=  F0_move;
        end else if ((requestedFloor ==1) || (call==5'b00010))begin
            #1 state <=  F1_move;
        end else if ((requestedFloor ==3) || (call==5'b01000))begin
            #1 state <=  F3_move;
        end else if ((requestedFloor ==4) || (call==5'b10000))begin
            #1 state <=  F4_move;
        end else begin 
            #1 state <=  F2_open;
        end     
        
 
 
    F3_move: if (door_state ==closed) begin
            if (elevatorLocation    >3)begin    //decide  move up or down
                moveDown <=1;
            end else begin
                moveUp <=1;
            end
        end else begin
            stop <=1;
            state<=#1 F3_move;
        end
        if (moveUp ==1) begin
            if ((call==5'b00010) && (elevatorLocation==1)) begin // call from 1st floor
                    stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveUp <=1;
            end  
            if ((call==5'b00100) && (elevatorLocation==2)) begin
                stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveUp <=1;
            end 
         end 
        if(elevatorLocation==3)begin
            stop <=1;
            door_state <= opened;
            #10;
            state <=#1 F3_open;
        end else begin 
            state <=#1 F3_move;
        end   
 
 
    F3_open:door_state = closed;
            if ((requestedFloor ==3) || (call==5'b01000)) begin
            stop <=1;
            door_state=opened;
            #10;
            state <=#1 F3_open;
        end else if ((requestedFloor ==0 )|| (call==5'b00001))begin
            state <= #1 F0_move;
        end else if ((requestedFloor ==1) || (call==5'b00010))begin
            state <= #1 F1_move;
        end else if ((requestedFloor ==2) || (call==5'b00100))begin
            state <= #1 F2_move;
        end else if ((requestedFloor ==4) || (call==5'b10000))begin
            state <= #1 F4_move;
        end else begin state <= #1 F3_open;
        end 
 
    F4_move: if (door_state ==closed) begin
            moveUp <=1;
        end else begin
            stop <=1;
            state<=#1 F4_move;
        end
        if ((call==5'b00100) && (elevatorLocation==2)) begin // call from 2nd floor
                    stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveUp <=1;
            end  
            if ((call==5'b01000) && (elevatorLocation==3)) begin
                stop <=1;
                door_state <= opened;
                #10;
                door_state <= closed;
                moveUp <=1;
            end 
         end 
        if(elevatorLocation==4)begin
            stop <=1;
            door_state <= opened;
            #10;
            state <=#1 F4_open;
        end else begin 
            state <=#1 F4_move;
        end   
 
 
    F4_open:door_state = closed;
            if ((requestedFloor ==4) || (call==5'b10000)) begin
            stop <=1;
            door_state<=opened;
            #10;
            state <=#1 F4_open;
        end else if ((requestedFloor ==0) || (call==5'b00001))begin
            state <= #1 F0_move;
        end else if ((requestedFloor ==1) || (call==5'b00010))begin
            state <= #1 F1_move;
        end else if ((requestedFloor ==2)|| (call==5'b00100))begin
            state <= #1 F2_move;
        end else if ((requestedFloor ==3) || (call==5'b01000))begin
            state <= #1 F3_move;
        end else begin state <= #1 F4_open;
        end 
 
    default :  #1 state <=    F0_move;
 
 
 endcase
end
end
endmodule


---------------------------------------------------------------------------------------


Errors is :

** Error: (vlog-13032) C:/Modeltech_pe_edu_10.4a/examples/Elevator cnt.v(12): near "{": Syntax error.

** Error: (vlog-13069) C:/Modeltech_pe_edu_10.4a/examples/Elevator cnt.v(44): near "if": syntax error, unexpected if.

** Error: (vlog-13025) C:/Modeltech_pe_edu_10.4a/examples/Elevator cnt.v(74): near ":": Syntax error. Statement labels are only allowed in SystemVerilog.

** Error: (vlog-13025) C:/Modeltech_pe_edu_10.4a/examples/Elevator cnt.v(92): near ":": Syntax error. Statement labels are only allowed in SystemVerilog.

** Error: C:/Modeltech_pe_edu_10.4a/examples/Elevator cnt.v(106): (vlog-13205) Syntax error found in the scope following 'door_state'. Is there a missing '::'?

Can ay one help??
 

You didn't specify which line is line12, but typedef and enum is only allowed in SystemVerilog. Change the file extension to *.sv

There will be more errors after that.
 
You are trying to implement the states as if you were coding a software implementation. # delay should not be used in synthesizable code, there is no equivalent hardware representation of such a delay. The following lines:
Code:
            stop <=1;
            door_state <=opened;
            #10;
            door_state <=closed;
            moveDown <=1;
are all done in parallel and the door_state <= closed assignment is just postponed in SIMULATION only. In hardware only closed would be used as you are assigning that after opened (only the last assignment to a specific variable will be used).

Your reset is wrong, you have an active low reset detection negedge reset and are checking for an active high reset if (reset == 1'b1)

Once stop goes active it's never set back to 1'b0 anywhere in the code.

You also didn't properly apply begin-end blocks in your FSM so you're getting all those label warnings (which aren't labels, but are the case items).

You really need to read a better book/tutorial than the one you are using because the code you are writing is not good.
 

ok , so what is the replacement of this enum type in verilog??

- - - Updated - - -

You are trying to implement the states as if you were coding a software implementation. # delay should not be used in synthesizable code, there is no equivalent hardware representation of such a delay. The following lines:
Code:
            stop <=1;
            door_state <=opened;
            #10;
            door_state <=closed;
            moveDown <=1;
are all done in parallel and the door_state <= closed assignment is just postponed in SIMULATION only. In hardware only closed would be used as you are assigning that after opened (only the last assignment to a specific variable will be used).

Your reset is wrong, you have an active low reset detection negedge reset and are checking for an active high reset if (reset == 1'b1)

Once stop goes active it's never set back to 1'b0 anywhere in the code.

You also didn't properly apply begin-end blocks in your FSM so you're getting all those label warnings (which aren't labels, but are the case items).

You really need to read a better book/tutorial than the one you are using because the code you are writing is not good.



so If I need to implement that the elevator door will open for 10 sec then it go close again in sequential manner how could I make it ??
 

ok , so what is the replacement of this enum type in verilog??

- - - Updated - - -





so If I need to implement that the elevator door will open for 10 sec then it go close again in sequential manner how could I make it ??

use a counter, set the counter limit based on your clock frequency...

ie, clock time period* number of clock cycle to reach counter limit =10sec


regards
 

I thought that if and case statement are sequential statement so statements inside them executed sequentially , am I right ???
 

I thought that if and case statement are sequential statement so statements inside them executed sequentially , am I right ???

Nope, you better read a better tutorial.
 

Nope, you better read a better tutorial.

https://www.csee.umbc.edu/portal/help/VHDL/verilog/sequential.html#block

this link said that any statement between begin and end executed sequentially (unnamed block ) what do you see?? Untitled.png
 

https://www.csee.umbc.edu/portal/help/VHDL/verilog/sequential.html#block

this link said that any statement between begin and end executed sequentially (unnamed block ) what do you see??View attachment 134073

you are referring this page https://www.csee.umbc.edu/portal/help/VHDL/verilog/sequential.html

it will execute as you expect, when there is blocking assignments.... which will not recommended in verlog
(if you are using a clock ie you are using it inside always block) ..

please refer blocking & non blocking assignments...

and please dont refer the link above...its not at all verilog coding style....(they are using a for loop like a software program)

refer asicword & test bench.in for some verilog examples

this is what you need to do..
Nope, you better read a better tutorial.
by ads_ee

regards
 
Last edited:

Sequential as in "the order written" not as in "a sequence of events", i.e. FSM,, counters, etc.

You are trying to implement a sequence of events in time, using assignments in the order written. Not going to work

Regardless what many think (especially software programmers) Verilog is not a software programming language, only a subset of it will behave exactly like software and will likey end up as unsynthesizable or become a very large slow circuit.
 

ok , so what is the replacement of this enum type in verilog??

that would be a series of localparams

also review your use of params, that is not what they are meant for. review your use of integers too. remove all "#" from your code. that is not how you describe hardware.

this, in fact, is a key distinction that many cannot see. verilog is used to describe hardware, not to code hardware. you have to adhere to the templates that will generate good logic. learn those templates ASAP.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top