This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
using_tcl_for_fame_and_fortune [2020/02/07 14:50] nelson created |
using_tcl_for_fame_and_fortune [2020/02/07 15:22] (current) nelson [Using Looping to Exercise All Combinations of 1's and 0's] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Using TCL for Fame and Fortune ====== | ====== Using TCL for Fame and Fortune ====== | ||
| - | If you hate to type repetitive TCL commands to exercise your design, here is are some ideas. | + | If you hate to type repetitive TCL commands to exercise your design, here are some ideas. |
| It turns out TCL is a full-featured programming language (even if it is verbose and perhaps clunky). | It turns out TCL is a full-featured programming language (even if it is verbose and perhaps clunky). | ||
| But, once you find some examples to cannibalize, it can be pretty easy to create very compact simulation scripts. | But, once you find some examples to cannibalize, it can be pretty easy to create very compact simulation scripts. | ||
| - | ====Using Looping to Exercise All Combinations of 1's and 0's | + | ====Using Looping to Exercise All Combinations of 1's and 0's==== |
| The following code sample shows how to loop across all combinations of 4-bits (from 0000 to 1111). | The following code sample shows how to loop across all combinations of 4-bits (from 0000 to 1111). | ||
| Line 28: | Line 28: | ||
| } | } | ||
| | | ||
| - | Or, it could be simpler: | + | Or, it could be much simpler: |
| set i 0 | set i 0 | ||
| Line 40: | Line 40: | ||
| } | } | ||
| - | And, if what you are forcing is itself a 4-bit quantity, this works just fine: | + | Or, if what you are forcing is itself a 4-bit quantity, it requires a function to be defined first to do the integer to binary conversion: |
| + | proc dec2bin i { | ||
| + | #returns a string, e.g. dec2bin 12 => 1100 | ||
| + | set res {} | ||
| + | while {$i>0} { | ||
| + | set res [expr {$i%2}]$res | ||
| + | set i [expr {$i/2}] | ||
| + | } | ||
| + | if {$res == {}} {set res 0} | ||
| + | return $res | ||
| + | } | ||
| + | | ||
| set i 0 | set i 0 | ||
| while {$i < 16} { | while {$i < 16} { | ||
| - | add_force mySignal $i | + | add_force a [dec2bin $i] |
| + | run 10ns | ||
| + | incr i | ||
| + | } | ||
| + | |||
| + | And, if you prefer for-loops: | ||
| + | |||
| + | for {set i 0} {$i < 16} {incr i} { | ||
| + | add_force mySignal [dec2bin $i] | ||
| run 100ns | run 100ns | ||
| incr i | incr i | ||
| } | } | ||