Hello everyone,
I am working on a project in LTspice where I am using the .machine
directive to create a state machine. My goal is to detect the rising (leading) or falling edge of a signal within the .rule
conditions to trigger state transitions.
For example, I want to have a rule like this:
.machine
.state X
.state Y
.rule X Y {edge detection condition}
.endmachine
Where {edge detection condition}
would allow me to detect a rising or falling edge of a certain signal (e.g., V(SAMPLE)
).
I understand how to use basic voltage comparisons for state transitions, but I am not sure how to implement edge detection directly within the .rule
conditions. Is there a way to detect edges in LTspice using the .rule
command, or is there a workaround that could be used to achieve this functionality?
Any advice or examples from your experience would be greatly appreciated!
Thanks in advance!
I solved the problem as follows:
Added a B source (voltage-controlled voltage source): I set the function to take the time derivative of the clock signal using the equation V=ddt(V(clock))
. This allows me to track both the rising (leading) and falling edges of the clock signal.
I solved the problem as follows:
Added a B source (voltage-controlled voltage source): I set the function to take the time derivative of the clock signal using the equation V=ddt(V(clock))
. This allows me to track both the rising (leading) and falling edges of the clock signal.
I was tinkering with the .machine statement for the first time recently and struggled with the same thing. Ultimately I also implemented a "dummy state" solution. Each "real" state has a corresponding "dummy" state which precedes it. To transition from the dummy state to its corresponding real state, all conditions which could cause transitions from the real state must be false. This prevents multiple transitions from single events.
It feels like there should be a much easier way to do this though.I presume most state machines will be edge-sensitive, not level-sensitive.
I thought the "tripdt" parameter would be useful for preventing extra transitions, but so far I have yet to observe it having any effect on behavior. Maybe I'm misunderstanding its purpose. It's only mentioned offhand in the documentation, without any examples.