Refactored version: cleaner with half the statements.
Also reduced the times to the actual targets, because the trace provides adequate feedback to demonstrate sub-millisecond resolution, as measured by the S7-1214C clcck. The cyclic interrupt blocks are possibly noticeable in the larger delay between the samples before and of the A rising edge.