Since a square pulse has very high harmonics how to obtain a good resolution of pulses? For example if we have pulse train around 500 Hz could we treat it as a typical analog signal and sample it with 1500 Hz? But if we do it I suspect that we will not have clear rising edges since it square pulse has very high component. Of course we cannot sample with infinity but I!m wondering if there is a standard sampling rate for sampling square pulses to obtain a clear pulse shape for each pulse?
Assumption: The pulse timing and frequency are desired as input, not the actual waveform.
If the pulse train is known to be essentially just pulses, i.e. with nearly vertical rising and falling edges, then an analog waveform acquisition mechanism is sub-optimal.
Greater precision would be obtained by using a comparator or a Schmitt trigger, sending its output to a GPIO, and using interrupts on the GPIO to capture the rising and falling transitions against a high precision timer.
To avoid false triggering in case the pulse stream edges are noisy, use a comparator with a fair bit of hysteresis. That way, brief noise pulses on the rising and falling edges will not falsely trigger the GPIO interrupts.
It all depends on what you are going to use the sampled square wave for. The pictures below should give you an idea what you would get should you sample and then convert back to an analogue signal via a DAC: -
The above picture is rather idealistic in that it has an exact number of samples per period of the square wave - should you sample on the edge of the input squarewave it'll look worse, probably more like this: -
The faster you sample the better it will look but we can't decide for you.
The sample rate for a binary signal depends very much on what you know up front about the signal (from its definition), and what features of the signal you need to measure and preserve.
At the very least, the sample period needs to be strictly less than both the minimum high time and the minimum low time of the signal; otherwise you might miss a high pulse or a low pulse altogether.
But it's usually the timing of the edges that's the key feature of any pulse train. You need to decide for your application which timing measurements are crucial and what resolution you need on those measurements. That's what will ultimately determine the sample rate required.