I have a simple test bed that implements the video output system, and that works just fine. But the instant I feed it with the whole design, so that the VIC-IV is feeding the video output system, I get really weird problems. And I mean really weird.
For example, the digital video output lines that are fed to the resister network for making the analog VGA signals should be either 3.3V or 0V at any point in time. However, with the whole design, they suddenly are showing quite weird analog modulation on the signals. This should simply not be possible. But if I bypass the FIFO and just pass the video signals through, then they come out just fine. FIFOs are First-In-First-Out digital buffers. They should not be able to add weird analog effects. In fact, if I even just pass the video signals in and out of the pixel_driver module, without even modifying them or delaying them, then the problems show up. The following photo gives an idea of the kind of thing we are seeing:
In the process of trying to debug it, I found that if I put an oscilloscope probe on the HSYNC line of the VGA port, then the pattern will shift sideways. It does this on all 3 FPGA boards we tested it on. Very weird. Especially since the HSYNC line is outputting just fine, and is an output-only signal. Clearly there is some weird analogy thing going on.
We can also work out a few other things from this display. Primarily, the FIFO feeding and reading are both working fine, because the text display is stable, and is not warped or distorted. There is also no jitter on the pixels: they are rock solid. It is only this weird analogy effect that iss causing trouble. We can see what is going on there a bit better if I make the screen all white, so that the red green and blue channels are all fully saturated, and then look at those signals. In these image, the top channel is the HSYNC pulse, and the bottom channel the blue VGA output.
So, here in the first one, we can see the time around a single HSYNC pulse. We see the blue channel is active, except for the HSYNC fly-back time, which is what we expect. We can also see that, although the blue channel should be stably fully saturated, it is showing a variation of about 300mV continuously:
So what is going on here? What are some possibilities?
Well, on the one hand, while we are using a 40MHz pixel clock (= 25ns period), the real pixel clock is 120MHz, i.e., 3x that. It is possible to speculate that we are seeing the blue channel pulling down 1/3 of the time, instead of holding constant. The monitor might then not latch onto this clock cleanly, and might thus have the fading effect due to different clock drift of when the monitor samples the signal, and when the sampling point of the monitor drifts with regard to the peaks and troughs in the signal, and ends up mostly sampling the troughs instead of the peaks. I did check that it isn't the signal itself going funny at the end of the raster lines, instead the signal looks more or less identical throughout.
What I can see is sometimes the blue channel has some strange oscillations visible on it. This could be due to meta-stability on cross-domain signal crossing, except that by using the FIFO the data for the blue channel doesn't actually cross clock domains.
Back to the sampling theory, there might be some evidence in support of this, because if I switch the video mode to 50Hz, which uses a different dot clock (30MHz instead of 40MHz), then the whole effect changes. Instead of the ragged right edge, only some of the columns of pixels are visible:
And the oscilloscope view of the blue channel looks like this:
But what is even stranger is something we discovered today, when one of our students was helping me to debug this. He bypassed the FIFO to see what would happen, and the result is quite interesting. Basically, it all works, without any of the funny problems, but of course the pixels are not all lined up in both modes, because the pixels are released on the wrong clock domain, so it isn't really an option. It does make me think that there is some problem in the way that I am using the FIFO, though. It also tempts me to make my own simpler FIFO for this job. We'll see. In the meantime, I'll sleep on it.