You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ipynb-examples/example3-statemachine.ipynb
+24-8Lines changed: 24 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -48,16 +48,14 @@
48
48
"req_refund = pyrtl.Input(1, \"req_refund\")\n",
49
49
"\n",
50
50
"dispense = pyrtl.Output(1, \"dispense\")\n",
51
-
"refund = pyrtl.Output(1, \"refund\")\n",
52
-
"\n",
53
-
"state = pyrtl.Register(3, \"state\")\n"
51
+
"refund = pyrtl.Output(1, \"refund\")\n"
54
52
]
55
53
},
56
54
{
57
55
"cell_type": "markdown",
58
56
"metadata": {},
59
57
"source": [
60
-
" First new step, let's enumerate a set of constants to serve as our states\n"
58
+
" First new step, let's enumerate a set of constants for all possible states.\n"
61
59
]
62
60
},
63
61
{
@@ -77,6 +75,26 @@
77
75
" RFND = 5 # Issue refund.\n"
78
76
]
79
77
},
78
+
{
79
+
"cell_type": "markdown",
80
+
"metadata": {},
81
+
"source": [
82
+
" Define a `StateRegister`, which is just like a [Register](https://pyrtl.readthedocs.io/en/latest/basic.html#pyrtl.Register), except that it calculates\n",
83
+
" the [Register](https://pyrtl.readthedocs.io/en/latest/basic.html#pyrtl.Register)'s bitwidth from the largest possible `State`. `StateRegister`s also\n",
84
+
" display state names in traces by default.\n"
85
+
]
86
+
},
87
+
{
88
+
"cell_type": "code",
89
+
"execution_count": null,
90
+
"metadata": {
91
+
"collapsed": true
92
+
},
93
+
"outputs": [],
94
+
"source": [
95
+
"state = pyrtl.StateRegister(State, \"state\")\n"
96
+
]
97
+
},
80
98
{
81
99
"cell_type": "markdown",
82
100
"metadata": {},
@@ -216,8 +234,7 @@
216
234
"metadata": {},
217
235
"source": [
218
236
" Also, to make our input/output easy to reason about let's specify an order to the\n",
219
-
" traces with `trace_list`. We also use `enum_name` to display the state names (`WAIT`,\n",
220
-
" `TOK1`, ...) rather than their numbers (0, 1, ...).\n"
0 commit comments