Actually, when I am writing this article, there is not much tutorial on nmigen. It is not complete in nmigen tutorial. In this tutorial, I will try my best to elaborate a FSM circuit.
Finite state machine
Let’s say… I want a circuit which samples data every 128+1 clock cycles. Then I need a initial state to reset every signal and one state to add a counter.
cnt is a 8-bit counter and data_in is a input I/O port and data_out is a output I/O port.
If cnt[8] == 1 which means counting from 0 to 128 and sampling data_in.