Multi-planet physics simulation

Python vs FPGA

A couple of months ago I got interested in FPGAs (a "processor" where instead of writing instructions you directly define how every circuit is wired. They're crazy fast, crazy parallel, and crazy time-consuming to write code for). This is an 8 planet physics simulator written in Verilog and running on a Mojo v3 development board (Based on Xilinx’s Spartan 6).

The fpga calculates the planets position and sends them to my laptop over serial. The speed is limited in how fast it can tell my laptop where it has calculated the planets to be. If this is sped up by having it only broadcast the result of every few calculations for error checking, it can calculate a frame in 256 clock cycles.

In comparison, an equivalent python program runs 1000 frames in 1s, so on a 2.3Ghz processor that’s about 2 million clock cycles per frame. Admittedly, the clock on the FPGA is about 50 times slower than on my laptop. But that's almost entirely counteracted by the fact that the FPGA is also about ~20 times cheaper than my laptop.

The github repository is here

The verilog code written from scratch is under src/gravity_simulator.v, src/force_calculator.v and src/inv_calculator.v. Code largely based on other people's code is in src/mojo_top.v which holds the top module and connects everything. Also in src/oscilloscope.v, an edit to a hello world program. The python code is under computer_side/python_version.

< Back to main