Video Composite Maximum Width/Height

I have basic code that I found from http://dailyduino.com/archives/368 that outputs to a video composite. I tweaked the code a little and had it display bars instead of text. I also wanted to increase the WIDTH and HEIGHT parameters but am having problems doing so. Does anybody know why I can’t increase the size of the framebuffer (WIDTH, HEIGHT)?

Also, if I just increase the DISPLAY_LINES from 240 to 480 the image just scrolls. Why is that?

Here is my altered version of the code:

//Adapted by nonfiction from:
//
//Adapted by phizone from:
//
//Arduino Tv framebuffer
//Alastair Parker
//2007

// Video out voltage levels
#define _SYNC 0x00
#define _BLACK 0x01
#define _GRAY 0x02
#define _WHITE 0x03


// dimensions of the screen
#define WIDTH 38 //38
#define HEIGHT 14 //14

//number of lines to display
#define DISPLAY_LINES 240  //240

//video pins
#define DATA_PIN 9
#define SYNC_PIN 8

// the video frameBuffer
byte frameBuffer[WIDTH][HEIGHT];

// loop indices
byte index, index2;

// pal video line loop
byte line;
// current drawing line in framebuffer
byte newLine;

// if displaying the title
boolean showingTitle = true;

// draw a pixel to the buffer
void setPixel(byte x,byte y)
{
  frameBuffer[x][y]= _WHITE;
}

void grayPixel(byte x, byte y)
{
  frameBuffer[x][y]= _GRAY;
}

// draw a black pixel to the buffer
void clearPixel(byte x,byte y)
{
    frameBuffer[x][y]= _BLACK;
}

void drawLines()
{
  for(int j=1;j<=WIDTH;++j)
  {    
        for(int i=1;i<=HEIGHT;++i)
        {
          if(i == 1)
          {
            if(j % 2 == 0)
              grayPixel(j,i);
            else
              setPixel(j,i);
          }
          else if(i==HEIGHT-1)
           {
             if(j % 2 == 0)
              clearPixel(j,i);
              else
              setPixel(j,i);
           }
          else
          {
            if(j % 2 == 0)
               setPixel(j,i);
            else
               grayPixel(j,i);
               
          }
        } 
  }
}

// clear the screen
void clearScreen()
{
    for (index = 0; index < WIDTH; index++)
    {
        for (index2=0;index2<=HEIGHT;++index2)
        {
            frameBuffer[index][index2] = _BLACK;
        }
    }
}

// the setup routine
void setup()
{
    cli();
    pinMode (SYNC_PIN, OUTPUT);
    pinMode (DATA_PIN, OUTPUT);
    digitalWrite (SYNC_PIN, HIGH);
    digitalWrite (DATA_PIN, HIGH);
    clearScreen();
    drawLines();
}

void loop()
{
  iterateLines();
}

void iterateLines()
{
 
    // iterate over the lines on the tv
    for ( line =0;line< DISPLAY_LINES;++line)
    {    
        // HSync 10.9us
        // front porch (1.5 us)
        PORTB = _BLACK;
        delayMicroseconds(1.5);
        //sync (4.7 us)
        PORTB = _SYNC;
        delayMicroseconds(4.7);
        // breezeway (.6us) + burst (2.5us) + colour back borch (1.6 us)
        PORTB = _BLACK;
        delayMicroseconds(0.6+2.5+1.6);
        
        
        //calculate which line to draw to
        newLine = line >> 4;
        delayMicroseconds(1);
    
        for(int i=0;i<WIDTH;++i)
        {
           PORTB = frameBuffer[i][newLine]; 
           //delay 10 * 62.5ns
           __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
        }
    }

    //vsync
    PORTB = _SYNC;
    
    // wait for the remainder of the sync period
    
    delayMicroseconds(565); //565  
}

Here’s the image off the TV:

Offhand the 38 width is probably as much as the arduino can do in the fixed length of the scan time - you probably can’t change that without rearchitecting it. The 14 height might be to match it in size, you might be able to change it to say 28 if you changed the code that reads “newLine = line >> 4;” to “newLine = line >> 3;”.

The 240 is going to be related to the number of scan lines in a frame, you probably can’t change it.

This is also set up for European TV (PAL) if that’s ok.

I would poke at it without changing those critical constants for starters. Thanks for pointing out the post - I’ll be trying it myself if i can figure out the differences for NTSC.