Pages: [1] 2 3 ... 19   Go Down
Author Topic: NTSC video out library  (Read 31801 times)
0 Members and 1 Guest are viewing this topic.
Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote a small video output library called TVout. It is completely interrupt driven to make writing things that need tvout easier.

It runs on a resolution of 128x96 with some basic text printing and line and dot drawing for now.

For the now its NTSC only and restricted to using pin8 for video data and pin9 for the sync signal, ascii art smiley-wink:

 Pin9: Sync line:  -->|--/\/\/\--o
                               1Kohm   |
 Pin8: Video line: -->|--/\/\/\--o---------------- RCA tip
                               330ohm  |
                                            o--/--/\/\/\--o-- RCA GND
                                                   75ohm |
                                                             V
                                                           GND

Video of the included demo sketch:
[media]http://www.youtube.com/watch?v=CjFx9WTnXOM[/media]

Here is the example .pde included with the library.
Code:
#include <TVout.h>

TVout TV;
char x,y;

void setup()  {
  x=0;
  y=0;
  TV.start_render();
}

void loop() {
  delay(2000);
  TV.clear_screen();
  x=0;
  y=0;
  for (char i = 32; i < 127; i++) {
    TV.print_char(x*6,y*8,i);
    x++;
    if (x >20) {
      y++;
      x=0;
    }
  }
  delay(2000);
  TV.clear_screen();
  TV.print_str(0,0,"fill screen pixel");
  TV.print_str(0,8,"by pixel");
  delay(2000);
  TV.clear_screen();
  for(x=0;x<127;x++){
    for(y=0;y<95;y++){
      TV.set_pixel(x,y,1);
    }
  }
  delay(2000);
  TV.clear_screen();
  TV.print_str(0,0,"draw some lines");
  delay(2000);
  for(y=0;y<95;y++){
    delay(10);
    TV.draw_line(0,y,x-y,y,1);
  }
}

It would be great to have feed back on this as I have only had one tv to test this on.  If anyone wants to try it, it must be noted that no other interrupts can run along side this as it will mess with the video signal (the sync signal will be fine but the video not so much).

Also this release was only tested on an arduino with a ATMega328p, the 168, and 8 do not have enough memory for this resolution.  I dont know if the mega will work as is, it may but I do not know if the pins are mapped the same (OC1A on PORTB0).

First post so a download link is in the next post.
« Last Edit: April 30, 2010, 02:52:56 pm by mdmetzle » Logged

Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And the Link:
http://code.google.com/p/arduino-tvout/
Logged

Dresden / Germany
Offline Offline
Sr. Member
****
Karma: 4
Posts: 451
Entwicklungsklaus
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, hope you will support PAL also.

Great Work!

Greetings ChrisS
Logged

Sturmfabrik - mediale Dienstleistungen
www.sturmfabrik.de

B0100111001000011, USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1503
I'm confused.  Wait, maybe not..
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Before I cut up an RCA cable, can anyone post a picture of the TV when using this?  I'm curious how it looks. smiley
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Before I cut up an RCA cable...
oh go one, cut the cable   smiley-wink

Many of us are curious.
Logged

Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ill post a video of the demo sketch when I get home.
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If anyone wants to try it, it must be noted that no other interrupts can run along side this as it will mess with the video signal


I am curious as to what this would limit...

I imagine that serial port interfacing would be out...? What about SPI or I2C? My thinking is the possibility of using this "standalone" as an interface for another Arduino-to-TV hookup...
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No you cant use the built in arduino serial library for receiving data as the interupt may occur during a video line.  I however do plan a sort of work around by including a UART sub class in the library that will poll the UART.  The same could be done for something like the SPI module too.

I would first have to change the timer interupts a bit as its sync interupt currently goes off at the end of the Hsync period and there isnt enough time to do much before rendering may be needed. (I ran into this issue and that is why there currently isnt any PAL support, the extra time to incriment a int for the line counter was causing random jitter.)

on a side note can the TIMER1_CAPT_vector be used to interrupt on the timer reset? or is that only for triggering an interrupt from an external source?
Logged

Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Added video to first post.
Logged

Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

New release:
added PAL support (my tv detects the signal as 576i anyway).
start_render(_PAL); or start_render(_NTSC);

made a few necessary changes that will facilitate future sound support and or polling UART/SPI/ect.

