| Home > Electronics > Video1 | Last Updated: 10/18/2003 |
|
Hardware
Microcontroller: Microchip PIC18LF252Program Memory: 32K bytes (16K instructions) RAM: 1536 bytes EEPROM: 256 bytes
Useful links
PIC18LF252 spec sheet6502.org VGA timing information PIC'Spectrum PIC Game System SX Game System PIC microcontroller
This is my first attempt at generating video. This is also my first
actual project with a PIC. It is inspired by a number
of ideas: Primarily, I'm seeing and actually understanding the layout
of a number of small (8 bit) computers. Secondly, I think having some
form of video output for a computer is a good thing. Thirdly, there
Being the first attempt, this is really a proof-of-concept. Can Rob do it? As you'll see, with a little head-scratching, Googling, and asking of questions, I did!! My general goal is 40x40 resolution. The PIC18LF252 microcontroller has plenty of memory, so the limitation becomes knowledge and timing. These are challenges I can deal with. As far as what the output should be - after digging, the VGA timing information is far easier to understand than NTSC. I can generally understand the NTSC black and white scheme - but color is beyond my comprehension at this time! The only realy problem with VGA is the 31.5KHz horizontal sync rate. As a side note, wiring isn't quite this basic. The Hsync and Vsync signals do run at 5V (TTL?) but the RGB lines are only 0.7V or 1V, I'm not quite certain. I've seen documents for both - but I was assured by people who have worked with video before that 0.7V is the correct target voltage. |
|
Resources
Source CodeEarly versionsI didn't really track intial versions well. The source code that I've supplied are copies of the working ASM file - if you do look, sort them by date to get the order of their creation. I figure that this isn't a great loss - if you want code, you'll grab a later version anyway.
After some headscratching, I realized that I needed to drive the routines by interrupts. This lead to reading up on the interrupts, calculating what 31.5KHz equated to in terms of clock frequency. Early on, the fastest clock I had was 2MHz which came out to 0.5MIPS. Not much, but I did achieve 13 horizontal lines of resolution (well, 12 1/2 in reality). After reading the spec sheet, there were some optimizations (besides raw speed) which could improve performance:
movf POSTINC0,W ;1
movwf PORTB ;1
swapf WREG ;1
movwf PORTB ;1
Please note that this actually gives 16 colors instead of the 8 I
use throughout the rest of this documentation. I termed the color
scheme XRGB where X was applied to the other colors. To some extent,
X is a palette.
|
|
Resources
Source Codev1 - 20030928 - Code separation
It was becoming apparant that I needed to separate the code.
A quick bit of digging introduced me to the You will note that the application code is nice an neat now.
The only functional addition is the creating of a |
|
Resources
Source CodeAppleCommander TextPad v2 - 20030928 - Text drawing routines
I created a font for the Apple IIe a number of years ago for a game I wrote in assembly. Some scrounging around with my disk images and AppleCommander made quick work of locating the file and making it available to me. Using a regular expression in TextPad formatted the file the way that mpasm expected. The drawchar, fcolor, and bcolor routines were added. |
|
Resources
Source Codev3 - 20030928 - Text drawing routines
At this point, I decided that the foreground color (fcolor) and background color (bcolor) should be utilized more fully. Already the bcolor was used for the cls routine and the fcolor was used for any plotting being done. However, I decided that drawchar should use them for coloring of the letters - hence the funky colors used in the word "Hello". The drawimage routine was added. |
|
Resources
Source Codev4 - 20041004 - Increase to 10MIPS
At 10MIPS, the PIC is able to do roughly 251 instructions during the active display interval. At 2 instructions per pixel, this comes out to be 124 horizontal pixels. The microcontroller only has enough memory for 22 lines (remember that there are some variables using up RAM), so I decided on 64 pixels across the screen. This gives enough memory for 44 lines of resolution. 64 lines across wasn't quite perfect, but I had pushed the microcontroller to its maximum as a single solution for video. Not bad, but not worth too much, either. I had achieved my goal of a resolution of 40x40 however! |
Final thoughtsThis is a good start for a completely home-built computer. With some more exposure to electronics and the hardware that is available, video will be achievable. Next steps will include external components (SRAM initially) and also experimentation with interchip communication. Useful routines developed:
|