Horizontal sync is generated by OC1 (Output Compare 1) register, which is syncronized to T1 (Timer 1). For the full horizontal clock syncronization, special routine is executed after each horizontal sync signal, otherwise permanent horizontal jitter would be generated. This routine is very important in software driven video signal, and it computes (blue) and executes (red) the series of NOPs to get proper horizontal timing.

 1:   btss IFS0,#T1IF     ; test horizontal sync interrupt flag
     bra 1b              ; wait for horizontal sync
mov #14,w0          ; minuend (may be changed to adjust horizontal picture position)
     subr TMR1,WREG      ; 14 - TMR1 ---> w0

repeat w0
nop                 ; repeat 14-TMR1 times until TMR1 is exactly 14
     bclr IFS0,#T1IF     ; reset horizontal sync interrupt flag

Vertical sync is generated by software. Timer 2 generates interrupts in variable timing periods, and it services four different events:

1. Vertical sync (one dummy line plus two lines)
     2. Markers for automatic monitor adjustment (one dummy line plus one line)
     3. Main graphical image (one dummy line plus 240*2 lines)
     4. Bottom line text image (one dummy line plus 10*2 lines)


Each of those events is initiated by T2 (Timer 2) interrupt. Special counter (VGATASK), which counts interrupts in the range 0...3, determines which routine will be executed. At the end of that routine, the number of lines (timing until next routine) is written to PR2, so that T2 triggers new interrupt at the right moment. These timing may be used to adjust vertical position of each picture portion.

Red coordinates on the previous picture signify the periods in which the non-interrupt program code (game scenario and logic, keyboard scan, pointer and sprite servicing, etc) is executed. Black ondes belong to the video sync (black line at the top of the drawing) routine, monitor auto adjusting markers (two blue lines at the top), main image and bottom line text. Blue coordinates (1 lines each) are for timing syncronization.

The polarity of both sync signals is positive. Although 24E-series PIC MCU use only 3.3 V power supply, some port pins are 5V tolerant, not only as input, but also as output, when they are defined as Open Drain output pin. In that case, pull-up resistors to +5 V are used to define high output voltage level.

    Back to projects 
1. Home
2. Hardware
3. Video signal
4. Sound
5. Sync
6. Jumping Jack
7. Download