# Using an FPGA over an Arduino

Having read this excellent answer on FPGA's vs Microcontrollers I have a few queries.

I recently completed a project that utilised reflectance sensors. Simply put, it reads the reflectance by measuring the discharge time across a capacitor. However, if I wanted to utilise an FPGA for this project, how would one go about interfacing such a sensor with an FPGA? I've written VHDL before with ModelSim, and synthesised using Xilinx, so I have a basic grasp of how VHDL works.

In general, are FPGAs and microcontrollers interchangeable? What is the best way to interface external sensors, such as the ones above which are digital, with an FPGA?

• Are FPGAs and microcontrollers interchangeable? Obviously not; they need entirely different design techniques and have very different cost profiles. You would connect your sensor to the GPIO and then build some sort of state machine to drive it. – pjc50 Apr 13 '15 at 15:27
• Sorry, I realised I didn't quite word my question correctly. Presumably what you can do on an Arduino can be done on an FPGA albeit with a completely different approach to the code? – CircularRecursion Apr 13 '15 at 15:45
• FPGAs are strictly more capable, yes, but it makes little sense to use one when a microcontroller would do. See electronics.stackexchange.com/questions/97277/… and electronics.stackexchange.com/questions/140618/… – pjc50 Apr 13 '15 at 15:54
• Btw there are FPGA kits (e.g. with MAX 10) that have Arduino connector. – Qiu Apr 13 '15 at 17:27

Your sensors seem to provide a timed pulse representing the measured value. In case of a micro-controller, this signal would trigger an interrupt, and the interrupt handler would use a timer to measure the pulse length and store it to a variable.

In case of an FPGA the equivalent of such variable would be a counter with enable signal connected to the output of your sensor. A positive pulse would start the counter, and once the pulse ends, the value of the counter would be used by the rest of the logic pretty much the same way as a variable.

For a small number of sensors there is no real benefit of using the FPGA which will cost far more than a micro-controller. However, the micro-controller only can handle a single task at a time, so adding more sensors will make the pulse measurement less and less precise. FPGAs could easily handle as much sensors as they have free pins (hundreds to several thousands).