Counting Really, Really Fast With An FPGA

fast

During one of [Michael]’s many forum lurking sessions, he came across a discussion about frequency counting on a CPLD. He wondered if he could do the same on an FPGA, and how hard it would be to count high clock rates. As it turns out, it’s pretty hard with a naive solution. Being a bit more clever turns the task into a cakewalk, with a low-end FPGA being able to count clocks over 500 MHz.

The simplest solution for counting a clock would be to count a clock for a second with a huge, 30-bit counter. This is a terrible idea: long counters have a lot of propagation delays. Also, any sampling would have to run at least twice as fast as the input signal – not a great idea if you’re counting really fast clocks.

The solution is to have the input signal drive a very small counter – only five bits – and sample the counter using a slower clock on board the FPGA. [Michael] used a 5-bit Gray code, getting rid of the problem of the ‘11111’ to ‘00000’ rollover of a normal binary counter.

Because [Michael] is using a 5 bit clock with 31 edges sampled at 32 MHz, he can theoretically sample a 992 MHz clock. There isn’t a chance in hell of the Spartan 6 on his Papilio Pro board ever being able to measure that, but he is able to measure a 500 MHz clock, something that would be impossible without his clever bit of code.

Dummy Load Uses Gray Code To Adjust Load In Small Steps

We’re not really interested in building a dummy load like this one for ourselves. But the concepts behind its design make for a nice little mental exercise as you read your way through the build description. [Pabr] wanted to build a dummy load which could be used to test a cheaply made gas generator. He wanted it to be as simple as possible, while providing a range of different loads. What he came up with is this monotonically adjustable load tester which uses gray codes for switching.

The video after the break does a good job of explaining the motivation for the design. Grey coding ensures that just one bit changes at a time. The example he uses to show the importance of this is when binary code transitions from 7 (0b0111) to 8 (0b1000). Three digits have been turned off and one has been turned on. Since he’s using light bulbs for his load this will turn off 700 Watts and then switch on 800W. That sudden jump in power draw can cause all kinds of problems with the generator’s engine. But the system he wired up will ensure that each flip of a switch moves in smaller steps.

Continue reading “Dummy Load Uses Gray Code To Adjust Load In Small Steps”