There can be many different types of comparators. Here, I have designed, a simple comparator with two 4 bit inputs 4 bit ripple down counter three output bits which says, whether one of the input is less,greater or equal to the second input. The code is written in behavioral model. Even though it checks for 4 bit inputs, the code can be extended for other input sizes with very small changes.
Verilog module – The inputs and output signals. Otherwise – check for A less than B. The codes when correctly simulated, will show you the following waveform in Xilinx ISE 13. The MOD of the ripple counter or asynchronous counter is 2n if n flip-flops are used. A counter may count up or count down or count up and down depending on the input control. The count sequence usually repeats itself. The complement of the count sequence counts in reverse direction.
If the uncomplemented output counts up, the complemented output counts down. If the uncomplemented output counts down, the complemented output counts up. There are many ways to implement the ripple counter depending on the characteristics of the flip flops used and the requirements of the count sequence. Asynchronous counters are slower than synchronous counters because of the delay in the transmission of the pulses from flip-flop to flip-flop.
With a synchronous circuit, all the bits in the count change synchronously with the assertion of the clock. Examples of synchronous counters are the Ring and Johnson counter. It can be implemented using D-type flip-flops or JK-type flip-flops. The D flip flop clock has a rising edge CLK input. Simulate and Breadboard the Ripple Counter circuit.