Electronic – Problem while simulating a 12 bit counter using 3x 4bit 74163 counters

digital-logicfpga

I have attached a circuit which includes three counters which are the IC 74163. This specific IC is a 4 bit counter. I want to make a bigger counter which will be able to count 752 steps with an input frequency of 20 MHz. The fact is that my counter does not work at all and I would like to know what do I make a wrong. Is there something that I do not see? In this case the preset is 4095 – 1 – 752 (steps) = 110100001110. Unfortunately the system does not count correctly and I am sure that there something wrong with my design. Could please someone give me advice?

The input signal is 26.6 kHz and the frequency of the system is 20 MHz. Also the reason for doing something like that is because I am trying to use an external PLL in cooperation with my FPGA design and the circuit below is used to make the division which is needed fout = N * fin and theoretically I want to make a division of 752 so I need 752 steps. The system does not work well but with another preset value it worked. Despite the fact that I get the 20 MHz I need digitally I want to understand completely why the counter that I have designed does not work properly.

The reason for which I do not get a bigger counter is that I have to simulate the system using parts available from my FPGA's software library. Is there a possibility of overflow or something like that, which I cannot see?

Schematic

Best Answer

Doh! Facepalm time. I completely missed the fact that your circuit is an FPGA, so ALL or my timing analysis was wrong. Well, OK. Scratch the timing. What remains is correct, so here is the new, improved, and maybe to the point version.

The simplest answer is that this is not going to work as you think. The first problem is that your preset is wrong. Instead of calculating 4095 - 1 - 752, you should have calculated 4095 + 1 - 752. You had the right idea (essentially recognizing that 0 is a state), but you got the sign wrong. That is, you were trying to calculate 4095 - (752 - 1).

Another problem is that you are using the last ripple carry to reset your counters. This is wrong on 2 counts. First, what you want to do is to load the presets which you calculated. Second, the counter will reset anyways, since the next count after FFF is 000. The most elegant way to load your preset is to change your preset to 1000 1000 1011, and use the QC output to drive your preset pins. Essentially you are presetting your counter to one count more than previously, then letting the rollover from FFF to 000 provide the active low signal you need to preset the counters. This eliminates the inverter you used.

In the absence of activity on the load lines, what will happen with this circuit is that it will produce on phase_three a 50 nsec pulse at a 4.88 KHz (20 MHz / 4096) frequency. That this is apparently not the case, since you say you're getting good outputs for a different preload, seems clear. If you are not sending pulses on the preload line, I have no faint idea why the preload setting would make a difference.

Also, be aware that RCOs are not clean. They will show spikes at intermediate counts. This is true for discrete logic, and in some respects even more so for FPGA logic.

Finally, a note of caution, if you are going to use an external preload as shown, you will occasionally get weird results. This is caused by the preset releasing too close to the rising clock edge, so that some counters will (occasianally) respond in a flakey manner. The term for this is metastability, and if you are going to synchronise any sort of clocked logic to external events, you need to do a little studying.

Related Topic