1 //---------------------------------------------------------------------
2 // FPGA MOONCRESTA H & V COUNTER
6 // Copyright(c) 2004 Katsumi Degawa , All rights reserved
10 // This program is freeware for non-commercial use.
11 // An author does no guarantee about this program.
12 // You can use this under your own risk.
15 //---------------------------------------------------------------------
17 // H_CNT 0 - 255 , 384 - 511 Total 384 count
18 // V_CNT 0 - 255 , 504 - 511 Total 264 count
19 //-----------------------------------------------------------------------------------------
20 // H_CNT[0],H_CNT[1],H_CNT[2],H_CNT[3],H_CNT[4],H_CNT[5],H_CNT[6],H_CNT[7],H_CNT[8],
21 // 1 H 2 H 4H 8H 16 H 32H 64 H 128 H 256 H
22 //-----------------------------------------------------------------------------------------
23 // V_CNT[0], V_CNT[1], V_CNT[2], V_CNT[3], V_CNT[4], V_CNT[5], V_CNT[6], V_CNT[7]
24 // 1 V 2 V 4 V 8 V 16 V 32 V 64 V 128 V
25 //-----------------------------------------------------------------------------------------
54 //------- H_COUNT ----------------------------------------
56 always@(posedge I_CLK)
58 H_CNT <= H_CNT==255 ? 384 : H_CNT +1 ;
60 assign O_H_CNT = H_CNT[8:0];
62 //------- H_SYNC ----------------------------------------
65 wire H_SYNC = ~H_SYNCn;
66 always@(posedge H_CNT[4] or negedge H_CNT[8])
68 if(H_CNT[8]==1'b0) H_SYNCn <= 1'b1;
69 else H_SYNCn <= ~(~H_CNT[6]& H_CNT[5]);
72 assign O_H_SYNC = H_SYNC;
73 //------- H_BL ------------------------------------------
77 always@(posedge I_CLK)
87 //------- V_COUNT ----------------------------------------
89 always@(posedge H_SYNC or negedge I_RSTn)
94 V_CNT <= V_CNT==255 ? 504 : V_CNT +1 ;
96 assign O_V_CNT = V_CNT[7:0];
97 assign O_V_SYNC = V_CNT[8];
99 //------- V_BLn ------------------------------------------
102 always@(posedge H_SYNC)
112 always@(posedge H_SYNC)
121 assign O_V_BLn = V_BLn;
122 assign O_V_BL2n = V_BL2n;
123 //------- C_BLn ------------------------------------------
125 assign O_C_BLn = ~(~V_BLn | H_CNT[8]);