I participated online in a 24h hackathon organised by Nokia in Krakow this year. The event wasn't so much a hackathon but rather a coding competition exclusively for FPGAs. I registered with two other friends but for life reasons they both had to drop out near the beginning of the competition. Despite this I completed 7 of the 10 tasks because it was fun and I wanted to learn. For this reason I also decided not to spend the full 24 hours on this competition but only my free time.
There were ten tasks related to the theme of rescuing a Mars colony town which suffered from technical problems. We were handed a Quartus project with a project already set-up with lots of scaffolding for the judge system. This made it so we could focus on small self-contained problems which made it a lot easier. On top of that, there were no requirements or points to win for efficient implementations. It is still more fun to aim for one though. I have only had experience with VHDL, but the template solutions were written in SystemVerilog. Luckily the provided scaffolding made this no problem. It turns out that there's pretty much a 1-to-1 mapping between VHDL and SystemVerilog at least when it comes down to actual implementations. I can image the differences are much larger for project organisation and validation. The tasks themselves weren't difficult either. Solving them in a regular programming language would take just a couple minutes. The more difficult part was getting it to run on an fpga e.g. timing constraints, pipelining and math with real numbers.
The problem statement asks to calculate gray values from 24-bit RGB using the Y'IV/Y'IQ model.
The result of the exact calculation should be rounded to the nearest integer to return it as a byte.
This was straightforwardly solved by using 12 extra fractional bits (we need at least 10 for the 3 fractional digits). The rounding can be accomplished by adding
The input was a 5x5 square of bytes. We were tasked to return the 9 3x3 overlapping windows in turn within the input. The input didn't need any processing so this was simple indexing, with a loop which increments the start point of the window each cycle.
We were tasked with returning a 3-bit enumeration of the octant an
The problem statement deliberately included the formula
as a suggestion for the algorithm. There are however easier integer math ways of doing this calculation. The angle between two vectors can be easily calculated with the dot product between the two.
If
The division is removed by multiplying both sides with
We can square both sides to remove the square root. By squaring, the new equation gains an extra solution. Luckily for us this is even better, because now we capture the opposite side of the cone in the same equation!
Now we're left with two integer multiplies, and multiplication with a constant which we can easily perform in fixed-point with the necessary resolution.
At this point we can determine whether a vector lies in the x-axis or y-axis octants, but we still need to take care of the diagonals. This becomes simple now that we can know if a vector DOESN'T lie in the x or y cones because we can look at the normal quadrants.

If the sign of x and y differ, it's in the green quadrants, otherwise purple. The differing sign is checked with an XOR between the sign bits.
This problem had provided code with an error. The code's purpose was to encode a binary number into a BCD. The code consisted of a three-process state machine for the conversion. The first one determined the next_state, the second one loaded next_state into state, and the third one did the operations. The bug was that both the next_state calculation and loading the next_state were synchronous with the clock. This meant that the actual state change happend on the second clock cycle after the decision instead of the first. This results in operations being done too many times, unexpected and inconsistent state changes, and general weird behaviour.
Given a complex (single precision float)
I calculated this in real math with 4 float multipliers and 2 adders and subtractors each.
Calculate
Demodulate an analog 16-bit QAM measurement into a 4-bit digital value. Solved by comparisons separate comparisons on the I and Q parts then mapping into the requested symbols.