Appearance
Spec: Registers & Counters
Overview
Add a library of sequential logic building blocks including shift registers, parallel registers, and various counter types. These are essential components for building state machines, data pipelines, and timing circuits.
Motivation
Flip-flops are the atomic sequential elements, but practical designs always use groups of flip-flops working together. Providing pre-built registers and counters saves significant design time and reduces wiring errors, enabling users to focus on higher-level architecture.
Requirements
Functional Requirements
Registers
- N-bit Parallel Register: Load N bits simultaneously on clock edge. Configurable width (4/8/16).
- Shift Register (SISO): Serial-In Serial-Out, configurable length.
- Shift Register (SIPO): Serial-In Parallel-Out, configurable length.
- Shift Register (PISO): Parallel-In Serial-Out, configurable width.
- Shift Register (PIPO): Parallel-In Parallel-Out (universal shift register).
- Universal Shift Register: Supports left/right shift, parallel load, hold (controlled by mode select).
Counters
- Binary Up Counter: N-bit, synchronous, with terminal count output.
- Binary Down Counter: N-bit, synchronous, with borrow output.
- Binary Up/Down Counter: Direction controlled by input signal.
- BCD Counter (Decade): Counts 0–9, reset on overflow.
- Ring Counter: Circulating single-bit pattern.
- Johnson Counter: Twisted ring counter (2N states from N flip-flops).
- Programmable Counter: Loadable preset value, counts to zero, generates terminal count.
Common Features
- Synchronous Reset: All registers/counters support clock-synchronous reset.
- Asynchronous Clear: Immediate reset regardless of clock.
- Enable Input: Count/shift only when enabled.
- Cascade Support: Terminal count/carry output for chaining multiple counters.
Non-Functional Requirements
- All components support configurable clock edge (rising/falling).
- Visual state display shows current register/counter value during simulation.
- Components are compact enough to use in larger designs without excessive canvas space.
Design
Component Hierarchy
Components/Sequential/
├── Registers/
│ ├── ParallelRegister.cs
│ ├── ShiftRegisterSISO.cs
│ ├── ShiftRegisterSIPO.cs
│ ├── ShiftRegisterPISO.cs
│ └── UniversalShiftRegister.cs
└── Counters/
├── BinaryUpCounter.cs
├── BinaryDownCounter.cs
├── BinaryUpDownCounter.cs
├── BcdCounter.cs
├── RingCounter.cs
├── JohnsonCounter.cs
└── ProgrammableCounter.csState Model
csharp
public class BinaryUpCounter : Component
{
private int _count;
public int Width { get; set; } = 4; // configurable
public int MaxCount => (1 << Width) - 1;
public override void Evaluate()
{
if (AsyncClear.IsHigh) { _count = 0; }
else if (Clock.IsRisingEdge && Enable.IsHigh)
{
_count = (_count + 1) & MaxCount;
}
TerminalCount.SignalState = (_count == MaxCount) ? Signal.High : Signal.Low;
// Set output pins from _count bits...
}
}Rendering
- Rectangular body with component type label ("CTR", "SRG", "REG").
- Pin groups clearly separated: data, control (CLK, EN, CLR), outputs.
- During simulation: display current value in hex/decimal inside the component body.
Toolbox Organization
New sub-category under existing "Sequential" or new "Registers & Counters" category:
- Registers (Parallel, Shift variants)
- Counters (Binary, BCD, Ring, Johnson, Programmable)
Implementation Tasks
- Create
Components/Sequential/Registers/andCounters/directories. - Implement
ParallelRegisterwith configurable width. - Implement shift register variants (SISO, SIPO, PISO, Universal).
- Implement binary counters (Up, Down, Up/Down) with configurable width.
- Implement BCD decade counter.
- Implement Ring and Johnson counters.
- Implement Programmable counter with preset load.
- Add common control inputs (Enable, Clear, Reset) to all components.
- Create JSON shape definitions with value display area.
- Add components to toolbox and write documentation.
Risks & Open Questions
- Should width be configurable at runtime (property dialog) or fixed per component variant?
- Interaction with bus pins: should N-bit data ports use bus connections?
- How to display the internal state value — inside the component shape or as a tooltip?
- Should counters support custom count sequences (arbitrary modulus)?
Priority
High — Complements flip-flops and enables practical sequential design.