Hi m-a-r-i-n,
I agree with zeppelin, why so complicated. ???
As far as the working is concerned, in the top line, 1st comparator is used to detect the crossing, the schmitt is to eliminate noise-chatter, 2nd comparator acts as a plain inverter to nagate the effect of "inverting scmitt trigger"...