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 vending machine code?

Status
Not open for further replies.

icd

Junior Member level 3
Joined
Jan 25, 2012
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,506
Hi guys,
i know that it is hard to check others code. however im having a problem with my vending machine verilog code. the problem it gives me an output which is vend_out when the input is a quarter even though the price should be 40 cents to give the product. im attaching the code and the waveform. if u can find what is wrong ill appreciate.
======================================

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
module test(clk,coin,reset,change,vend_out);
 
input clk,reset;
input [2:0] coin;
output reg vend_out;
output reg [2:0] change;
 
parameter [3:0] idle=4'b0000;
parameter [2:0]nickle=3'b001;
parameter [2:0]dime=3'b010;
parameter [2:0]quarter=3'b011;
parameter [2:0]nickle_dime=3'b100;
parameter [2:0]two_dime=3'b101;
parameter [2:0]quarter_nickle=3'b110;
parameter [2:0]quarter_dime=3'b111;
 
parameter [3:0]five=4'b0001;
parameter [3:0]ten=4'b0010;
parameter [3:0]fifteen=4'b011;
parameter [3:0]tweenty=4'b0100;
parameter [3:0]tweenty_five=4'b0101;
parameter [3:0]thirty=4'b110;
parameter [3:0]thirty_five=4'b111;
parameter [3:0]fourty=4'b1000;
parameter [3:0]fourty_five=4'b1001;
parameter [3:0]fifty=4'b1010;
 
reg [3:0] state, next_state;
 
 
 
always@(posedge clk, negedge reset) begin
if(!reset)
state<=idle;
else state<=next_state;
end
 
always@(coin,state) begin
 
case(state)
idle: case(coin)
           nickle:begin
           next_state= five;
           change=3'b000;
           vend_out=1'b0;
           end
           dime:begin
           next_state= ten;
           change=3'b000;
           vend_out=1'b0;
           end
           quarter:begin
           next_state= tweenty_five;
           change=3'b000;
           vend_out=1'b0;
           end
           default:begin
           next_state=idle;
           change=3'b000;
           vend_out=1'b0;
           end
           endcase
five: case(coin)
            nickle: next_state=ten;
            dime : next_state=fifteen;
            quarter : next_state=thirty;
            default:next_state=nickle;
            endcase
ten: case(coin)
            nickle:next_state=fifteen;
            dime: next_state=tweenty;
            quarter:next_state=thirty_five;
            default:next_state=dime;
            endcase
fifteen:case(coin)
             nickle:next_state=tweenty;
             dime:next_state=thirty_five;
             quarter:begin
                     next_state=idle;
                     vend_out=1'b1;
           change=3'b000;
                     end
             default:next_state=fifteen;
             endcase
tweenty:case(coin)
             nickle:next_state=tweenty_five;
             dime:next_state=thirty;
             quarter:begin
             next_state=idle;
             change=nickle;
             vend_out=1'b1;
             end
             default:next_state=tweenty;
             endcase
tweenty_five:case(coin)
                  nickle:next_state=thirty;
                  dime:next_state=thirty_five;
                  quarter:begin
                  next_state=idle;
                  change=dime;
                  vend_out=1'b1;
                  end
                  default:next_state=tweenty_five;
                  endcase
thirty:case(coin)
            nickle:begin
            next_state=thirty_five;
            change=3'b000;
            vend_out=1'b0;
            end
            dime:begin
            next_state=idle;
            vend_out=1'b1;
            change=3'b000;
            end
            quarter:begin
            next_state=idle;
            change=nickle_dime;
            vend_out=1'b1;
            end
            default:next_state=thirty;
            endcase
thirty_five:case(coin)
                 nickle:begin
                 next_state=idle;
                 vend_out=1'b1;
                 change=3'b000;
                 end
                 dime:begin
                 next_state=idle;
                 change=nickle;
                 vend_out=1'b1;
                 end
                 quarter:begin
                 next_state=idle;
                 change=two_dime;
                 vend_out=1'b1;
                 end
                 default:next_state=thirty_five;
                 endcase
fourty:case(coin)
            nickle:begin
            next_state=idle;
            change=nickle;
            vend_out=1'b1;  
            end
            dime:begin
            next_state=idle;
            change=dime;
            vend_out=1'b1;
            end
            quarter:begin
            next_state=idle;
            change=quarter;
            vend_out=1'b1;
            end
            default:begin
            next_state=idle;
            vend_out=1'b1;
            change=3'b000;
            end
            endcase
fourty_five:case(coin)
            nickle:begin
            next_state=idle;
            change=dime;
            vend_out=1'b1;  
            end
            dime:begin
            next_state=idle;
            change=nickle_dime;
            vend_out=1'b1;
            end
            quarter:begin
            next_state=idle;
            change=quarter_nickle;
            vend_out=1'b1;
            end
            default:begin
            next_state=idle;
            change=nickle;
            vend_out=1'b1;
            end
            endcase
fifty:case(coin)
            nickle:begin
            next_state=idle;
            change=nickle_dime;
            vend_out=1'b1;  
            end
            dime:begin
            next_state=idle;
            change=two_dime;
            vend_out=1'b1;
            end
            quarter:begin
            next_state=idle;
            change=quarter_dime;
            vend_out=1'b1;
            end
            default:begin
            next_state=idle;
            change=dime;
            vend_out=1'b1;
            end
            endcase
default:begin
next_state=idle;
change=3'b000;
vend_out=1'b0;
end
endcase 
end                                                           
endmodule


====================
Untitled.png
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top