Thanks for reading this post and any suggestions you have.
I have a SNAP-PAC R1 and I need to run certain code periodically, say every 20ms or 50ms. The code is relatively simple…check a variable and enable/disable an output accordingly. You could think of the code as generating a PWM signal using software (I know of the 29HFi modules, but I am after a software, not a hardware solution). The strategy could be implemented as loops with either:
- “blocking” chart, using delays: turn on, delay 20ms, turn off, delay 20ms.
- “non-blocking” chart using timers: start timer, delay 1ms, if timer elapsed toggle output and reset timer, continue otherwise.
The above follows mainly some tips found under Greatest Hits - and mini-lessons
The above works well for a single output. Now assume I want to run 2 PWM signals whose rising and falling edges are synchronized. That is, when one signal goes ON, so should the other.
I am aware of the round robin with 1ms slice used by the SNAPPAC to run concurrent charts, so I am attempting to synchronize the charts within 1ms (ideal, but unlikely) or few milliseconds. This is tricky as neither the time required to start a chart nor the round robin loop time is constant. Even if the charts cannot be perfectly synchronized (say they start with 5ms difference), at least I would like to ensure that the time offset is constant, i.e. no jitter.
To some extent I am looking something like the “interrupt” function found in micro-controllers and some PLCs. That is, instead of waiting for the round robin to go around the loop (with variable loop times), some simple tasks can be executed exactly every X milliseconds.
I have implemented rendezvous/semaphores with some success (the starting edges are almost synchronized), but (I believe) the round robin causes the offset to jitter (best case) or to go out of sync (worst case).
I would love to hear if some experts have dealt with this issue before.