We can start with a few basic things and see how much they improve performance. Here are my first thoughts:- Why are there two frames in the Timed Loop? This really isn't necessary for anything. The main reason for using frames in a Timed Loop is to control the timing or priority of specific frames, which isn't happening here. First, I would get rid of the frames. You currently seem to be using the frame just so you can set a local variable then read it in the next frame. This leads me to point two:
- Avoid local variables. Use the data in the wire as much as possible, rather than using local variables. This will help performance, and avoids potential race conditions, which is where two parallel processes overwrite one local variable with conflicting data. For instance, with the Duty Cycle control, you set its value, then read it in the next frame. Simply wire that value through and delete those local variables. That control seems like it should really be an indicator, because the value is only set programmatically, not by by users. And you never need a local variable for it. Wherever possible, use a wire value directly, or use a feedback node or shift register to save a value from one iteration to the next. These are both much faster and more efficient memory-wise than locals.
Here's a quick mockup of some changes you could make. I make no guarantee that this does exactly what you want, so don't hook it up to the motor without taking a very close look! :) But it does demonstrate these ideas to an extent.These two ideas might not get you down to 1ms periods, but they're a step in the right direction.