Thursday, December 13, 2012

NTSC TV Interface (PIC12F1840)

UPDATE 12.1231:
As you may know, the preliminary work on video from the PIC led to creating of a PONG game. Well, that game has led to a LOT of work done on the NTSC interface. And as part of that work, I split out all of the NTSC stuff into it's own module - NTSC_Interface.INC and NTSC_Interface.ASM. Hopefully this makes for easier implementation of NTSC video in your projects. I also have ODD/EVEN fields implemented and the timings are _really_ tweaked to try to meet spec. The big LCD TV is working better (VSync locks now, data is clean, but there's a weird shifting of the line data), and everything else I have thrown at it works great, including my Sony LCD goggles.

I am including the full PONG game so you can see how the NTSC_Interface module was integrated into the game itself - and hopefully it will be a learning example so you can implement NTSC video into your own PIC project.

PONG.ASM (V4.04):
Common.INC (V1.10):
NTSC_Interface.ASM (V1.00):
NTSC_Interface.INC (V1.00):

Enjoy - and Happy New Year!

UPDATE 12.1220:
Thanks to helpful readers - I know have a method to post source code.

The main program (Video_Game.ASM):
A common file I drop in all projects (Common.INC):

Let me know if that gives you any problems.

UPDATE 12.1214:
We have a bouncing ball! I am updating the video buffer during the vertical sync.

UPDATE 12.1213:
Data retrieval from the EEPROM is working now. It also simplifies the code quite a bit. I put a monochrome (1 bit - black or white) 32x32 picture of my son in the EEPROM and this is how it looks. Nice! Pixelicious, but nice!

Original post after the break.


Another night, another quickie project. This is an NTSC TV Interface, using the PIC12F1840. The hardware is simple - two resistors (1K ohm and 470 ohm), a PIC12F1840, a RCA composite video connector - and that's it.

It's only NTSC because that is how I programmed the timing. If you want PAL or SECAM, you will have to research the timing and incorporate those timings into the program.

For NTSC - 512 lines, interlaced. Each line has a 4us hsync (low) and then 60us of data. The vsync pulse is 60us low, then 4us high. So - vsync pulse, then 256 lines (hsync pulse then data), then another vsync, then the last 256 lines. Lather, rinse, repeat.

Timings are CRITICAL. You want each line of equal length. A 4us hsync, then 60us of data, then another hsync, then _58_us of data will cause jitter. If you get the timing right, the display locks in very nicely to the signal.

My target composite video device is a Sony PS1 LCD display. Running the PIC at 32Mhz, I can get theoretically get a 32 bit x 512 line display. Yeah, not great, but you _can_ do something with it. Just look at the pic.

Right now I am working on retrieving the video data from the EEPROM. There's enough space for 64 lines (32x64 display) - or, I may split it into 2 video pages (32x32 display, 2 pages). That's enough to do some blocky graphics.

All in all, a very interesting night. I haven't dealt with composite video (with horizonal and vertical sync, front porch, back porch, etc.) in a long time - not since my CMX/Orrox days.


  1. Nicely done, Timothy. Can you share any software at this time, Sir?

    Happy Holidays...

  2. Thank you, Sir!

    What is the best way to post a large chunk of source code to blogger? I don't want to just create a new post and drop the whole mess into it.

    Merry Christmas and Happy Royal Plowing Day to you!!!

  3. you could drop code into pastebin
    or equivalent ?

  4. Yes! Thank you. It will be posted as an update to this post (at the top) shortly.

    Thanks again!