Why FPGA?
This will be the first post of 2022, and I want it to be different. Time ago I have been thinking to write about how I started to use FPGA and also what I expect of them for the future. Likely, the thoughts that I am going to write in this post will change in the next year, but it would be interesting to see how my thoughts about the FPGA field change with the years.
Since I started my degree in industrial electronics and automatics, I always had wanted to work as DSP developer for power electronics equipment. This area mixes 2 fields that I like, embedded development and power electronics. Also, in my degree, I coursed 2 subjects about FPGA. The first one, in the 4th year, was purely theoretical and, although is true that we made some simulations, it was not something that caught my attention. In the 5th year I coursed the second subject based on FPGA and this time, I think that is something obvious if you have no experience using FPGA, the subject was mostly practical but focused only on the digital side. The FPGA at this moment was turning interesting but the purely digital world that involves only digital protocols and RGB screen management isn’t interesting enough to leave my purpose, the DSP development. Nevertheless, in my final degree project, I used an FPGA to make a proportional–integral control for a DC motor. This was my first contact with a project where I was made a design in FPGA to manage power electronics equipment, but even with that, I took this project as a parenthesis of my real purpose, to be a DSP developer. With this purpose, when I finish my degree I started to work as DSP developer for renewable energy equipment, first as a collaborator from the college, and then in a company as a DSP developer to control power electronics equipment. One day, an FPGA designer left the company, and the team needed a new developer urgently. Since I had some experience using FPGAs, I was asked if I could do some of the modules that a new project would need while they were hiring a new FPGA designer. During this period I started to search a lot of documents, application notes and much information about FPGA and how they work internally, the hardware that they use looks amazing to me. Finally, they didn’t find an FPGA designer for that project, so I left my job as DSP developer and I started to work as an FPGA designer in the same company.
I have worked as a full-time FPGA developer since 2015, and when I said full-time is full-time since I always loved to make projects and developments at home. For almost 2 years I write controlpaths in my free time, but some years ago I wrote another blog about microcontrollers and DSP in Spanish named Mipsandchips, and it is still published, you can visit it if you want.
Focusing on the FPGAs, since 2015 I have noticed that the FPGAs field has grown exponentially, and the articles and application notes have been increased exponentially. Even the number of manufacturers has increased. This interest in the FPGAs is not only from the developers and companies side, also companies like INTEL, Microchip and AMD have shown that the FPGA is an emergent business. Part of the success of the FPGA comes from the limitations that the conventional processors have, you need one processor to execute an instruction, even if this instruction is as simple as performing an addition, do you want to duplicate it? Great! add another processor, do you want to increase by 100 your capacity? no problem, add 100 processors and you will make the energy companies very happy. The structure of the FPGA makes it easy and efficient to execute an instruction, only you need to synthesize a hardware circuit capable to execute it, and multiplying that by 100 is not a big deal if the entire circuit fits in your FPGA, I no going to talk about timing restrictions this time. If you are thinking about the high power consumption of the FPGAs, that is indeed high, but in case you need to execute a lot of simple instructions, I am thinking of a large FFT, even if the clock of the FPGA is several times slower than the clock of the processor, you will be faster using an FPGA due to the parallelizing capability of this kind of algorithms. Obviously, this is not free, you will need to design your hardware circuit in order to execute the instruction you need. These circuits are called kernels, and they are very common in hardware acceleration.
Talking about designing your circuit, let’s talk about the synthesizer. I have several colleagues that asked me about how I design the circuit that makes the FPGA execute a task. And by how I design, they thought that the design in the FPGA has been designed using a schematic where I put the logic gates and the flips-flops, but this is not true… in part. Starting with the part that is not true, all the FPGA with a minimum complexity are not designed by drawing the logic gates and the register. High-level languages are used to describe the hardware (HDL) but is true that there is a big difference in the meaning of instruction for an embedded developer and an FPGA designer. If you are using Verilog, you will notice reading some code lines that are based on C, the same with VHDL and Pascal, so can be tempted to think that an FPGA could be “programmed” as a microcontroller, but it is very far from the reality. When you are using an if instruction, the processor executes a program memory jump to a certain address if the condition is true, and to another address when the condition is false. In FPGA, if an instruction is written as an electronic circuit, that has some limitations, for example, if the circuit is synthesized with a multiplexer, the output of this multiplexer cannot be connected to the output of another multiplexer, this will produce a short-circuit. In a microcontroller, there is no limitation if a variable is set in 2 different parts of the code. Also regarding the widths, in a microcontroller there is a physical memory with a certain width, 16 or 32 bits, and all the variables must be fitted in this width or a combination of these widths. In an FPGA there is no predefined width for the signals, so using 32 bits register to store a 2 bit signal will be a misusing. Luckily for us, synthesizers have some intelligence, but to the synthesizer do what we want to do, we need to understand (at least at the basic level), how they work, in order to write a code that they will understand, in other words, write a Verilog code is easy, mostly if you have a background developing C or C++, but do that the code will be synthesized exactly how you need is not easy, and not only is not easy, but is different for each vendor, or even for different families of the same vendor, the reason is the resources that each device has are different, so the synthesizer must translate your code with the resources that the device has available.
Regarding the different devices, until now I only have talked about FPGA, but some years ago, there is another device in town, the System On Chip. I have to say that when I started with the FPGA, SoCs based on an FPGA and a processor are rare, at least that is what I see. Xilinx release the Zynq 7000 family in 2011, that is when I finish my project using an ALTERA Cyclone IV, and I don’t remember hearing about SoC. Before Zynq, there were other families based on Power PC and other processors but as I said, SoCs 10 years ago was rare. Now they are in many devices that you use in your day. Also, sometimes people ask me about a board to start with FPGA, and I always recommend the TUL Pynq Z2, a board that you can find for less than 130 Euros and is based on a big Zynq 7020. My relationship with SoCs is a love-hate relationship. The reason is that something that I like a lot about FPGAs, is that I develop the peripheral I need, with all and only the functionalities that I need. When I have to work with, i.e. a SmartFusion 2 SoC, and I want to use the SPI from the Cortex M3, I have to study the datasheet, and search between all the registers and the capabilities that the SPI peripheral has, when the only thing that I need is to send 16 bytes and receive 8. Many times is faster for me to add an AHB or AXI Lite interface to my Verilog module and use it from the processor. So, I know that the SoCs are very interesting devices, and I have to know them, but it is the part that I like least.
To finish, if something asks me about the future of the FPGA, I have no doubts, FPGA will be used more and more because we will need devices that can handle many execution lines at the same time, and the FPGA will be there to help the processors. A limitation factor that the FPGAs have now is that if you have a processor that needs to accelerate a function, you need to develop a design that satisfies this need, but maybe the processor in another moment needs to accelerate another function, so you have to develop other design for the FPGA. The goal for the next years could be that the processor that needs to accelerate a function, will be capable of developing a hardware design capable to perform the function that needs by itself, and then remake the design when a different function will be needed.
I promise that the next post will be a normal post… 🙂 Thanks to all for reading. Hope you be healthy and happy in 2022!