This is Qspice C++ code I can think of to implement your request. I assume during delay (500us), the comparator won’t need to trigger again (if it does, possibly the code is very complicated).
The most difficult part in your request is to switch state with a delay after main triggering event. This means you have to play with variable t (i.e. simulation time).
Another challenge is that, Qspice is adaptive time step, and we have to ensure timestep is reduced (i.e. use TTOL in Trunc() template) at 500us after main triggering event, or your delay event will not happen at exactly 500us.
In the code, you can see I added inst->lastOUT
and inst->lastDelayOut
, which is for above purpose.
In short, you have to fully understand purpose of these two template, as this is essential to achieve what you need.
Parent.ComparatorWithDelay.qsch (2.6 KB)
delaycompare.cpp (4.5 KB)