Colour Carrier Modulation

It is relatively simple to convert the digital video pixel data into their analogue signals, like so:

Digital:       Analogue:
R --> 6847
analogue
circuitry
--> VIDEO_R
G --> --> VIDEO_G
B --> --> VIDEO_B
HSYNC --> --> VIDEO_LUM
VSYNC --> --> VIDEO_SYNC

The function is to buffer the signals from logic levels to video levels (0-1V) and impedances (75R).

In the early 80s TVs could not accept these signals directly, only in the form of an RF modulated signal. So modulation circuits appears in all old micros that sent a colour signal to a TV. It's a bit mysterious to me, being both analogue and RF.

Key blocks of PAL video analogue modulator

Sync Luma
matrix
------------- --+-- --> Luma
R   v  
G   Comp
video
amp
--> Composite
B  
  |     ^  
  |
+-->
B'-Y'
matrix
U
modulator
U+V
mixer
 
  |     --> Chroma
  |
+-->
R'-Y'
Matrix
V
modulator
 
      ^    
Half
line
freq.
--------> +/-90º
phase
switch
<---- Colour
sub-carrier
oscillator
           

Analogue modulators

TELEVISION PRINCIPLES AND PRACTICE states that the modulation is thus:

Y  = 3/10* R + 53/90 * G + 1/9 * B
Cr = R - Y
Cb = B - Y

Using the lowest common denominator:

Y  = (27 * R + 53 * G + 10 * B) / 90

This is easily reversed at the TV, where:

R = Cr + Y
B = Cb + Y
G = Y - R - B

Your VHDL code will probably be restricted to the digital domain.
It might be easiest to leave the division-by-90 and subtractions to the analogue domain.

Lets assume that full-scale R,G,B is 90 units.

27 * R + 53 * G + 10 * B = 2430 + 4470 + 900 = 8100 = 1fa4 hex = 111111
0100100.

You could put the top 6 or 8 bits into a video DAC to get the Y signal, put R and B through similar DACs, then have a video op-amp circuit doing weighted subtractions.

Rickard Gunee's electronic projects page says that "one variation is the white level as PAL was developed after NTSC and has hence more accurate coefficients to the newer more luminant phosphors used in modern CRTs".

NTSC:	Y = 0.299 * R + 0.587 * G + 0.114 * B
PAL:	Y = 0.222 * R + 0.707 * G + 0.071 * B
222 =   11011110
707 = 1011000011
 71 =    1000111
200/900 = .222 recurring
700/900 = .777 recurring
636/900 = .706666 recurring
 64/900 = .071111 recurring
  110010
10101111
   10000
PAL:	Y = ( 50 * R + 159 * G + 16 * B ) / 225
PAL:	Y = ( 110010 * R + 10101111 * G + 10000 * B ) / 11100001 binary
PAL:	Y = ( 110010 * R + 10110000 * G - G + 10000 * B ) / 11100001 binary

 

2/9 + 7/10 + 7/100

Digital modulators

However, their circuits have a lot in common, and often had this structure:

R --> High
speed
digital
logic
--> Resistor
network
==> Chrominance signal(s):
G --> -->   one for PAL systems,
B --> -->   two for NTSC systems.
SYNC --> -->    
BURST --> -->    
U --> -->    
V --> -->    
    -->    

The high speed digital logic block can be done discrete TTL, or more conveniently with a small fast ROM (typically the 74S188 bipolar PROM). We can read the discrete logic of the BBC micro:

A 17.734475 MHz signal is divided by four to provide the 4.43361875 MHz colour subcarrier frequency. Two signals are generated at this frequency, with a phase difference of 90 degrees. The one that is 'In Phase' is modulated with the Red-Luminance, or R-Y signal. The other, with a 90 degree lag, carries the Blue-Luminance, or B-Y signal.

This subcarrier Phase = Hue, and Amplitude = Saturation. The higher the amplitude, the more saturated the colour. Where there is no colour content, the subcarrier will disappear.

