square wave generator on 20MHz
Assuming you want a pseudorandom sequence, a Linear Feedback Shift Register is an easy option. You can implement one with one or more shift registers, and a single XOR gate. Then, simply feed a clock signal into the latch pin to clock it. You can read the signal from any output pin on the shift register.

If you need a longer period than 511 bits, you can add additional shift registers.

The only complication to this is that you need to initialize the register with at least one bit set. One way to do this would be to use a shift register with output enable, tie one of the XOR gate's inputs to VCC with a pullup resistor, and use an RC circuit to ensure the output enable takes a short while to turn on after power is applied.

Here's an untested example:







simulate this circuit &ndash; Schematic created using CircuitLab