Monday, April 18, 2011

Easier method of color generation for NTSC Television

 Please read this and this (optional) for better understanding before you read this post.

Few popular methods used to generate different colors for NTSC are
1. using AD725 IC for RGB values to NTSC color conversion
2. using a standard 3.579545MHz as the color carrier and producing different delays to get different phase and in-turn different colors in NTSC. This can be done by using a number of buffers to create delays and selecting the required color among these delayed signals by the use of a multiplexer.

The first method takes the fun out of it and the second method requires a lot of hardware. So for everyone searching for a new easier method to generate a good amount of colors for NTSC TV, you are in the right place and reading the right post!!

The idea is very simple. It involves PWM and diodes. The number of colors that you can generate will depend on the number of double edge PWMs available in your microcontroller. In LPC1768 we can use all the 6 PWM channel outputs to generate 64 (2^6) solid colors. Taking into account the shades of luminance you can create, a lot of color shades can be created here with minimal hardware. In the Blueboard LPC1768-H there are only 5 PWM channel outputs are accessible. But currently keeping 4-bits for luma and 4-bits for chroma, only 4 channels are used.

The idea is to generate different phases at different PWM channels and add them suitably to get different colors. To do this the LPC clock frequency should be a multiple of the color carrier 3.579454MHz. 85.90908MHz (3.579545 * 24) can be used as the PLL generates this with less error when compared to other frequencies. Now keeping

    LPC_SC->PCLKSEL0 |= 1 << 12; // PCLK_PWM1 = CCLK

    // This is the PWM time period. 24 is chosen as the CPU freq is 24 times the color carrier.
    MR0 = 24; 

    LPC_PWM1->MR1 = 1;
    // Channel 2 output will be high from 1 to 6
    LPC_PWM1->MR2 = 6;
    // Channel 3 output will be high from 6 to12
    LPC_PWM1->MR3 = 12;
    // Channel 4 output will be high from 12 to 16
    LPC_PWM1->MR4 = 16;
    // Channel 5 output will be high from 16 to 24
    LPC_PWM1->MR5 = 24;

Channel 4 will be used as color burst in this case. The on time duration of it is made low in the intention of getting higher color saturation. As the on time duration of this signal is low, its average value will be lower than other channel signals. Thus higher color saturation achieved.

As each channel has different phase signals, we already have 4 colors. I said earlier that we can get (2^4) 16 basic colors by using 4-bits for chroma. The extra 12 colors are obtained by adding the outputs of these 4 channels in a controlled manner. By adding channel 2 and channel 4's outputs a new phase is obtained and hence a new color. Like this we can add these 4 channels in 16 different ways and thus we can get 16 basic colors (two or three of them can be gray. For example if all channels are added or if no channel is added we get gray).

Now the question is how to add these signals. Using an analog 4 channel adder is complex than the buffer method mentioned above. So what another way is there in which we can add signals? Simple answer is by shorting the wires in which those two signals are present. But shorting does not sound good as it has many disadvantages like sourcing and sinking problems of the peripherals (they might get damaged due to high currents) and influence of one signal on the other will be too high. So here is one novel method to add these colors.

The novel method is to put a diode in all the signal paths and to short the outputs of these diodes!! As the diodes conduct in only one direction, both the problems stated above are solved. Now the big question is how to controll the addition? For that there is another very simple solution!! Making use of the open drain feature of the GPIO ports, we can put HIGH and LOW on the pins which are configured in open drain mode and control the addition. If an HIGH is put in an open drain output pin, that pin will be in high impedance state and if a LOW is put, the pin will be grounded and the output will be LOW. So by connecting 4 open drain GPIO pins to the PWM channel outputs we can control and generate any of the 16 basic colors at a time.
The schematic of the circuit is shown below.

If you have access to all 6 channels of PWM and are willing to assign 6-bits for chroma you can use Match Register values like

    MR0 = 24;
    // Channel 1 output will be high from 24 to 4 
    MR1 = 4;
    // Channel 2 output will be high from 4 to 8 
    MR2 = 8;
    // Channel 3 output will be high from 8 to 12
    MR3 = 12;
    // Channel 4 output will be high from 12 to 16 
    MR4 = 16;
    // Channel 5 output will be high from 16 to 20 
    MR5 = 20;
    // Channel 6 output will be high from 20 to 24 
    MR6 = 24;

You can keep one of the signals high for a less duration to get greater color saturation.

The results obtained by this method of color generation can be seen in the below pics. Here each pixel is represented by an 8-bit number out of which 4-bits are used for chroma and 4-bits for luma. Hence you can see there are 16 brightness levels and 16 basic colors. In combination there are 256 shades of colors!!

A method similar to this devised and tested by me and my friend is here.

No comments: