PAL color video with Atmel controllers


Objective:

I've started out a new project in which i will try to create a PAL color generator with the use of an Atmel microcontroller.
The objective is to have a quality comparable with the Commodore 64 video, being 320x200x16 colors (40x25 character display - non graphical). Any leftover flash space can be used to create a simple BASIC interpreter, so one could use the project as an old-fashioned 8bit micro computer. Only difference is, this is a single-chip system, compared to the rather large PCB required for the Commodore 64.




September 28, 2007

Early tests were done with the ATTiny2313, giving promising results, being a 1-bit signal (B/W) displaying a 32x32 'pixel' image. It required me to do some googling for PAL information, particularly how the synchronisation signals were created and when. I soon found out , that displaying a color image would not be easy, given the maximum speed of most microcontrollers being 16MHz. A slim ray of brightness on the matter was that my Tiny2313 performs pretty well, being able to run at 20 MIPS.



The PAL system sweeps across your TV screen at 15.625 kHz, or 64µs per scanline. Of this time, the visible screen area covers roughtly 45µs only. The rest is either off-screen (retrace) or synchronisation signal (SYNC). Reverting back to the C64 story: if we use 5µs for the left and right border, 40µs can be used to display 320 pixels each scanline. This is calculated using 8 pixels per µs, resulting in an 8MHz dotclock. This is quite close to the C64, which runs on a 7.875MHz dotclock (63/8).

When outputting a B&W signal, the 8MHz would suffice. With a 16MHz controller, this would mean that it would need to be able to read the next pixel and change the pin output every 2 clock cycles. This is bordering to the impossible. ...or so i thought... but more on that later!
The next challenge would be to create a color signal, which would be even more difficult.
Hmm.. more difficult than 'impossible' .. would be nice if i can make it work!

After the initial tests i switched to my Mega88, since i already figured the ridiculously small SRAM on the Tiny2313 (128 bytes) would not cut it. After all: i will need some space to put my screen information. The ATMega88 has 1kB of internal SRAM, capable of storing the 1000 characters required for a 40x25 character screen, leaving 24 bytes for stack and additional variables. Still not enough for the objective i laid out, but since i do not have any larger controllers, this will have to do.

But first things first: a test with colors.
I pulled up my SCART connector and built a 4-bit color testing-setup for the next step (we'll use an RGB-to-PAL converter later on, for example the AD725 from Analog Devices). I wrote a simple program to output the 16 possible colors, and started tweaking my resister-DAC to get the desired colors. (Note to self: i should really consider building an 8-bit color DAC to have more control over my colors, coz this is just not enough for nice graphics)



Using the schemetic above, any color will blend a little with the other colors. If, for example, only blue is high, then both green and red will be added to the signal through resisters R5/R6 and R5/R7 respectively. This will cause a slight discoloration, that could be prevented by adding diodes between the color outputs and resisters R5..R7 just like in the Tiny2313 test above; but i left it like this, because it more accurately creates the C64 colors. Also: it doesn't matter all that much to me.. all i want is 16 colors that differ from each other - and that they do.

This color sample is using a 400kHz dot-clock, resulting in 40µs being used for 16 vertical bars, each 2.5µs wide.
This test does not yet use vertical sync, since it wasn't required to show this image.
The blue bars left and right are the borders and are actually not part of the testimage, but i made them blue so it would be visible where the border starts.
The color signal consists of 4 outputs: Red, Green, Blue and Intensity.
When the I-signal is low, the color outputs are aproximatly 60% of maximum resulting in a low-intensity color.
When the I-signal is high, the output on all 3 color pins is increased by 40% creating a high-intensity color: when any RGB level is high, that color will be at 100% intensity, while a color-signal that is low results in a 40% intensity level. This creates the unique colors shown in the screenshot on the left.
The objective is an 8MHz dot-clock: 20 times faster than this test. But with the above test, there was plenty of time left for NOPs which can eventually be used up for sensible code. Actually, the dot-clock in my test was 3.2MHz




September 29, 2007

I created this webpage to start logging my progress.

On the project itself, i added vertical synchronisation signals, improved on timing and created another test-image

I increased the usable area on the screen from 128 pixels in my test yesterday to 144 pixels using only a narrow border. This way i can fit 36 colorbars, running at twice the speed (800kHz dot-clock).
This screen should look familiar to those who own(ed) a Commodore 64. I widened the borders, so the screen area covers 40µs again. The colors in this picture don't seem to match well with the original C64, but trust me: the screen i'm looking at now looks JUST like my old Commodore! This brings back memories :)
Looks like i was successful in determining the correct resister-values of my DAC after all!

F.Y.I: The image on the left was created with an ATMega88 microcontroller and *NOT* with a Commodore 64 computer!





Back to the 80's