The quadrature colour-difference signals "U" and "V" are produced on pin 9 of IC46 and pin 11 of IC48 respectively. The horizontal synchronisation pulses produced toggle the "V" colour difference signal polarity. This produces the required alternating phase signal for each horizontal line scan.

Exclusive OR gates (IC47 and IC48) generate the yellow, cyan, green, magenta, red and blue colours according to the phase relationships of the "U" and "V" signals. These signals are then "mixed" by six NAND gates.

The colour burst gate signal is generated using an inverter and a NOR gate. This arrangement is timed by a CR network (C45 and R189) thus producing a burst gate pulse in the back porch period of the line scan. The burst gate signal is also mixed using the NAND gate mixer.

-- Signals
-- PalPhaseA	The 4.433 MHz PAL carrier, phase= 00º
-- PalPhaseB	The 4.433 MHz PAL carrier, phase= 90º
-- chroma_burst Active for 10 cycles of 4.433 MHz, just after HSYNC
-- pal_switch	Odd/even line signal, to alternate the phase

signal_V = pal_switch xor PalPhaseB;	-- Phase Alternation of PAL signal

u48a = G xor signal_V;			-- Alternating
u48b = B xor signal_V;

u47c = B xor signal_U;			-- Non-alternating
u47d = G xor signal_U;
					-- chroma burst:
u50a = not ( u47d and chroma_burst ) ;	-- to R157 (680R)
u50b = not ( u48b and chroma_burst ) ;	-- to R155 (680R)

u47a = R xor G;				-- to R148 (820R). 1 if G != R
u47b = G xor B;				-- to R156 (1K2).  1 if G != B
u49a = not ( u47a and u47d ) ;		-- to R152 (2K2)
u49b = not ( u47b and u47c ) ;		-- to R150 (680R)
u49c = not ( u47b and u48b ) ;		-- to R154 (470R)
u49d = not ( u47a and u48a ) ;		-- to R158 (470R)
RGB	u47a,b	u49a,b,c,d
000	00	1
001	01	1
010	11	0
011	10	1
100	10	1
101	11	0
110	01	1
111	00	1

Limitations

Note that this digital processing assumes the colour guns are either on or off, which prohibits the Atom's official orange colour. I suspect that extending the colour phase-modulation circuit would be non trivial. A compromise might be to have orange as lower-intensity red, as this only affects the luminance part of the circuit. Acorn's own Atom colour board just used red, which is the nearest match.

The Atari has twice the phase resolution of the Acorn circuit, so needs a clock twice as fast as the Acorn. My PAL Atari has a video timing crystal of 14.875576 MHz, which is not a multiple of the PAL 4.43361875 MHz colour carrier. 17.734475 MHz would be 4x carrier but I don't see a crystal so marked. 14,187,576.00 is Atari crystal Y1 in my machine, nearest the memory controller chip. This is 3.2 times 4.4336175, nearly but not quite the PAL colour subcarrier. There is one unmarked crystal in the video circuit area.

The Atom 60Hz colour card uses a 4.43361875 MHz then phase shifts this carrier signal.
The BBC micro uses a 17.734475 MHz driving a twisted-ring counter to get the four phases.
The latter method requires less analogue circuitry but the crystal is less commonly available.

Off the shelf modulators

Alternatively one might forego the 'DIY' modulation and just use a dedicated RGB encoder (AD722, AD724, AD725, CXA1645P, CXA2075M, TDA8501) which takes Luminance and analogue RGB signals, then modulates them for PAL or NTSC. The only thing the FPGA need do is drive three video DACs.

The downside is that you need to find and buy one of these chips, which is easier said than done. I had a look around UK suppliers and I can report that as of the time of writing, Farnell don't sell any of them. RS Components sell only the Sony CXA1645P for £6.13+VAT. It adds an extra part to find but there has to be some kind of buffering between the FPGA digital ouputs and the 75 ohm analogue signal outputs. It might as well be this chip which has 75 ohm drivers and modulates PAL/NTSC into the bargain.

