How to make a 1280x1024 black and white grid on VGA port using Propeller
mtomar
Posts: 6
Hi,
I am trying to get a 1280x1024 black and white grid using the VGA port on Propeller. the demo code uses a driver where we save the complete image data as display buffer which doesn't work for higher resolutions. Any suggestions how to go about it.Thanks!!
I am trying to get a 1280x1024 black and white grid using the VGA port on Propeller. the demo code uses a driver where we save the complete image data as display buffer which doesn't work for higher resolutions. Any suggestions how to go about it.Thanks!!
Comments
#define printf __simple_printf
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "propeller.h"
#include "simpletools.h"
int RedPin1=22;
int RedPin2=23;
int GreenPin1=20;
int GreenPin2=21;
int BluePin1=18;
int BluePin2=19;
int VsyncPin=16;
int HsyncPin=17;
int hResolution = 640;
int vResolution = 480;
void setBlack(){
low(RedPin1);
low(RedPin2);
low(GreenPin1);
low(GreenPin2);
low(BluePin1);
low(BluePin2);
}
void setWhite(){
high(RedPin1);
high(RedPin2);
high(GreenPin1);
high(GreenPin2);
high(BluePin1);
high(BluePin2);
}
int main(){
int n;
n=10000;
unsigned int clkfreq = _CLKFREQ;
long int HfrontPorch = (clkfreq / 1000000) *0.94* n;
long int HbackPorch = (clkfreq / 1000000) * 1.89*n;
long int HsyncPulse = (clkfreq / 1000000) * 3.77*n;
long int HactiveVideo = (clkfreq / 1000000) * 25.17*n;
long int VfrontPorch = (clkfreq / 1000) * 0.35*n;
long int VbackPorch = (clkfreq / 1000) * 1.02*n;
long int VsyncPulse = (clkfreq / 1000) * 0.06*n;
long int VactiveVideo = (clkfreq / 1000) * 15.25*n;
low(VsyncPin);
low(HsyncPin);
setBlack();
while(1){
waitcnt(_CNT + VfrontPorch);
high(VsyncPin);
waitcnt(_CNT + VsyncPulse);
low(VsyncPin);
waitcnt(_CNT + VbackPorch);
for (int i =0; i < 480; i++) {
waitcnt(_CNT + HfrontPorch);
high(HsyncPin);
waitcnt(_CNT + HsyncPulse);
low(HsyncPin);
waitcnt(_CNT + HbackPorch);
setWhite();
waitcnt(_CNT+ HactiveVideo);
setBlack();
}
}
}
Read up on the video hardware, and write it in assembly code.
FYI, there is not enough memory to do a bitmap, but like Roger says, you could display a grid made from tiles.
Propeller manual, has information in video circuitry and instructions:
http://www.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2_0.pdf
Hydra manual - has really good explanation of video generation:
http://www.parallax.com/sites/default/files/downloads/32360-Hydra-Game-Dev-Manual-v1.0.1.pdf
The following object from Obex would be a good basis for what you want, you just need to make a C wrapper to replace the Spin wrapper.
VGA 1280x1024 Tile Driver w/Cursor
This object generates a 1280x1024 VGA display from a 80x64 array of 16x16-pixel 4-color tiles.
It requires three cogs (or four with optional cursor enabled) and at least 80 MHz.
http://obex.parallax.com/object/646
''VGA display 40x15 (single cog, ROM font, palette) - demo
'' Author: Marko Lukat
'' Last modified: 2013/10/25
'' Version: 0.2.pal.7
VGA monitors tend to be very picky about their timing, and most will refuse to sync to a signal that isn't fairly accurate.
However there are lots of objects and projects out there where people (including myself) have done different combinations of functionality. While it's hard to write a video driver it's much easier to take a tile driver someone else has written and write font maps for it.
(We call them tile drivers because the "tiles" represent a combination of bitmap and color information; they usually involve some creative shifting to load properly as the tile format is optimized for shoveling bits out to the video hardware, and some drivers can have more than 256 tiles so they're not really "characters.")
If you have enough tiles you can devote a group of them to making a bitmap canvas, and if your resolution is low enough (the limit is 32K of Hub RAM for bit data) you can actually have a full screen bitmap.
So this is what I have been trying. Can anyone explain me how to get the values of the following parameters for various resolutions in the format given below if I know the timing descriptions for various resolutions.
static const uint32_t invisibleScale = (16 << 12) + 160;
static const uint32_t visibleScale = (4<<12) + 16;
static const uint32_t blankPixels = 640;
static const uint32_t syncPixels = 0x3FFC;
static const uint32_t HSyncColors = 0x01030103;
static const uint32_t VSyncColors = 0x00020002;
static const uint32_t HVSyncColors = 0x03030303;
I know the values for a VGA signal in the format below instead :
ParameterValueUnit
Pixel clock frequency
25.175
MHz[10]
Horizontal frequency
31.469
kHz
Horizontal pixels
640
Horizontal sync polarity
Negative
Total time for each line
31.778
µs
Front porch (A)
0.636
µs
Sync pulse length (B)
3.813
µs
Back porch (C)
1.907
µs
Active video (D)
25.422
µs
ParameterValueUnit
Vertical lines
480
Vertical sync polarity
Negative
Vertical frequency
59.94
Hz
Total time for each frame
16.683
ms
Front porch (A)
0.318
ms
Sync pulse length (B)
0.064
ms
Back porch (C)
1.048
ms
Active video (D)
15.253
ms
If someone can help me to understand how above values have been derived from the table below, It will help me assign values for 1280x1024 as I know the timings for this resolution but don't know How to convert.
I am using these values for the code below:
https://code.google.com/p/propside/source/browse/propside-demos/C-VGA/vga.cogc?r=76b72d90083f6cc3cd2af52b4d20b6e062bb33fb.
Please help me make necessary changes in the parameters above for a new resolution.
https://code.google.com/p/propside/source/browse/propside-demos/C-VGA/vga.cogc?name=beta_v0_7_2&r=1a0bd3f7931eb25df5fe5844cdcdfc6d853918fe