Frequency generator is connected to Ctr0 and set to continuous acquisition of period. One tick is sent every 90 degrees the flywheel turns.
ao0 is a continuous output "dummy channel." I just wrote [0,0] to it so the ao/SampleClock is running. I'm using the ao/SampleClock to time my digital outputs. I set the output rate to 90*x times the frequency measured by Ctr0. x is arbitrarily set to 4 right now, so the ao/SampleClock in theory gives me 1 pulse for every 0.25 degrees the flywheel turns. Every time Ctr0 gives me an update, I update the ao sample clock rate.
My DO task uses a 90*x sample buffer for continuous output. Each element in the buffer ideally represents the output state at a known flywheel angle with a resolution of 1/x degrees.
Ctr1 is set to measure two edge separation between a reference digital output "at 45 degrees before a pulse" and the next reference tick from the flywheel (frequency generator). Basically, I placed a falling edge exactly halfway through the DO buffer on one line (used as a circular buffer, explained below). I use the two edge separation measurement and the current speed of the wheel to calculate where the falling edge
actually fell. The difference between the actual pulse location and where I tried to place the pulse is what I am calling "skew." "Total skew" is basically a summation of previous skews for use in the next step. I use the total skew to determine the starting index for the DO circular buffer. So if the current total skew is 5 degrees, then the first sample in my 90*x length DO sample buffer will fall at 5 degrees before one of the 90 degree reference marks. So for an event I want to happen at 3 degrees past a reference mark, I set that value at the location (5+3)*x in the sample buffer.
When the flywheel is moving at a constant rate (or close), the skew is less than 1/x degrees, meaning my outputs are timed as accurately as possible. If I raise (or lower) the frequency generator output frequency (flywheel speeding up or slowing down), and then let it stay ~constant at the new frequency, the error correction algorithm quickly re-aligns the DO sample buffer and the outputs are with 1/x degrees again.
The problem is
while the speed is changing, the measured skew is very bad (many degrees).