Subversion Repositories pentevo

Rev

Rev 492 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. // counter-based 'fapch', based on pentagon design, with filter and adopted to
  2. // 28mhz
  3.  
  4.  
  5. module fapch_counter
  6. (
  7.         input  wire fclk,
  8.  
  9.         input  wire rdat_n,
  10.  
  11.         output reg  vg_rclk,
  12.         output reg  vg_rawr
  13. );
  14.  
  15.  
  16.         reg [4:0] rdat_sync;
  17.         reg rdat_edge1, rdat_edge2;
  18.         wire rdat;
  19.         wire rwidth_ena;
  20.         reg [3:0] rwidth_cnt;
  21.         wire rclk_strobe;
  22.         reg [5:0] rclk_cnt;
  23.  
  24.         // RCLK/RAWR restore
  25.         // currently simplest counter method, no PLL whatsoever now
  26.         //
  27.         // RCLK period must be 112 clocks (@28 MHz), or 56 clocks for each state
  28.         // RAWR on time is 4 clocks
  29.  
  30.         // digital filter - removing glitches
  31.         always @(posedge fclk)
  32.                 rdat_sync[4:0] <= { rdat_sync[3:0], (~rdat_n) };
  33.  
  34.  
  35.  
  36.         always @(posedge fclk)
  37.         begin
  38.                 if( rdat_sync[4:1]==4'b1111 ) // filter beginning of strobe
  39.                         rdat_edge1 <= 1'b1;
  40.                 else if( rclk_strobe ) // filter any more strobes during same strobe half-perion
  41.                         rdat_edge1 <= 1'b0;
  42.  
  43.                 rdat_edge2 <= rdat_edge1;
  44.         end
  45.  
  46.  
  47.  
  48.         assign rdat = rdat_edge1 & (~rdat_edge2);
  49.  
  50.  
  51.  
  52.         always @(posedge fclk)
  53.                 if( rwidth_ena )
  54.                 begin
  55.                         if( rdat )
  56.                                 rwidth_cnt <= 4'd0;
  57.                         else
  58.                                 rwidth_cnt <= rwidth_cnt + 4'd1;
  59.                 end
  60.  
  61.         assign rwidth_ena = rdat | (~rwidth_cnt[2]); // [2] - 140ns, [3] - 280ns
  62.  
  63.         always @(posedge fclk)
  64.                 vg_rawr <= rwidth_cnt[2]; // RAWR has 2 clocks latency from rdat strobe
  65.  
  66.  
  67.  
  68.  
  69.         assign rclk_strobe = (rclk_cnt==6'd0);
  70.  
  71.         always @(posedge fclk)
  72.         begin
  73.                 if( rdat )
  74.                         rclk_cnt <= 6'd29; // (56/2)-1 plus halfwidth of RAWR
  75.                 else if( rclk_strobe )
  76.                         rclk_cnt <= 6'd55; // period is 56 clocks
  77.                 else
  78.                         rclk_cnt <= rclk_cnt - 6'd1;
  79.         end
  80.  
  81.         always @(posedge fclk)
  82.                 if( rclk_strobe )
  83.                         vg_rclk <= ~vg_rclk; // vg_rclk latency is 2 clocks plus a number loaded into rclk_cnt at rdat strobe
  84.  
  85. endmodule
  86.  
  87.