Writing long PLC code routine without scan-time over-run
For those not familiar with PLCs, they are used in industrial automation and usually run with a program scan time of &lt; 1 to 20 ms. (OP's 200 ms scan time would be considered very slow.) The short and preferably fixed scan time gives a predictable and repeatable response time to a change in inputs and timing of outputs.



Figure 1. PLC scan cycle. Source: The Basics of PLC Operation.

The OP's question is how to handle a procedure that will extend the program scan time - without extending the program scan time!

There are several ways of tackling the problem:


Farm the task out to a speciality module - e.g., a PID temperature control module and let it perform asynchronously with regard to the PLC scan time. The speciality module can update some shared memory registers when complete.
The PLC can do the same trick in certain circumstances where a portion of each scan cycle is set aside for special function programs which execute until their time is up, hold the intermediate calculations, return control to the main program and pick up where they left off on the next cycle. This only works if the system can tolerate a slow update rate for these sub-programs.
Complete the task over several scan cycles. For example, I recently had to create an RS485 message checksum routine in an old PLC. I created a word counter, reset it to zero and every scan added a word to the checksum and incremented the counter until the complete message was summed. It took maybe twelve scans to complete the checksum but that was fine as the message transmit was once per second.