Search code examples
vhdlboolean-logiccircuit

Easy way of dividing an integer by 3


I'm working on a project that is to make a simple music player on an FPGA. It takes a music file of a specified format from the PC and plays it out loud in loops.

We need to implement the standard note lengths, i.e. Quaver for half a beat, Minim for 2 beats, etc. Currently we have a table of the lengths of a beat in numbers of clock cycles at various BPM values. We need to multiply them by these note lengths to yield the correct clock cycles. The only problem is Tuplet, which is a third of a full beat.

Without implementing a full-blown divider circuit, are there any maths tricks one can do to divide, approximately, an integer by 3?


Solution

  • Dividing by 3 is the same as multiplying by 1/3 (=0.33333). 0.3333 can be expressed as an addition of two or more (depending on the needed accuracy) (left) shifted input values.

    input*2^-a + input*2^-b + input*2^-c ...
    

    Just find suitable values for a, b, c, ...

    This works for (almost) all divisions.