I solved the staggering of ALU execution step and fetch of the next instruction.
The state machine diagram is updated accordingly.
The problem was in timings of propagation delays. All the registers are clocked on rising edge, and the update of gpr and IR should have been at the same exact moment. But in reality, there are several gate delays between rising edge of system clock signal, and the latching of particular register in the register file. On the other hand, instruction register is updated right at the system clock rising edge, thus control signals for the next instruction propagate at the time of latching registers for previous instruction, leading to wrong operation results.
To solve this problem, I introduced "Shadow" register right after the Instruction register, that is latched some time after the IR:
This new register is clocked with 90 degrees shift relative to system clock, so that instruction word is propagated to decoder a quarter of system clock period later, when all other registers are long latched to their values.
Here is clock diagram for this:
The system clock is derived from base clock by dividing its period by 2, and Shadow register clock signal is AND between base and system clock signals.
I figured, there is no particular need to make additional clock phase -- all that needed is a sufficient delay between Instruction Register and Shadow Register latch signals. This can be accomplished by several consecutive NOT gates in the latching signal path for the Shadow Register. While tinkering with simulation, it become clear that delay of just 2 gates is sufficient. In real circuit it may better be done with longer delay, say 6 NOT gates, it will be 20-30 ns.
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.