loops - 如何在 Verilog 中停止无限循环
问题描述
我试图将数字作为模块的输入:0-127。这就是我使用 for 或 while 循环的原因。但是,我的问题是循环永远不会结束。我正在使用 Verliog,所以我不能使用 break,系统 Verliog 正在使用 whis。我还使用 EDA Playground 来编译我的代码。你知道我该如何解决这个问题吗?任何帮助表示赞赏。
module TOP();
parameter ENDTIME=40000;
reg [63:0] inputdata1; // is an 63-bit "register", or variable
reg [6:0] AddressR,AddressW;
reg cen,clk=1'b0, R_W, reset;
wire [63:0] Data_Out;
integer count;
wire Que_Full=0, Que_Last=0, Que_Empty=1;
//call module for data I/O
process_data process_data( inputdata1, AddressR, AddressW, R_W , cen, clk, reset, Data_Out, Que_Full, Que_Last, Que_Empty);
always #10 clk=~clk; //every 10 ->change
initial
begin
$dumpfile("ALU.vcd");
$dumpvars(0);
$display("\t\ttime\tclk\t\t\tinputdata1\t\tData_Out\t\tAddressR");
$monitor($time, "\t%d\t%d\t%d\t%d",clk,inputdata1,Data_Out,AddressR);
cen=1'b1; //chip enabled
count = 0;
R_W=1'b1; //read
AddressR=7'b0000_000;
//input
Execute loop till count is 127. exit at count 128
for (count=0; count < 128; count=count+1) //while(count<128)
#10
begin
inputdata1 = count;
AddressR=AddressR+7'b0000_001;
//count = count + 1;
end
#ENDTIME
$display("-------------- THE SIMULATION FINISHED ------------");
$finish;
end
endmodule
我从 Icarus 编译器得到的结果是:
time clk inputdata1 Data_Out AddressR
0 0 x x 0
10 1 0 x 1
20 0 1 x 2
30 1 2 x 3
40 0 3 x 4
50 1 4 x 5
60 0 5 x 6
70 1 6 x 7
80 0 7 x 8
90 1 8 x 9
100 0 9 x 10
110 1 10 x 11
120 0 11 x 12
130 1 12 x 13
140 0 13 x 14
150 1 14 x 15
160 0 15 x 16
170 1 16 x 17
180 0 17 x 18
190 1 18 x 19
200 0 19 x 20
210 1 20 x 21
220 0 21 x 22
230 1 22 x 23
240 0 23 x 24
250 1 24 x 25
260 0 25 x 26
270 1 26 x 27
280 0 27 x 28
290 1 28 x 29
300 0 29 x 30
310 1 30 x 31
320 0 31 x 32
330 1 32 x 33
340 0 33 x 34
350 1 34 x 35
360 0 35 x 36
370 1 36 x 37
380 0 37 x 38
390 1 38 x 39
400 0 39 x 40
410 1 40 x 41
420 0 41 x 42
430 1 42 x 43
440 0 43 x 44
450 1 44 x 45
460 0 45 x 46
470 1 46 x 47
480 0 47 x 48
490 1 48 x 49
500 0 49 x 50
510 1 50 x 51
520 0 51 x 52
530 1 52 x 53
540 0 53 x 54
550 1 54 x 55
560 0 55 x 56
570 1 56 x 57
580 0 57 x 58
590 1 58 x 59
600 0 59 x 60
610 1 60 x 61
620 0 61 x 62
630 1 62 x 63
640 0 63 x 64
650 1 64 x 65
660 0 65 x 66
670 1 66 x 67
680 0 67 x 68
690 1 68 x 69
700 0 69 x 70
710 1 70 x 71
720 0 71 x 72
730 1 72 x 73
740 0 73 x 74
750 1 74 x 75
760 0 75 x 76
770 1 76 x 77
780 0 77 x 78
790 1 78 x 79
800 0 79 x 80
810 1 80 x 81
820 0 81 x 82
830 1 82 x 83
840 0 83 x 84
850 1 84 x 85
860 0 85 x 86
870 1 86 x 87
880 0 87 x 88
890 1 88 x 89
900 0 89 x 90
910 1 90 x 91
920 0 91 x 92
930 1 92 x 93
940 0 93 x 94
950 1 94 x 95
960 0 95 x 96
970 1 96 x 97
980 0 97 x 98
990 1 98 x 99
1000 0 99 x 100
1010 1 100 x 101
1020 0 101 x 102
1030 1 102 x 103
1040 0 103 x 104
1050 1 104 x 105
1060 0 105 x 106
1070 1 106 x 107
1080 0 107 x 108
1090 1 108 x 109
1100 0 109 x 110
1110 1 110 x 111
1120 0 111 x 112
1130 1 112 x 113
1140 0 113 x 114
1150 1 114 x 115
1160 0 115 x 116
1170 1 116 x 117
1180 0 117 x 118
1190 1 118 x 119
1200 0 119 x 120
1210 1 120 x 121
1220 0 121 x 122
1230 1 122 x 123
1240 0 123 x 124
1250 1 124 x 125
1260 0 125 x 126
1270 1 126 x 127
1280 0 127 x 0
1290 1 127 x 0
1300 0 127 x 0
1310 1 127 x 0
1320 0 127 x 0
1330 1 127 x 0
1340 0 127 x 0
1350 1 127 x 0
1360 0 127 x 0
1370 1 127 x 0
1380 0 127 x 0
1390 1 127 x 0
1400 0 127 x 0
1410 1 127 x 0
1420 0 127 x 0
1430 1 127 x 0
1440 0 127 x 0
1450 1 127 x 0
1460 0 127 x 0
1470 1 127 x 0
1480 0 127 x 0
1490 1 127 x 0
1500 0 127 x 0
1510 1 127 x 0
1520 0 127 x 0
1530 1 127 x 0
1540 0 127 x 0
1550 1 127 x 0
1560 0 127 x 0
1570 1 127 x 0
1580 0 127 x 0
1590 1 127 x 0
1600 0 127 x 0
1610 1 127 x 0
1620 0 127 x 0
1630 1 127 x 0
1640 0 127 x 0
1650 1 127 x 0
1660 0 127 x 0
1670 1 127 x 0
1680 0 127 x 0
1690 1 127 x 0
1700 0 127 x 0
1710 1 127 x 0
1720 0 127 x 0
1730 1 127 x 0
1740 0 127 x 0
1750 1 127 x 0
1760 0 127 x 0
1770 1 127 x 0
1780 0 127 x 0
1790 1 127 x 0
1800 0 127 x 0
1810 1 127 x 0
1820 0 127 x 0
1830 1 127 x 0
1840 0 127 x 0
1850 1 127 x 0
1860 0 127 x 0
1870 1 127 x 0
1880 0 127 x 0
1890 1 127 x 0
1900 0 127 x 0
1910 1 127 x 0
1920 0 127 x 0
1930 1 127 x 0
1940 0 127 x 0
1950 1 127 x 0
1960 0 127 x 0
1970 1 127 x 0
1980 0 127 x 0
1990 1 127 x 0
2000 0 127 x
.......
解决方案
原始问题:
您需要删除此行:
count = count + 1;
for
循环会自动count
为您递增。您不应该在循环中修改循环迭代器变量。
问题发生重大变化后:
当您达到 127 时,循环结束。然后您在循环之后添加一个很长的延迟,其中计数保持在 127,正如预期的那样。也许您认为模拟处于无限循环中,因为您的日志文件一直显示计数为 127。然后模拟在时间 41270 结束。您在 EDAplayground 上确认了此行为。
推荐阅读
- c# - 我如何在 webBrowser 中使用 c# 执行点击事件
- python - Python中处理负整数的问题
- python - 使用 ctypes 在 python 中分配的 C 中写入缓冲区,并在 python 中再次读回
- php - 如何防止以操作形式调用的 PHP 文件显示为页面?
- python - Docker,Flask,SQLAlchemy:ValueError:int() 的无效文字,基数为 10:'None'
- spring-boot - 如果通过 Zuul API 网关发送请求,则缺少授权标头
- c++ - 在 ns3 中使用 tcp 发送文件时未在跟踪文件中获取任何数据
- json - neo4j 插入复杂的 json 与节点之间的关系相同
- ios - IOS 上的 Ionic 3 背景音频
- ruby-on-rails - ruby rails:索引中的 ArgumentError:键必须是 32 个字符