⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dve_ccir_vtg.v

📁 全电视信号编码器
💻 V
📖 第 1 页 / 共 3 页
字号:
always @(posedge sclk)
 if (!srst_n) sm_tip_state<=`SYNC_TIP_LEADER;
 else sm_tip_state<=sm_tip_next;
	
always @(sm_tipstat or start_sync or end_sync)
  case (sm_tipstat)
	  `SYNC_STAT_PASSIVE: if (start_sync) sm_tipstat_next=`SYNC_STAT_ACTIVE;
	  		else sm_tipstat_next=`SYNC_STAT_PASSIVE;
	  `SYNC_STAT_ACTIVE:  if (end_sync) sm_tipstat_next=`SYNC_STAT_PASSIVE;
	  	    else sm_tipstat_next=`SYNC_STAT_ACTIVE;
  endcase	 
		
always @(posedge sclk)
 if (!srst_n) sm_tipstat<=`SYNC_STAT_ACTIVE;
 else sm_tipstat<=sm_tipstat_next;

// -----------------------------------------------------------------------------
// Color burst control
// -----------------------------------------------------------------------------
// In PAL mode, color burst is disabled on lines 1-6, 310-318, 623-625 inclusively
// for fields 1,2,5,6
// and lines 1-5, 311-319, 622-625 inclusively
// In NTSC mode, color burst is disabled on lines 1-6, 261-269, 523-525 (non SMPTE numbering)
assign color_burst_on = (coding_ntsc) ?
       ((line_counter == `LINE_NUMBER_7) |
        (line_counter == `LINE_NUMBER_270)) :  
       (((line_counter == `LINE_NUMBER_7) && sm_first_frame_reg) | 
       ((line_counter == `LINE_NUMBER_319) && sm_first_frame_reg) |
       ((line_counter == `LINE_NUMBER_6) && !sm_first_frame_reg) |
       ((line_counter == `LINE_NUMBER_320) && !sm_first_frame_reg));
              

assign color_burst_off = (coding_ntsc) ?
       ((line_counter == `LINE_NUMBER_261) | 
        (line_counter == `LINE_NUMBER_523)) :
       (((line_counter == `LINE_NUMBER_310) && sm_first_frame_reg) | 
       ((line_counter == `LINE_NUMBER_623) && sm_first_frame_reg) |
       ((line_counter == `LINE_NUMBER_311) && !sm_first_frame_reg) |
       ((line_counter == `LINE_NUMBER_622) && !sm_first_frame_reg));

	   
assign line_video_on = (coding_ntsc) ?
     ((line_counter == `LINE_NUMBER_17) |
	  (line_counter == `LINE_NUMBER_282)) :
	 ((line_counter == `LINE_NUMBER_24) |
	  (line_counter == `LINE_NUMBER_336));
	 
assign line_video_off = (coding_ntsc) ?
     ((line_counter == `LINE_NUMBER_260) |
	  (line_counter == `LINE_NUMBER_523)) :
	 ((line_counter == `LINE_NUMBER_311) |
	  (line_counter == `LINE_NUMBER_623));

	  
assign active_video_on = (coding_ntsc) ?
      (timeline_counter == `NTSC_VIDEO_ENABLE) : (timeline_counter == `PAL_VIDEO_ENABLE);
assign active_video_off = (coding_ntsc) ?
      (timeline_counter == `NTSC_VIDEO_DISABLE) : (timeline_counter == `PAL_VIDEO_DISABLE);
  
	  
// -----------------------------------------------------------------------------
// Line blanking state machine, activates the video per current line
// -----------------------------------------------------------------------------
always @(posedge sclk)
 sm_activeline_reg <= srst_n & (( ~sm_activeline_reg & line_video_on) |
                      (sm_activeline_reg & ~line_video_off));
	   
// -----------------------------------------------------------------------------
// Line blanking state machine, activates the video per current line
// -----------------------------------------------------------------------------
always @(posedge sclk)
 sm_videoenable_reg <= srst_n & (( ~sm_videoenable_reg & sm_activeline_reg & active_video_on) |
                      (sm_videoenable_reg & ~active_video_off));
// -----------------------------------------------------------------------------
// ColorBurst state machine, enables the color burst per current scan line
// -----------------------------------------------------------------------------
always @(posedge sclk)
 sm_burst_enable_reg <= srst_n & (( ~sm_burst_enable_reg & color_burst_on) |
                        (sm_burst_enable_reg & ~color_burst_off));


// -----------------------------------------------------------------------------
// ColorBurst gate state comparators. Send the flag to switch on color burst
// -----------------------------------------------------------------------------
assign burst_gate_on =(coding_ntsc) ? 
       (pixel_counter==`NTSC_CBURST_ON) : (pixel_counter==`PAL_CBURST_ON);
assign burst_gate_off=(coding_ntsc) ?
       (pixel_counter==`NTSC_CBURST_OFF) : (pixel_counter==`PAL_CBURST_OFF);

// -----------------------------------------------------------------------------
// ColorBurst insertion state machine. Dynamically enables the color burst 
// -----------------------------------------------------------------------------
always @(posedge sclk)
 sm_burst_gate_reg <= srst_n & ((~sm_burst_gate_reg & sm_burst_enable_reg &
               burst_gate_on & sm_first_halfline_reg) |
               (sm_burst_gate_reg & ~burst_gate_off)); 

 