Off the shelf video DACs

The simplest solution is to build a textbook R/2R resistor ladder. Resistors are commonly available to 1% accuracy, which is adequate up to about 6 bits which requires 1/64th accuracy. Most old machines only had 1 to 4 bits per colour gun. If building such a resistor ladder, try to use resistors cut from a bandolier, as these are more likely to be better matched. Also try to find a group of 'R' and '2R' resistors that are most closely in proportion. Finally, of these resistors try to use the most accurate ones at the MSB end.

I wasnted to make a prototype board that could render colour to 8 bits per gun, and as I don't have easy access to resistors accurate to 1 part in 256, I decided to use off-the-shelf DAC chips. TDA8702 chips is available from RS Components, at £3.11 each. Dearer than 16 resistors but less hassle to fit.

A variety of higher integration video DACs exist, such as the ADV7120 (3x8bits in DIP40, PLCC44 or TQFP48) but are harder to obtain and tend to be surface-mounted: not convenient on a prototyping board. Others can take take digital video from an MPEG data stream. This is conveniently just 8-bits wide, but the data is luminance and chrominance encoded. Convenient for video pictures but less suited to sharply resolved text and fine detail.

RAMDACs are also fairly common, taking up to 8-bits pixel data in and driving three analogue RGB pins. However, they are designed for analogue monitors and so the digital RGB data are not taken to physical pins. This saves about 24 pins which is a good thing for analogue-only systems. I want the digital palette data accessible so that I could perhaps send them to an LCD panel in the future. For this reason I decided to keep the palette and the DACs seperate. The palette can be implemented inside an FPGA.

Using the TDA8702 video DACs

The data sheet states the output signal is 0.8V pk-pk with a 75R load, or 1.6V with a 10k load. I calculated that a 125R load would give the 1V pk-pk signal required by the CXA1645P modulator. 120R is the nearest value.

I wanted to test one DAC before doing all three, then considered that it would probably be quicker to wire the two extra chips than to invent some way of testing the single DAC.

Initial results

I found that when the DACs are loaded with 120R, the s-video output was poor. The colour yellow appeared as brown, indicating the luminance was too low. The DAC signals were obviously not big enough for the modulator. They were big enough to drive SCART RGB signals, yellow appearing as yellow. Theses signals are meant to be 0V7 pk-pk, and reducing the DAC loads to 75R makes this so and yellow remained the correct colour.

Colour Carrier Quartz Crystals

I can easily find 1x and 4x the NTSC carrier (it is used in all PCs) and 1x PAL carrier crystals (used in PAL TVs) but for some reason the 4xPAL carrier frequency is not at all common. Perhaps because it is only of use at PAL transmitters. I ordered one from RS components, but it is also available fromGolledge and Euroquartz (UK), Comtec (Germany), Jewon (Korea). Golledge have 4xPAL as a standard frequency for crystals, but currently not the 5V oscillators. No standard frequencies are mentioned in the 3V3 range data sheet.

  Frequency Manu. Case load/pF stability
/ppm
accuracy
/ppm
RS
stock
1 off:
Crystal 17.73447  CMAC  HC49 30 100 50 130-8939 £0.94
Crystal 4.43361875  AEL HC18U 20 30 20 300-798 £0.59
Oscillator 14.3818 CMAC DIL8 - - 100 174-1005 £1.46

Suitable TVs

Wanting to progress with this project, I found my PC TV card was not ideal. The s-video black level appeared as grey, although it did appear black on a real TV. I assume this is a problem with my PCTV card. Also, s-video does not seem to be very good. To avoid wondering whether problems were with my circuits or my PCTV, I was going to need a real TV. I had access to one but I did not want to be carrying the big 25" TV up stairs or my battery-powered circuits downstairs every time I needed to test something. So I shopped around for a TV I could put in my room.

