• ## Xilinx SDK: make crashing with Interrupt/Exception

After exporting the implemented and generated project from PlanAhead to Xilinx SDK and having generated a Board Support Package, the build stops with an error due to make crashing with a rather dubious message along the lines of

make: Interrupt/Exception caught (code = 0xc00000fd, addr = 0x4227d3)


It turned out that this is due to an existing installation of Git, when the Git directory is added to the path. Specifically, sh.exe is the problem here and simply removing that from (or renaming it in) the Git installation directory solves the problem.

• ## Digilent ZYBO (Zynq-7010)

The ZYBO is an evaluation board for the Xilinx Zynq-7010 All-Programmable SoC made by Digilent. I got mine from Trenz Electronic at a reduced price for academic use.

I chose it over the ZedBoard (which I already have some experience with) because of the reduced size and since I don’t need the high-density I/O jack. It turns out though that the board is very small, yet quite heavy.

One thing to keep in mind though is that despite the rather large number of PMOD connectors, not all of them might be actually useful for a given task. The one on the left is connected to the Cortex processor, the right one is mixed analog/digital, and the three lower right ones are differential, leaving exactly the one on the lower left as a logic-dedicated PMOD for the FPGA (i.e. a single ended one that is connected directly to the FPGA, apart from the XADC one, of course).

I originally intended the board to be used to experiment with the OV7670 camera, but that might turn out to be a problem because of the PMODs. So: Caveat emptor.

Unfortunately, while Digilent’s own software, Adept, was now able to talk to the board too, it was still unable to recognize the chip.

Edit: After asking Digilent support I received a mail saying that the Zybo can’t be programmed with Adept, so that’s expected behavior.

Edit: I wrote up a quick-start tutorial for the ZYBO. You can read more about it here.

• ## Pipistrello rev. 2.0

I just received my Pipistrello board and it’s damn beautiful! (Unfortunately the site seems to be down sometimes; It looks like a DNS problem to me. Just try again later if the link does not work.)

On the front side, there’s the Spartan 6 LX45 FPGA (XC6SLX45-2CSG324), an FT2232H FTDI chip (one channel wired for custom use), the HDMI, USB, MicroSD and Headphone connectors, a button and six LEDs as well as a whole bunch of GPIOs.

On the bottom the DRAM chip can be found.

Shipment to Germany took less than a week (apart from being held back by customs) and in addition to a tracking number Magnus, the creator of the Pipistrello board, sent a mail regarding additional information to the board, as well as sources and example code.

The board comes pre-configured with a MicroBlaze prozessor running a Linux system that identifies itself as Linux Pipistrello-LX45 3.6.0-11207-ga0d271c #12 Sun Dec 9 11:56:59 EST 2012 microblaze GNU/Linux. CPU and architecture information can be grabbed with cat /proc/cpuinfo, as can be seen on the following screenshot of PuTTY.

All in all a very nice experience.

• ## Kalman filter: Modeling integration drift

One interesting observation when working with the standard model for constant acceleration in the Kalman filter is that the results tend to drift over time, even if the input to the system is zero and unbiased. I stumbled across this recently when integrating angular velocities measured using a gyroscope. Obviously, calibrating the gyroscope is the first step to take, but even then, after a while, the estimation will be off.

So the differential equations describing motion with constant acceleration are given as

\begin{align} x(t) &= x_0 + v(t)\,\mathrm dt + \frac{1}{2}a(t)\,\mathrm dt^2 \\ v(t) &= v_0 + a(t)\,\mathrm dt \\ a(t) &= \mathrm{const} \end{align}

The continuous-time state-space representation of which being

\begin{align} \dot{\vec{x}}(t) = \underbrace{\begin{bmatrix} 0 & \mathrm dt & 0.5\,\mathrm dt^2 \\ 0 & 0 & \mathrm dt \\ 0 & 0 & 0 \end{bmatrix}}_{\underline{A}} \cdot \underbrace{\begin{bmatrix} x \\ v \\ a \end{bmatrix}}_{\vec{x}} \end{align}

where the state vector $\vec{x}$ would be initialized with $\left[x_0, v_0, a_0\right]^T$. Modeled as a discrete-time system, we then have

\begin{align} \vec{x}_{k+1} = \begin{bmatrix} 1 & T & 0.5\,\mathrm T^2 \\ 0 & 1 & \mathrm T \\ 0 & 0 & 1 \end{bmatrix}_k \cdot \begin{bmatrix} x \\ v \\ a \end{bmatrix}_k \end{align}

with $T$ being the time constant.

Now due to machine precision and rounding issues we’ll end up with an error in every time step that is propagated from the acceleration to the position through the double integration. Even if we could rule out these problems, we still would have to handle the case of drift caused by noise.

According to Position Recovery from Accelerometric Sensors (Antonio Filieri, Rossella Melchiotti) and Error Reduction Techniques for a MEMS Accelerometer-based Digital Input Device (Tsang Chi Chiu), the integration drift can be modeled as process noise in the Kalman filter.

Tsang (appendix B, eq. 7) shows that the drift noise is given as

\begin{align} \underline{Q}_a = \begin{bmatrix} \frac{1}{20} q_a \,T^5 & \frac{1}{8} q_a \,T^4 & \frac{1}{6} q_a \,T^3 \\ \frac{1}{8} q_a \,T^4 & \frac{1}{3} q_a \,T^3 & \frac{1}{2} q_a \,T^2 \\ \frac{1}{6} q_a \,T^3 & \frac{1}{2} q_a \,T^2 & q_a \,T \end{bmatrix} \end{align}

with $q_a$ being the acceleration process noise (note that Tsang models this as $q_c$ in continuous-time).

• ## Linear (binary) integer programming in Matlab

So, suppose you’re in university, it’s that time of the year again (i.e. exams) and you already have written some of them. Some are still left though and you wonder: How hard can you fail – or: how good do you have to be – in the following exams given that you do not want your mean grade to be worse than a given value.

## Linear programming

Say you’re in Germany and the possible grades are [1, 1.3, 1.7, 2, .. 4] (i.e. a closed interval) with 1 being the best grade and 4 being only a minor step to a major fuckup. Given that you’ve already written four exams with the grades 1, 1, 1.3 and 1 and that you do not want to have a mean grade worse than 1.49 in the end (because 1.5 would be rounded to 2 on your diploma), but there still are 9 more exams to write, the question is: Which worst-case grades can you have in the following exams and what would that imply for the others?

This is what’s known to be a linear programming or linear optimization problem, and since the values (here: the number of grades) are constrained to be discrete values, it’s integer programming.

The goal of linear programming is to find the arguments $x$ of the objective function $f(x)$ such that $f(x)$ is maximized, given some constraints on $x$. In Matlab, all linear programming functions try to minimize the cost function, so the problem is formulated as

\begin{align} \underset{x}{\mathrm{min}} \, f(\vec{x}) \, \mathrm{such}\,\mathrm{that} \, \left\{\begin{matrix} \underline{A}\cdot \vec{x} \leq \vec{b} \\ \underline{A}_{eq} \cdot \vec{x} = \vec{b}_{eq} \end{matrix}\right. \end{align}

Obviously, maximizing an objective function is the same as minimizing it’s negative, so $\mathrm{max} \, f(\vec{x}) = -\mathrm{min} \left(\, -f(\vec{x}) \right)$. In Matlab, these kind of problems can be solved with the linprog function.