// -----------------------------------------------------------------------------
// 
// Burst polarity state machine .....
// PAL only. Equals to 1 every even line (starting from 0) in the first frame
// Equals to 1 every odd line (starting from 0) in the second frame
//
// -----------------------------------------------------------------------------
assign positive_v_flag = sm_first_frame_reg ^ line_counter[0] | coding_ntsc;

// -----------------------------------------------------------------------------
// 
// Timeline counter. Required for the precise video blanking and other 
// timeline functions (timecode, etc.)
// -----------------------------------------------------------------------------
always @(posedge sclk)
 if (~srst_n | last_line_sample & ~sm_first_halfline_reg) timeline_counter <= {PIXEL_COUNTER_WIDTH+1{1'b0}};
 else timeline_counter <= timeline_counter + {{PIXEL_COUNTER_WIDTH{1'b0}},1'b1};
	 
// -----------------------------------------------------------------------------
// 
// Color bars counter
// 
// -----------------------------------------------------------------------------
always @(posedge sclk)
 if (~srst_n | last_line_sample & ~sm_first_halfline_reg) color_bars_counter <= 3'd0;
 else if ((next_color_bar) && (color_bars_counter != 3'd7)) 
    color_bars_counter<= color_bars_counter + 3'd1;

always @(posedge sclk)
 if (~srst_n | (last_line_sample & ~sm_first_halfline_reg) | next_color_bar) bar_width_counter <= 8'd0;
 else if (sm_videoenable_reg) bar_width_counter <= bar_width_counter + 8'd1;

assign next_color_bar = (coding_ntsc) ? 
       (bar_width_counter == `COLORBAR_WIDTH_NTSC) : (bar_width_counter == `COLORBAR_WIDTH_PAL);

// -----------------------------------------------------------------------------
// 
// Clock gating state machine
// 
// -----------------------------------------------------------------------------
always @(posedge sclk)
 if (!srst_n)
  begin
   y_even_sample_reg <= 1'b0;	  
   y_gate_reg  <= 1'b0;
   cb_gate_reg <= 1'b1;
   cr_gate_reg <= 1'b0;
  end
 else
  begin
   cb_gate_reg <= (last_line_sample & ~sm_first_halfline_reg) | 
                  (~cb_gate_reg & y_even_sample_reg & y_gate_reg);
   y_gate_reg  <= ~y_gate_reg & (cb_gate_reg | cr_gate_reg);
   cr_gate_reg <= ~cr_gate_reg& ~y_even_sample_reg & y_gate_reg;
   y_even_sample_reg <= (~y_even_sample_reg & y_gate_reg) |
                        (y_even_sample_reg & ~y_gate_reg);
  end


// -----------------------------------------------------------------------------
// CHROMA/LUMA PIPELINE ADJUSTMENT & TIME RETENSIONING
// -----------------------------------------------------------------------------
always @(posedge sclk)
begin
 if (~srst_n)
  begin
   set_phase_flag_del_0_reg<=1'b0;
   set_phase_flag_del_1_reg<=1'b0;
   set_phase_flag_del_2_reg<=1'b0;
   set_phase_flag_del_3_reg<=1'b0;

   frame_num_del_0_reg <= 1'b0;
   frame_num_del_1_reg <= 1'b0;
   frame_num_del_2_reg <= 1'b0;
   frame_num_del_3_reg <= 1'b0;

   end_of_flag_del_0_reg <= 1'b0;
   end_of_flag_del_1_reg <= 1'b0;
   end_of_flag_del_2_reg <= 1'b0;
   end_of_flag_del_3_reg <= 1'b0;
  end
 else
  begin
   set_phase_flag_del_0_reg<=(last_line_sample & last_line & ~sm_first_halfline_reg);
   set_phase_flag_del_1_reg<=set_phase_flag_del_0_reg;
   set_phase_flag_del_2_reg<=set_phase_flag_del_1_reg;
   set_phase_flag_del_3_reg<=set_phase_flag_del_2_reg;

   frame_num_del_0_reg <= {~sm_fields_one_to_four_reg, ~sm_first_frame_reg};
   frame_num_del_1_reg <= frame_num_del_0_reg;
   frame_num_del_2_reg <= frame_num_del_1_reg; 
   frame_num_del_3_reg <= frame_num_del_2_reg;

   end_of_flag_del_0_reg <= last_line_sample & ~sm_first_halfline_reg;
   end_of_flag_del_1_reg <= end_of_flag_del_0_reg; 
   end_of_flag_del_2_reg <= end_of_flag_del_1_reg;
   end_of_flag_del_3_reg <= end_of_flag_del_2_reg;


  end
end


// -----------------------------------------------------------------------------
// OUTPUT SECTION
// -----------------------------------------------------------------------------
assign burst_gate = sm_burst_gate_reg;
assign pal_v_flag = positive_v_flag; 
assign video_enable = sm_videoenable_reg;
assign color_bars = color_bars_counter;
assign y_gate = y_gate_reg;
assign cr_gate = cr_gate_reg;
assign cb_gate = cb_gate_reg;
// In PAL the initial phase alters, in NTSC always 0 after 4 fields
assign frame_number = frame_num_del_2_reg; //{~sm_fields_one_to_four_reg, ~sm_first_frame_reg};
assign end_of_line_flag = end_of_flag_del_2_reg; // last_line_sample & ~sm_first_halfline_reg;
// Phase is set ones per 4 fields
assign set_phase_flag = set_phase_flag_del_2_reg; //(last_line_sample & last_line & ~sm_first_halfline_reg); 

assign sync_levels = sm_tip_state; 



endmodule // dve_ccir_vtg









⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -