Simulating Similar Digital Devices - Randomizing to prevent Simulation Failure

From LTwiki-Wiki for LTspice

Simulations may contain LTspice's digital devices and these are often interconnected forming feedback loops (a simple NAND gate flipflop being a common example). When noiseless, identical devices are used in such loops, they can be driven to switch states at exactly the same instant in time causing the simulator to stop as reducing the time step does not resolve the conflict. The recommended technique to avoid this problem is to introduce some delay in the device via the "td" digital parameter. And indeed this works most of the time as the changing input no longer results immediately in a changing output.

However, this does not always work because complex interconnections and parallel equal delays may sometimes still result in an ambiguity. I have found that adding a small random element to each gate's delay parameter eliminates this possibility. This is done using the Monte Carlo function perhaps set up with a user function.

.func x(n) = {mc(n,0.1)} ; vary the parameter randomly over a +/-10% range around its nominal value

Then the delay in otherwise identical digital device would be specified as follows:

td={x(10n)} ; rather than simply td=10n

This results in a more realistic slight variation from device to device so that no two devices change state at the same time, thus avoiding potential conflicts.