added a delay_frame(#frames) function to regain some semi accurate delay. this will block the user code until the end of the visible screen so it can be used to wait for a frame render to occur.

added ability to pause the display rendering but keep outputting a sync  signal(Hsync only) so user code can have full access to the cpu.

I also did some quick calculations and running as it(128H pixels by 96V double height pixels) is there is about 3.6MIPS left for user code.

updated NTSC demo (there is an included pal example too)
Code:
#include <TVout.h>

TVout TV;
char x,y;

void setup()  {
  x=0;
  y=0;
  TV.start_render(_NTSC);
}

void loop() {
  TV.clear_screen();
  x=0;
  y=0;
  for (char i = 32; i < 127; i++) {
    TV.print_char(x*6,y*8,i);
    x++;
    if (x >20) {
      y++;
      x=0;
    }
  }
  TV.delay_frame(60);
  TV.clear_screen();
  TV.print_str(0,0,"fill screen pixel");
  TV.print_str(0,8,"by pixel");
  TV.delay_frame(60);
  TV.clear_screen();
  for(x=0;x<127;x++){
    for(y=0;y<95;y++){
      TV.set_pixel(x,y,1);
    }
  }
  TV.delay_frame(60);
  TV.clear_screen();
  TV.print_str(0,0,"draw some lines");
  TV.delay_frame(60);
  for(y=0;y<95;y++){
    delay(10);
    TV.draw_line(0,y,x-y,y,2);
  }
  TV.delay_frame(60);
}
Logged

Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, great job!!!
Any chanches to run it on Arduino Diecimila? Someone have tested it???
« Last Edit: May 03, 2010, 11:45:59 am by joeSeggiola » Logged

Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It will work with the 168 if the output resolution is lowered.  to do this open up the library and change the video_timing.h file like so:

_RESOLUTION_VERTICAL 96
to
_RESOLUTION_VERTICAL 54

the basic formula is this:
16*_RESOLUTION_VERTICAL must be less than the amount of SRAM the board has. in this case with a vres of 54 the library will use 864bytes of ram(not much left for user code).

the horizonal resolution currently cannont change without modifying the render_line() function in video_gen.cpp.  for instance to render a horizonal resolution of 120 change:

video_timing.h:
#define _RESOLUTION_HORIZONTAL       128
to
#define _RESOLUTION_HORIZONTAL       120

video_gen.cpp:
in render_line() remove the last set of the byte output code(these lines, note the comments):
"LD            __tmp_reg__,X+\n\t"            //16
"byteshift\n"

I do plan to implement a tile render engine at some point. so the memory needs of that version will drop drastically.

doing either of these changes will break the demo code. it modifies the whole screen space as it is now, and since the library assumes that you know what you are doing when changing the screen it does not do any bounds checking.  I think I will add that to the next release.

I haven't tested any of the changes i suggested so....
Logged

Dresden / Germany
Offline Offline
Sr. Member
****
Karma: 4
Posts: 451
Entwicklungsklaus
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, that's cool... PAL-Support!!!

Ok, if I understood right, you need much as possible SRAM, to get the most resolution possible?

So you think Sanguino btw. AtMega644p is the right Device to improve Resolution?

Because of Sanguino, 644p is arduino-compatible mcu. So far as I know, it's the "biggest sram" Dip/Dil mcu on the market and avaiable also.
It runs on 20Mhz so, this could be an improvement too.

I know, there are mcu's with much more sram, but in Dil/Dip Formfactor 644p is the choice of simple handling... maybe i am right.... mmh....

I am no expert... whart do you think about using 644p?

Greetings ChrisS
« Last Edit: May 04, 2010, 02:37:25 am by ChrisS » Logged

Sturmfabrik - mediale Dienstleistungen
www.sturmfabrik.de

Michigan, US
Offline Offline
Full Member
***
Karma: 3
Posts: 148
Go Huskies
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes the sanguino(ATMega644p) would work well, however do note that it would require a quick modification the the library.  This is because the OC1A pin is not on PORTB1, it is on PORTD5, the required modifications would be setting PORTD5 to be output, and connect the sync resistor to that pin (i don't know what it is on the sanguino).

The arduino mega would be even better resolution wise as it has 8k sram.

As far as the best DIP chip to use the ATMega1284p would be best, if it can be found. it is the bigger brother to the 644, with 16k sram! (@20mhz 320x240 would be possible)

clock speed really isn't an issue with this frame buffer method because unless we have about 8k of SRAM 16mhz is fast enough to output the buffer.
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am no expert... whart do you think about using 644p?

At that point, you might look into the Uzebox:

http://belogic.com/uzebox/

 smiley
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Pages: [1] 2 3 ... 19   Go Up
Jump to: