SHOWALL FUN PRANKS HIGH VOLTAGE LAZARUS-64 PHOTOGRAPHY SPY GADGETS VIDEO GAME
Figure 10 - The monitor displays 256 pixels, but thinks it is showing 640 pixels
Figure 10 - The monitor displays 256 pixels, but thinks it is showing 640 pixels

If you can't get your monitor to display anything, then you likely have a wiring problem on the VGA connector. The signal generated by this source code is as good (or better) as some accepted standards, so any error will be in the wiring, not the programming here. Now, before moving on to more advanced graphics drawing, I will go through the source code and explain all of the black magic that goes on in order to get the VGA monitor to play well with the microcontroller.





Figure 11 - The basic sync and palette generator assembly source code
Figure 11 - The basic sync and palette generator assembly source code

Open the source code in whatever IDE you like to use and let's go through it one block at a time. As you can see, I am a "lefty", and don't much care for indented code...ack, I know! Also, these sources were done in a few hours, and could certainly be optimized and improved, but the point of this tutorial is to show how you can make a VGA signal by using these basic examples as a starting point. The source codes will also evolve and improve as each new version is made, resulting in a simple framework that you can use as a starting point to build VGA demos, games, and applications. I will be explaining the code following a comment block, as each important function has been labeled. Also note that after each timing critical instruction, the number of clock cycles is shown as a comment since these need to be counted precisely at all times.

< Here is the basic sync and palette generator in AVR assembly >

The first few blocks ("PORT SETUP" and "STARTUP SEQUENCE") just set the IO pins and initialize the stack pointer. Also in Startup Sequence, Timer1 is setup for a compare match interrupt that will happen every 636 cycles. This time defines an entire horizontal line, which has been calculated by cross multiplying the real 25.175MHz standard VGA timings with the required 20MHz AVR timings. All of the work will happen in the video interrupt, leaving the main program loop free to draw graphics only when there are no active lines of video. The nice thing about having all of the timing critical code in the interrupt is that your main loop code can just do whatever it wants without needing to worry about the completely insane timing needed to display a stable VGA image. The real puzzle is going to be where are these graphics going to be stored and how will the main program loop share this space with the VGA frame generator? First, let's look at how the timing for 20MHz was calculated.

Back Home Last Next
You are Viewing... Page 6 of 16
Lucid Science Electronics from the Fringe AtomicZombie Hack-a-day SparkFun