Processing video images, using the xilinx v5 board, when the 964*625 camera output, the effective pixel area 768*576,, after using the following code, every time the program, the video output from the board has a row and column deviation, every time Different.

Ask, how to use your own counter to make the output of the board consistent with that when it does not pass through the board. (If you directly use wire assign definition for lval fval cameralink, it can be satisfied)

Attached code:

module cameralink(

    clk,

         rst_n,

         fval,

    lval,

// dval,

         cameralink_A,

         clk_out,

         fval_out,

         lval_out,

         cameralink_B

    );

    input clk;

         input rst_n;

input fval;

input lval;

// input dval;

         input [7:0]cameralink_A;

                 

         output clk_out;

         output fval_out;

         output lval_out;

         output cameralink_B;


    wire clk_out;

         assign clk_out=clk;

         

         reg [7:0] video_in_data_r;

    reg [7:0] video_out_data_r;

/*************************Counting and decoding module********************* ************/

  

   

         reg [9:0] pix_in_x_cnt; //964, 8+ 768+ 188 768 pixels per line

         reg [9:0] pix_in_y_cnt; //625, 11+ 576+ 38 576 lines of pixels in one frame

         

         //fval line 29 to 600 is line 1, the rest is 0, there are 625 lines in one frame

         //Lval Columns 20 to 842 are 1, and the rest are 0, a total of 964 rows

         

always @ (posedge clk )begin

           if(!rst_n)

                     pix_in_x_cnt <= 10'd0;

           else begin

                              if(pix_in_x_cnt == 10'd964)

                                    pix_in_x_cnt <= 10'd0;

                         else

                                                        pix_in_x_cnt <= pix_in_x_cnt+1'b1;

                                end

                 end

               

  always @ (posedge clk )begin

           if(!rst_n)

                     pix_in_y_cnt <= 10'd0;

           else begin

                                   if(pix_in_y_cnt == 10'd625)

                                    pix_in_y_cnt <= 10'd0;

                    else begin

                                              if(pix_in_x_cnt == 10'd964)

                                    pix_in_y_cnt <= pix_in_y_cnt+1'b1;

                                                  end

           end

                end

               

wire dval; //effective pixel area

assign dval=((pix_in_x_cnt>=10'd27)&&(pix_in_x_cnt<=10'd794))&&((pix_in_y_cnt>=10'd33)&&(pix_in_y_cnt<=10'd608));

         

always @ (posedge clk )begin

           if(!rst_n)begin

                                 video_in_data_r<=8'd0;

                                        end

                else begin

                         if(dval)begin

                                                video_in_data_r<=cameralink_A;

                                        end

                     end

        end

/*************************Algorithm processing module********************* ************/



/*************************Counting coding module********************* ************/

         reg [9:0] pix_out_x_cnt; //964, 8+ 768+ 188 768 pixels in a row

         reg [9:0] pix_out_y_cnt; //625, 11+ 576+ 38 576 lines of pixels in one frame

         

         //fval line 29 to 620 is line 1, the rest is 0, there are 625 lines in one frame

         //Lval Columns 20 to 842 are 1, and the rest are 0, a total of 964 rows

wire frame_end_flag;

assign frame_end_flag=((pix_in_x_cnt == 10'd0)&&(pix_in_y_cnt == 10'd0));

                 

always @ (posedge clk)begin

           if(!rst_n)

                     pix_out_x_cnt <= 10'd0;

           else begin

                              if((pix_out_x_cnt == 10'd964)|| (frame_end_flag))

                                    pix_out_x_cnt <= 10'd0;

                         else

                                                        pix_out_x_cnt <= pix_out_x_cnt+1'b1;

                                end

                 end

               

  always @ (posedge clk )begin

           if(!rst_n)

                     pix_out_y_cnt <= 10'd0;

           else begin

                                   if((pix_out_y_cnt == 10'd625)|| (frame_end_flag))

                                    pix_out_y_cnt <= 10'd0;

                    else if(pix_out_x_cnt == 10'd964)

                                    pix_out_y_cnt <= pix_out_y_cnt+1'b1;

           end

                end

   

        wire fval_out;

        assign fval_out=((pix_out_y_cnt>=10'd28)&&(pix_out_y_cnt<=10'd619));//Initial


// assign fval_out=fval;

        

        wire lval_out;

        assign lval_out=((pix_out_x_cnt>=10'd19)&&(pix_out_x_cnt<=10'd841));


// assign lval_out=lval;

        

        wire pix_en_dis; //Effective pixel area

        assign pix_en_dis=((pix_out_x_cnt>=10'd27)&&(pix_out_x_cnt<=10'd794))&&((pix_out_y_cnt>=10'd33)&&(pix_out_y_cnt<=10'd608));


        

        wire [7:0] cameralink_B;

   reg [7:0] cameralink_B_r;

   assign cameralink_B=cameralink_B_r;

        

always @ (posedge clk )begin

           if(!rst_n)

                     begin

                              cameralink_B_r<=8'd0;

                          end

                else begin

                         if(pix_en_dis)

                                          begin

                                             //cameralink_B_r<=video_out_data_r;

                                                  cameralink_B_r<=video_in_data_r;

                                          end

                                   else

                                             cameralink_B_r<=8'd0;

                     end

        end


endmodule

Reply