Sine to sqare waveform but with variable peak-to-peak input
First, use a comparator rather than an op-amp. They're designed for your application and don't latch up when the input gets close to the rail voltages.


  Max RMS output generated voltage = 45 volt, at the maximum velocity.


A resistor divider will do the job. Add a diode between ground and the input (pointing up in your diagram) to prevent the voltage going negative. Make the VREF close to ground so you can detect low-amplitude signals accurately.


  Max output generated frequency=50 kHz at the maximum velocity.


Shouldn't be a problem.


  A square signal circuit output to be sent to the micro min = 0 V, max = 5 V.


Most comparators have an open-collector output so a pull-up resistor to the 5 V supply will give you the required square-wave signal.


  Only unipolar voltage to 12 V or 5 V to supply the circuit.
  So I thought to a Schmitt trigger op-amp comparator like this.


So far, so good - but use a proper comparator.


  Due to the variable peak to peak signal I cannot fix the two comparator's threshold VH, VL.


You only need one comparator. Since the voltage is alternating you can set the threshold very close to 0 V.


  I have to scale (I think) the voltage produced by the generator to avoid to damage the op-amp. Here could be sufficient a voltage divider to the non inverting pin, fixing the divider resistors to have a value that at the maximum RMS signal 40 V, produce for example Vcc.


You've got it. Don't forget that peak will be \$ 40\sqrt 2 \$.