Objective 13) FPGA Programming
Difficulty:
Write your first FPGA program to make a doll sing. You might get some suggestions from Grody Goiterson, near Jack's elevator.
Note
This objective unlocks after reaching the roof of Frost Tower
Hints and Resources
Hints provided after helping Grody Goiterson and completing the Frostavator Terminal Challenge
FPGA for Fun
There are FPGA enthusiast sites.
FPGA Talk
Prof. Qwerty Petabyte is giving a lesson about Field Programmable Gate Arrays (FPGAs).
Other Resources
Introduction Hint for Rounding Numbers
If $rtoi(real_no * 10) - ($rtoi(real_no) * 10) > 4, add 1
Solution
Open the FPGA Programming terminal on the roof of Frost Tower and program it so all tests pass and you are able to program the device.
The Code
There may be a more elegant way to do this but the following code will, at least in every test I ran, result in exact matches for any target frequency and will successfully complete the challenge. See below for an explanation of the math.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
The Frequency Math
Our clock is running at 125MHz, so 125,000,000 clock ticks = 1 second
The number of clock ticks that pass during each cycle of a given frequency (say for example, 500Hz) is equal to 125,000,000 divided by that number.
(125,000,000 / 500) = 250,000
But a square wave cycle represents both the high and low portions of the wave, so the number of clock ticks between each transition is half that.
((125,000,000 / 500) / 2) = 125,000
The target frequency supplied to our code is an integer value with the last 2 digits representing the fractional portion. So a frequency of 500Hz will be seen by the code as the number 50000, so we have to multiply the previous result by 100.
(((125,000,000 / 50000) / 2) * 100) = 125,000
Simplifying our final calculation gives us the following formula for how many clock ticks pass before each high / low transition.
((125,000,000 / freq) * 50)
Completion
Answer
Successfully programming the device from the FPGA terminal completes the challenge and gives you the FPGA item, which can be plugged into the Speak and Spell next to Crunchy