I found that although Toshiba TVs have a tuner for PAL signals, they can also display NTSC video signals. So although you cannot tune in to NTSC broadcasts, you can view NTSC videotapes. This is useful to me, because I can test out my circuits in NTSC mode without having to take them to the USA. Toshiba seem to be the only makers of TVs with this feature.

The Toshiba 15V11 looked ideal. This has two SCART sockets, front AV sockets, headphone socket, teletext, a 15" flat screen, fasttext, weighed just 11 kg and priced at £163. For £2 more, I could also buy a 21" model with NICAM sound. However this is 23 kg and takes a lot more space which I can't really spare. So I ordered the 15" model.

Colour Carrier Oscillators

There are many ways to design an oscillator. A simple example uses two inverting logic gates, two resistors, one capacitor and one crystal. Such a circuit is used in the Atom and BBC micro. Given that PALx4 oscillator modules seem rare, my first effort created this frequency from the synthesiser of my FPGA development board. Although I did get a picture, the colour was pale and noisy. A clue to the cause was that the vertical edges of the picture jittered. I suspect the synthesised frequency had jitter, inherent from the fact that the master frequency was not an exact ratio of the base frequency (20MHz). I tried settings that were less accurate but with less jitter, with no improvement.

I thought of replacing the base crystal with a PALx1 crystal, but the on-line calculator warned the synth chip could not use a frequency that low. A PALx4 crystal frequency caused no complaints, but I did not have one. So I ordered one from RS.

I notice that the Atom and the BBC micro colour carrier oscillators use a more complex circuit than the simple two-inverter circuit. Based on discrete components, it includes a trimmer capacitor for fine-adjustment of the carrier frequency. This indicates that the frequency must be more precise than the standard crystal accuracy (typically 100 ppm, which is +/- 443.3 Hz for a PALx1 crystal). The PAL TV standard requires the frequency to be 4,433,618.75 Hz +/- 5 Hz, which is about 1 ppm! This explains the need for trimmable frequency.

None of the common crystals or oscillator modules are that accurate, so there seems no avoiding the trimmable oscillator circuit.

NTSCx4 oscillators are widely used in PCs, but these do not have to be very accurate because they are not used for generating a colour carrier.

 


 

Angle H Sample Name  
0   Red  
  20      
  25      
30º 30   Orange  
  35   Gold  
60º 40   Yellow  
90º 50      
120º 80   Green  
150º 110      
180º 120   Cyan  
210º 130   Powder blue  
240º 160   Blue  
270º 190   Purple  
300º 200   Magenta  
330º 210   Rose  

Pre-calculated YUV palette

It is not very efficient use of logic to do the RGB to YUV conversion in VHDL because it will use a lot of logic to create the various multipliers, adders, dividers etc. However, if you do not need to cope with 90 levels on each colour gun then you can have a palette of pre-calculated values. The table below was easily created using Excel. Using 180 as the maximum value produces integer YUV values, though of course you can scale these for other maxima with some rounding errors.

180 R G B Y U V      
Black 0 0 0 0 0 0 00000000 00000000 00000000
White 180 180 180 180 0 0 10110100 00000000 00000000
                   
Red 180 0 0 54 126 -54 00110110 01111110 11001010
Green 0 180 0 106 -106 -106 01101010 11001100 11001100
Blue 0 0 180 20 -20 160 00010100 11101100 00010100
                   
Yellow 180 180 0 160 20 -160 00010100 00010100 01100000
Cyan 0 180 180 126 -126 54 01111110 10000010 00110110
Magenta 180 0 180 74 106 106 01001010 01101010 01101010
                   
Orange 180 90 180 127 53 53 01111111 00110101 00110101

The Luminance only really needs about 6 bits resolution, Chroma even less (perhaps 3 bits each for 64 colours?)