In this article an algorithm for optimized realtime sensing of crashes for control purposes is presented. The algorithm is based on time-scale wavelet theory and edge-detection. It is designed for the control of the sawtooth instability, a relaxation oscillator, in fusion plasmas. However, in principle, it can be applied to any periodic crash, measured with any temporally resolved data. It is argued that the detection of crashes has considerably less delay and detects crashes with higher temporal accuracy than other linear methods; this holds especially for very noisy measurements.