;Precision PAL/NTSC SYNC generator ;PIC16F631/677/685/687/689/690 ;20MHz Crystal ;200ns Instruction execution time ; ;One instruction cycle consists of four oscillator periods; ;for an oscillator frequency of 4 MHz, this gives a normal ;instruction execution time of 1 µs. All instructions are ;executed within a single instruction cycle, unless a ;conditional test is true, or the program counter is ;changed as a result of an instruction. When this occurs, ;the execution takes two instruction cycles, with the ;second cycle executed as a NOP. #include errorlevel -302, -307 ; this line to remove banking warning __config (_HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF) cblock 0x20 pulse_counter ;Define file registers for counter and pulse timers. pulse_low_timer pulse_high_timer active_line_timer endc ;------------------------------------------------------------------------------------------------------------------------------------ org 0 Start bsf STATUS,RP0 ; select Register Page 1 clrf TRISA ; make IO Port A output clrf TRISB ; make IO Port B output clrf TRISC ; make IO Port C output bcf STATUS,RP0 ; back to Register Page 0 clrf PORTA clrf PORTB clrf PORTC clrf pulse_counter ;Clear counters clrf pulse_low_timer clrf pulse_high_timer clrf active_line_timer ;------------------------------------------------------------------------------------------------------------------------------------- ;------------------------------------------------------------------------------------------------------------------------------------- ;START OF PAL CODE BLOCK////////////////////////////////////////////////////////////////////////////////////////////////////////////// ;------------------------------------------------------------------------------------------------------------------------------------- ;------------------------------------------------------------------------------------------------------------------------------------- PAL ;This section generates PAL sync pulses - Starts at the end of odd field --622 lines up to here do_half_PAL_line ;Half of line 623 --622.5 lines up to here call half_PAL_line movlw d'5' ;5 Pre-equalisation pulses movwf pulse_counter do_equalisation_pulses_0_PAL call equalization_pulse_PAL decfsz pulse_counter goto do_equalisation_pulses_0_PAL ;--625 lines up to here ;--------------------------- End of odd field ------------------------------------------------------------------------------- ;--------------------------- Start of even field - 5 Field sync pulses ------------------------------------------------------- ;----------------------------------------------------------------------------------------------------------------------------- movlw d'5' movwf pulse_counter do_field_sync_pulses_0_PAL call field_sync_PAL decfsz pulse_counter goto do_field_sync_pulses_0_PAL ;-------------------------- Start of even field - 5 Post equalisation pulses -- 2.5 lines up to here movlw d'5' movwf pulse_counter do_equalisation_pulses_1_PAL call equalization_pulse_PAL decfsz pulse_counter goto do_equalisation_pulses_1_PAL movlw d'10' movwf pulse_counter do_line_sync_PAL_0 ;Do line sync pulses 6-15 (10 lines) without any "RECORD PCM SAMPLE" indicator pulse -- 5 lines up to here call line_sync_PAL_0 decfsz pulse_counter goto do_line_sync_PAL_0 ;-- 15 lines up to here ;-------------------------- Even field - Normal lines 16 - 158 ;next 294 lines used for PCM samples, 6 samples/line movlw d'143' movwf pulse_counter do_line_sync_pulses_00_PAL call line_sync_PAL decfsz pulse_counter goto do_line_sync_pulses_00_PAL ;-- 158 lines up to here ;-------------------------- Even field - Normal lines 159 - 310 movlw d'151' movwf pulse_counter do_line_sync_pulses_01_PAL call line_sync_PAL decfsz pulse_counter goto do_line_sync_pulses_01_PAL ;-- 310 lines up to here ;-------------------------- End of even field - 5 Pre equalisation pulses movlw d'5' movwf pulse_counter do_equalisation_pulses_2_PAL call equalization_pulse_PAL decfsz pulse_counter goto do_equalisation_pulses_2_PAL ;--312.5 lines up to here ;-------------------------- End of even field -------------------------------------------------------------------------------- ;----------------------------------------------------------------------------------------------------------------------------- ;-------------------------- Start of odd field - 5 Field sync pulses --------------------------------------------------------- movlw d'5' movwf pulse_counter do_field_sync_pulses_1_PAL call field_sync_PAL decfsz pulse_counter goto do_field_sync_pulses_1_PAL ;--315 lines up to here ;-------------------------- Start of odd field - 4 Post equalisation pulses movlw d'4' movwf pulse_counter do_equalisation_pulses_3_PAL call equalization_pulse_PAL decfsz pulse_counter goto do_equalisation_pulses_3_PAL movlw d'10' movwf pulse_counter ;--317 lines up to here do_line_sync_PAL_00 ;Do line sync pulses 318-328 without any "RECORD PCM SAMPLE" indicator pulse call line_sync_PAL_0 decfsz pulse_counter goto do_line_sync_PAL_00 ;--327 lines up to here ;-------------------------- Odd field - Normal lines 328 - 470 ;next 294 lines used for PCM samples, 6 samples/line movlw d'143' movwf pulse_counter do_line_sync_pulses_10_PAL call line_sync_PAL decfsz pulse_counter goto do_line_sync_pulses_10_PAL ;--470 lines up to here ;--------------------------- Odd field - Normal lines 471 - 622 movlw d'151' movwf pulse_counter do_line_sync_pulses_11_PAL call line_sync_PAL decfsz pulse_counter goto do_line_sync_pulses_11_PAL ;--622 lines up to here goto PAL ;------------------------------------------------------------------------------------------------------------------------------------- ;PAL signal generator functions/////////////////////////////////////////////////////////////////////////////////////////////////////// ;------------------------------------------------------------------------------------------------------------------------------------- half_PAL_line ;Function to generate HALF of complete 64 microsecond line - 4.6 microseconds sync level followed by ;27.4 microseconds black level - PORTC,bits 0 and 1 ;Video is not active during this line nop clrf PORTC ; Set PORTC output to sync level movlw D'5' movwf pulse_low_timer ; Pulse remains low for 4.6 microseconds movlw D'43' movwf pulse_high_timer ; Pulse remains high for 27.4 microseconds line_sync_pulse_PAL_half decfsz pulse_low_timer goto line_sync_pulse_PAL_half nop bsf PORTC,0 ;1 Set PORTC output to black level black_level_video_PAL_half decfsz pulse_high_timer goto black_level_video_PAL_half nop return ;------------------------------------------------------------------------------------------------------------------------------------- field_sync_PAL ;Function to generate field_sync pulse - 27.4 microseconds sync level followed by 4.6 microseconds black level nop clrf PORTC ;1 Set port output to sync level movlw D'44' movwf pulse_low_timer ; Pulse remains low for 27.4 microseconds movlw D'5' movwf pulse_high_timer ; Pulse remains high for 4.6 microseconds long_low_pulse_PAL decfsz pulse_low_timer goto long_low_pulse_PAL nop bsf PORTC,0 ;1 Set port output to black level short_high_pulse_PAL decfsz pulse_high_timer goto short_high_pulse_PAL return ;This funtion simulated and tuned correctly. ;------------------------------------------------------------------------------------------------------------------------------------ equalization_pulse_PAL ;Function to generate Pre-and Post equalization pulses - 2.4 microseconds sync level followed by 29.6 microseconds black level nop clrf PORTC ;1 Set port output to sync level movlw D'23' movwf pulse_high_timer ; Pulse remains high for 29.6 microseconds short_low_pulse_PAL nop ;1 nop ;1 nop ;1 nop ;1 nop ;1 nop ;1 nop ;1 nop ;1 nop ;1 ;----------------------------- bsf PORTC,0 ;1 Set port output to black level long_high_pulse_PAL nop ;1 nop ;1 nop ;1 decfsz pulse_high_timer ;1 goto long_high_pulse_PAL ;2 nop ;1 nop ;1 return ;This funtion simulated and tuned correctly. ;------------------------------------------------------------------------------------------------------------------------------------ line_sync_PAL ;Function to generate complete 64 microsecond line - 4.6 microseconds sync level followed by 59.4 microseconds black level - PORTC,bits 0 and 1 ;Function also generates pulse on PORTB, bit 7 to indicate active line area - 5.4 microseconds after "bsf PORTC,0" there must be ;a 52 microsecond pulse movlw b'000000000' movwf PORTC movlw D'5' movwf pulse_low_timer ; Pulse remains low for 4.6 microseconds movlw D'95' movwf pulse_high_timer ; Pulse remains high for 59.4 microseconds line_sync_pulse_PAL decfsz pulse_low_timer goto line_sync_pulse_PAL nop nop nop movlw b'000000011' movwf PORTC black_level_video_PAL decfsz pulse_high_timer goto black_level_video_PAL nop nop nop nop return ;------------------------------------------------------------------------------------------------------------------------------------ line_sync_PAL_0 ;Function to generate complete 64 microsecond line - 4.6 microseconds sync level followed by 59.4 microseconds black level - PORTC,bits 0 and 1 ;Function also generates pulse on PORTB, bit 7 to indicate active line area - 5.4 microseconds after "bsf PORTC,0" there must be ;a 52 microsecond pulse ;This function keeps PORTC,1 low through out to indicate NOT to record PCMsamples movlw b'000000000' movwf PORTC movlw D'5' movwf pulse_low_timer ; Pulse remains low for 4.6 microseconds movlw D'95' movwf pulse_high_timer ; Pulse remains high for 59.4 microseconds line_sync_pulse_PAL_0 decfsz pulse_low_timer goto line_sync_pulse_PAL_0 nop nop nop movlw b'000000001' movwf PORTC black_level_video_PAL_0 decfsz pulse_high_timer goto black_level_video_PAL_0 nop nop nop nop return ;------------------------------------------------------------------------------------------------------------------------------------ end