analogWrite freeze the arduino

To paraphrase your problem:

smallpoul:
My sketch is doing weird things. It uses the String class a lot.

Stop using the String class. It can cause memory corruption which can make your sketch do weird things.