2012-05-19 28 views
2

我想爲我的解碼器模塊編寫一個tcl腳本(modelsim中的verilog) 我需要將'din'輸入值從000循環到111
這就是我現在想到的。Tcl二進制循環。二進制增量

vsim work.decode_shift 
add wave -noupdate -format Logic -radix binary /decode_shift/din 
add wave -noupdate -format Logic -radix binary /decode_shift/dout 
for { set i 0 } { $i==0111 } { incr i } { 
    force din $i 
    run 100 
} 
run @500ns 

它不起作用,因爲我不知道如何繞過一些類型的問題。我在做什麼錯,什麼是在tcl中增加二進制數字的正確方法?

+0

是不是隻是從0到7的循環?如果你需要把它變成二進制字符串,你可以使用格式。 – Julian

+0

是的,以十進制表示。但我如何分配一個小數到二進制din? – user1405165

+0

當我到達'2'時,我得到「錯誤:(vsim-4011)無效的力值:2」。 – user1405165

回答

0

不知道這是否會幫助你http://codepad.org/YX4nfMIS(轉載如下)它使用二進制表示字符串的升序列表。但這可能不是Verilog想要你的數據的方式。

set l { "000" "001" "010" "011" "100" "101" "110" "111"} 
for { set i 0} { $i<8 } { incr i } { 
puts [lindex $l $i] 
} 

或者正如多納爾指出

set l { "000" "001" "010" "011" "100" "101" "110" "111"} 
foreach i $l { 
    puts $i 
} 
+0

在這種情況下,最好使用'foreach';我喜歡'foreach'很多... –

+0

我也喜歡這個簡單的B/C,如果你想改成灰色代碼,這很容易。 –

2

與TCL,你不增加二進制數字。您將數字格式設置爲二進制。在此之前8.6,您使用的binary formatbinary scan組合來進行轉換,如下:

vsim work.decode_shift 
add wave -noupdate -format Logic -radix binary /decode_shift/din 
add wave -noupdate -format Logic -radix binary /decode_shift/dout 
for { set i 0 } { $i<=7 } { incr i } {  # Need non-binary literal 
    # Convert to 8 binary digits, store result in 「i_bin」 variable 
    binary scan [binary format c $i] B8 i_bin 

    force din $i_bin; # Assume takes 8 bits; [string range] to trim otherwise 
    run 100 
} 
run @500ns 

如果你有8.6,你可以這樣做,而不是:

vsim work.decode_shift 
add wave -noupdate -format Logic -radix binary /decode_shift/din 
add wave -noupdate -format Logic -radix binary /decode_shift/dout 
for { set i 0 } { $i<=0b111 } { incr i } { # Binary literal... 
    force din [format %04b $i]; # width 4 field, zero padded on left 
    run 100 
} 
run @500ns