Generating Composite Video

O.K. so after reading some about using the registers and applying it to some code I ended up with this


http://datablue.net/random/better_vid.AVI

Not perfect, but alot better than before!
This code still doesn't incorporate the vertical sync because I can't get the timing right. I think It might have something to do with the loop I'm using.

/* Composite Video Generation
 * ------------
 *
 * uses a 2-bit D-A converter to generate
 * voltages for composite video to RCA. This
 * code should generate continous white horizontal 
 * lines to create a fullly white TV
 *
 * Created 18 December 2006
 * copyleft 2006 Kyle Granat <http://www.datablue.net>
 * http://arduino.cc
 *
 * based on Rickard Gunée's pic work
 * http://www.rickard.gunee.com/projects/video/pic/howto.php
 * 
 * Register code from Cosine Kitty
 * http://www.arduino.cc/playground/Code/BitMath#registers 
 */


void setup()
{
        // set pins 0 (serial transmit) and 2 and 3 as output,
        // but leave pin 1 (serial receive) as input
        // (otherwise serial port will stop working!) ...
        DDRD = B00001101;  // digital pins 7,6,5,4,3,2,1,0
        // Turn off digital output pins 2 and 3
        PORTD &= B00000011;   // turns off 2..7, but leaves pins 0 and 1 alone

}

void loop()
{
  
  
    PORTD = B00000000;    // sets out to 0V for sync pulse for 4 uS 
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);

    PORTD = B00000100;//sets out to .33V  for 'porch'
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);
    delayMicroseconds(1);

    PORTD = B00001100;   //sets out to 1V(White)
    delayMicroseconds(52);   


}

My guess is that you might have some problems because of timer interrupts (or other interrupts?) messing up your timing. Just as an experiment, try adding this to the end of your setup():

cli(); // disable interrupts

Of course, this will mess up all kinds of stuff you might want to add later, like serial port I/O, use of timers, delay(), millis(), etc.

I say this because I was surprised when I tried generating radio frequency energy and encountered an unexpected tone modulated on top of what was supposed to be a pure carrier wave. See here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166896036

My guess is that you might have some problems because of timer interrupts (or other interrupts?) messing up your timing. Just as an experiment, try adding this to the end of your setup():

cli(); // disable interrupts

I disabled the interrupts but nothing noticable has changed. Thanks for the suggestion though.

I disabled the interrupts but nothing noticable has changed. Thanks for the suggestion though.

Any news? :slight_smile:

Here is a video overlay project using the ATmega8 [...]

http://www.knology.net/~gdion/videoverlay.html

Hi, do you understand what's Q1 specifications in that schematic?

Thanks,
Superware

Any news? :slight_smile:

Still working on it, though classes seem to be getting in the way :3
I might get a chance this weekend to tinker some more, but no real progress as of late.

Also q1 in the schematic is a pnp transtor. I'd imagine a 2n3906 would work fine.

I'm going to start work on an ASM version of this to get the timing exact.

How would I go about writing a block of ASM code in C? Would you just stick all the lines in an asm() ?

Looking forward to any updates on this. Also, anyone knows if it would be possible to create a video overlay (OSD) with Arduino?

Looking forward to any updates on this. Also, anyone knows if it would be possible to create a video overlay (OSD) with Arduino?

http://www.knology.net/~gdion/videoverlay.html

Thank Erik,

That is a very valuable link!

Cheers,

JD

hello,

I had the same idea : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176757335.

Now I'm giong to read your post, I have some timming pbroblems in interruption mode...

Hello,

I've read the post. You have the same problems :slight_smile: of timing.

Could we try to resolve them together ? My project is working in the loop() function, everything is ok. I try do it with interupt but I don't have an oscilloscope to fine tuning synchro.

Hi everyone,

I just stumbled on this thread while looking into something else entirely (curse you stream of consciousness browsing).

Some of us did this a few years ago with a pair of PIC 18f452s in CSS C at 40MHz. One PIC set up the video environment, and on interrupt we used a second one to read inputs and do our "drawing" routines.

As I recall, it was a pretty crude effort, but it worked well enough for our purposes. You can look at the project notes and code here : http://droolcup.com/pictv

~s

Hello droolcup,

Thank's for your post. I've just seen the video of your project. I have the same result with interrupt, one somme image configuration there some lines are "overshooting", it depends of the white surface on screen...

I think I'll have to write some parts of the code in asm to be sure of timings.

The best way that I've seen to do this is by using 2 micros- one of them is programmed in ASM and reads the pixel data from a ram chip, which the other micro updates. There would be a sync line between the two to make sure one isn't trying to write while the other is reading. This would eliminate timing problems and also allow for more complex programs to be run.

I'm thinking of giving this approach a try soon- what does everyone think?

Maybe this is just crazy talk, but couldn't you try and generate your sync signal with a bi-stable oscillator, you'd want to watch that with the MCU so that you don't keep sending data as your sync goes off, if not using the oscillator directly, you could use it to keep track of were you are in your output (send the sync with the MCU, but use the oscillator to time everything right.

(Please excuse any tyops I've made, it's late, and it's hard for me to keep up with my high standard of typing when I'm tired.)

Hello,

Yes, I'm thinking about soltions with external components. But, at first I want to do it the best without active components. It's a challenge with Arduino Board :). I will try with some asm code include in C code...

Hey Benoît ROUSSEAU,

Just want to say good luck! I hope you'll find a way to get it to work eventually, meanwhile I can dream about arduino pong!

-Z-

I stumbled upon a site where they sell all kinds of electronic video/audio instruments. There's a lot of interesting information about how these guys managed to get the video output running.. They use a ARM7TDMI Microcontroller in conjunction with an AD725 RGB to PAL/NTSC encoder IC from Analog Devices. They run a crystal at 4 times the video burst frequency to get stable output, it still only handles 256 colors at a 160 x 128 resolution. But it looks like lots of fun to play with, it could also be interfaced with an arduino board. Programming the microcontroller itsself requires C skills and the GNU toolchain, a flash utility and an USB board (i bet the arduino can also be used as an Serial/USB interface to program this board).

http://www.critterandguitari.com/catalog/index.php?main_page=product_info&cPath=1&products_id=13

Hi All,

Possibly this should be a new thread, but the "generating video bboard" is pretty close to my question:

Has anyone written code to detect the vertical blanking interval in an incoming NTSC composite video signal (RS-170A)?

I'm creating a project in which I need to switch a circuit on and off, precisely in sync with the video fields from an NTSC video source. In order to do this, I would need to sample the video signal fairly frequently and write an analyzer/detector for the vertical blanking interval, which is used to synchronise the video frames.

Any advice would be greatly appreciated before I bore headlong into the oscilloscope.
Thanks,
Golan