> I'm looking for a means of phase shifting a square wave clock pulse by > 90 degrees. > > ______ ______ > | | | | > | | | | > ---- ---- ---- > ______ _____ > | | | | > | | | | > ---- ---- ---- One possible way (not necessarily the easiest) is to: 1) differentiate the signal by XORing each port reading with the previous one: || || || || || || || || ---- ------ --- ----- ---- 2) low-pass filter this new signal. If it is of unknown and variable frequency, the easiest way is to: a) count the number of samples between two 1s (= period) b) output 1/2 that many samples of 1, and 1/2 that many as 0. That effectively does generate a new waveform with the desired property: ___ __ ___ __ | | | | | | | | | | | | | | | | ---- --- -- ---- --- Wow, you have doubled the frequency! 3) XOR the output of 2) with the original input: _____ ______ | | | | | | | | -------- ----- ---- That's it!! You have shifted phase by 90 degree - on any single frequency input - no matter which frequency (as long as it is substantially lower than your sample rate). Your example waveform is a good example: it is not a pure "square sinus" :) All frequency deviations were preserved during the processing, and the output is a 90 degree shift, as good as the ASCII art resolution can get. Make sure that you read the port only ONCE per sample, and use the buffered values for processing. If you read it twice and the calculations base on two versions of it, the output might become flickery..