Implement the controller using three one-hot state signals:
IDLE = I
RUN = R
DONE = D
The provided datapath generates:
Fourth = Count[1] · Count[0]
Fourth_Valid = Fourth · Sample_Valid
Use these signals with Start to generate the next controller state:
I_next = I · Start' + D
R_next = I · Start + R · Fourth_Valid'
D_next = R · Fourth_Valid
Generate the datapath control outputs as:
Init_Clear = I · Start
Sum_Load = R · Sample_Valid
Count_Enable = R · Sample_Valid · Fourth'
Generate the external status outputs as:
Busy = R
Done = D
When Start = 1 in IDLE, Init_Clear initializes the provided datapath and the controller enters RUN.
While in RUN, every valid sample activates Sum_Load.
For the first three valid samples, Count_Enable = 1, so the provided counter advances.
When Count = 11, Fourth = 1. If the current sample is valid, Fourth_Valid = 1.
The fourth valid sample still activates Sum_Load, so it is included in the final sum. However, Count_Enable = 0, preventing a normal counter increment.
The controller then enters DONE.
In DONE:
Busy = 0
Done = 1
The provided datapath automatically restores the sample counter for the next transaction.
On the next rising edge, the controller returns to IDLE.