-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to use the clock net for PLL signals (#139)
* Add ability to use the clock net for PLL signals The nextpnr can now use the clock network to deliver PLL outputs if it sees fit. On the apicula chip base side, all four outputs can be connected to the clock network, but the nextpnr currently has a limit of 3 networks, if I'm not mistaken. This is not being touched for the time being. In the process of experimentation, the functions of the many internal wires of the large central clock MUX have been discovered and these are reflected in the names. An example of using the PLL to form a picture on a 4.3" LCD screen is added. ! This commit uses the existing clock network processing logic and does not require any changes to the nextpnr, i.e. no new information about the big MUX device will be applied. Signed-off-by: YRabbit <[email protected]> * Delete accidentally added temporary files Signed-off-by: YRabbit <[email protected]> Signed-off-by: YRabbit <[email protected]>
- Loading branch information
Showing
5 changed files
with
315 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
(* top *) | ||
module TOP | ||
( | ||
input rst, | ||
input clk, | ||
|
||
output LCD_CLK, | ||
output LCD_HYNC, | ||
output LCD_SYNC, | ||
output LCD_DEN, | ||
output [4:0] LCD_R, | ||
output [5:0] LCD_G, | ||
output [4:0] LCD_B, | ||
|
||
output [2:0] led | ||
|
||
); | ||
|
||
wire CLK_SYS; | ||
wire CLK_PIX; | ||
wire LED_R; | ||
wire LED_G; | ||
wire LED_B; | ||
|
||
/* //使用内部时钟 | ||
Gowin_OSC chip_osc( | ||
.oscout(oscout_o) //output oscout | ||
); | ||
*/ | ||
rPLL pll( | ||
.CLKOUT(CLK_SYS), // 90MHz | ||
.CLKIN(clk), | ||
.CLKOUTD(CLK_PIX), | ||
.CLKFB(GND), | ||
.FBDSEL({GND,GND,GND,GND,GND,GND}), | ||
.IDSEL({GND,GND,GND,GND,GND,GND}), | ||
.ODSEL({GND,GND,GND,GND,GND,GND}), | ||
.DUTYDA({GND,GND,GND,GND}), | ||
.PSDA({GND,GND,GND,GND}), | ||
.FDLY({GND,GND,GND,GND}), | ||
); | ||
defparam pll.DEVICE = "GW1N-1"; | ||
defparam pll.FCLKIN = "24"; | ||
defparam pll.FBDIV_SEL = 29; | ||
defparam pll.IDIV_SEL = 7; | ||
defparam pll.ODIV_SEL = 8; // 90MHz sys clock | ||
defparam pll.CLKFB_SEL="internal"; | ||
defparam pll.CLKOUTD3_SRC="CLKOUT"; | ||
defparam pll.CLKOUTD_BYPASS="false"; | ||
defparam pll.CLKOUTD_SRC="CLKOUT"; | ||
defparam pll.CLKOUTP_BYPASS="false"; | ||
defparam pll.CLKOUTP_DLY_STEP=0; | ||
defparam pll.CLKOUTP_FT_DIR=1'b1; | ||
defparam pll.CLKOUT_BYPASS="false"; | ||
defparam pll.CLKOUT_DLY_STEP=0; | ||
defparam pll.CLKOUT_FT_DIR=1'b1; | ||
defparam pll.DEVICE="GW1N-1"; | ||
defparam pll.DUTYDA_SEL="1000"; | ||
defparam pll.DYN_DA_EN="false"; | ||
defparam pll.DYN_FBDIV_SEL="false"; | ||
defparam pll.DYN_IDIV_SEL="false"; | ||
defparam pll.DYN_ODIV_SEL="false"; | ||
defparam pll.DYN_SDIV_SEL=10; // 90MHz / 10 = 9MHz --- pixel clock | ||
defparam pll.PSDA_SEL="0000"; | ||
|
||
assign led[0] = LED_R; | ||
assign led[1] = LED_G; | ||
assign led[2] = LED_B; | ||
|
||
VGAMod D1 | ||
( | ||
.CLK ( CLK_SYS ), | ||
.nRST ( rst ), | ||
|
||
.PixelClk ( CLK_PIX ), | ||
.LCD_DE ( LCD_DEN ), | ||
.LCD_HSYNC ( LCD_HYNC ), | ||
.LCD_VSYNC ( LCD_SYNC ), | ||
|
||
.LCD_B ( LCD_B ), | ||
.LCD_G ( LCD_G ), | ||
.LCD_R ( LCD_R ) | ||
); | ||
|
||
assign LCD_CLK = CLK_PIX; | ||
|
||
//RGB LED TEST | ||
reg [31:0] Count; | ||
reg [1:0] rgb_data; | ||
always @( posedge CLK_SYS or negedge rst ) | ||
begin | ||
if( !rst ) | ||
begin | ||
Count <= 32'd0; | ||
rgb_data <= 2'b00; | ||
end | ||
else if ( Count == 12000000 ) | ||
begin | ||
Count <= 4'b0; | ||
rgb_data <= rgb_data + 1'b1; | ||
end | ||
else | ||
Count <= Count + 1'b1; | ||
end | ||
assign LED_R = ~(rgb_data == 2'b01); | ||
assign LED_G = ~(rgb_data == 2'b10); | ||
assign LED_B = ~(rgb_data == 2'b11); | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
module VGAMod | ||
( | ||
input CLK, | ||
input nRST, | ||
|
||
input PixelClk, | ||
|
||
output LCD_DE, | ||
output LCD_HSYNC, | ||
output LCD_VSYNC, | ||
|
||
output [4:0] LCD_B, | ||
output [5:0] LCD_G, | ||
output [4:0] LCD_R | ||
); | ||
|
||
reg [15:0] PixelCount; | ||
reg [15:0] LineCount; | ||
|
||
//pulse include in back pulse; t=pulse, sync act; t=bp, data act; t=bp+height, data end | ||
|
||
/* 480x272 4.3" LCD with SC7283 driver, pixel freq = 9MHz */ | ||
localparam V_BackPorch = 16'd12; | ||
localparam V_Pulse = 16'd4; | ||
localparam HightPixel = 16'd272; | ||
localparam V_FrontPorch= 16'd8; | ||
|
||
localparam H_BackPorch = 16'd43; | ||
localparam H_Pulse = 16'd4; | ||
localparam WidthPixel = 16'd480; | ||
localparam H_FrontPorch= 16'd8; | ||
|
||
/*localparam V_BackPorch = 16'd12; | ||
localparam V_Pulse = 16'd11; | ||
localparam HightPixel = 16'd272; | ||
localparam V_FrontPorch= 16'd8; | ||
localparam H_BackPorch = 16'd50; | ||
localparam H_Pulse = 16'd10; | ||
localparam WidthPixel = 16'd480; | ||
localparam H_FrontPorch= 16'd8; */ | ||
/* | ||
localparam V_BackPorch = 16'd0; //6 | ||
localparam V_Pulse = 16'd5; | ||
localparam HightPixel = 16'd480; | ||
localparam V_FrontPorch= 16'd45; //62 | ||
localparam H_BackPorch = 16'd182; //NOTE: 高像素时钟时,增加这里的延迟,方便K210加入中断 | ||
localparam H_Pulse = 16'd1; | ||
localparam WidthPixel = 16'd800; | ||
localparam H_FrontPorch= 16'd210; | ||
*/ | ||
|
||
localparam PixelForHS = WidthPixel + H_BackPorch + H_FrontPorch; | ||
localparam LineForVS = HightPixel + V_BackPorch + V_FrontPorch; | ||
|
||
always @( posedge PixelClk or negedge nRST )begin | ||
if( !nRST ) begin | ||
LineCount <= 16'b0; | ||
PixelCount <= 16'b0; | ||
end | ||
else if( PixelCount == PixelForHS ) begin | ||
PixelCount <= 16'b0; | ||
LineCount <= LineCount + 1'b1; | ||
end | ||
else if( LineCount == LineForVS ) begin | ||
LineCount <= 16'b0; | ||
PixelCount <= 16'b0; | ||
end | ||
else begin | ||
PixelCount <= PixelCount + 1'b1; | ||
end | ||
end | ||
|
||
reg [9:0] Data_R; | ||
reg [9:0] Data_G; | ||
reg [9:0] Data_B; | ||
|
||
always @( posedge PixelClk or negedge nRST )begin | ||
if( !nRST ) begin | ||
Data_R <= 9'b0; | ||
Data_G <= 9'b0; | ||
Data_B <= 9'b0; | ||
end | ||
else begin | ||
end | ||
end | ||
|
||
//注意这里HSYNC和VSYNC负极性 | ||
assign LCD_HSYNC = (( PixelCount >= H_Pulse)&&( PixelCount <= (PixelForHS-H_FrontPorch))) ? 1'b0 : 1'b1; | ||
//assign LCD_VSYNC = ((( LineCount >= 0 )&&( LineCount <= (V_Pulse-1) )) ) ? 1'b1 : 1'b0; //这里不减一的话,图片底部会往下拖尾? | ||
assign LCD_VSYNC = ((( LineCount >= V_Pulse )&&( LineCount <= (LineForVS-0) )) ) ? 1'b0 : 1'b1; | ||
//assign FIFO_RST = (( PixelCount ==0)) ? 1'b1 : 1'b0; //留给主机H_BackPorch的时间进入中断,发送数据 | ||
|
||
assign LCD_DE = ( ( PixelCount >= H_BackPorch )&& | ||
( PixelCount <= PixelForHS-H_FrontPorch ) && | ||
( LineCount >= V_BackPorch ) && | ||
( LineCount <= LineForVS-V_FrontPorch-1 )) ? 1'b1 : 1'b0; | ||
//这里不减一,会抖动 | ||
|
||
assign LCD_R = (PixelCount<110)? 5'b00000 : | ||
(PixelCount<132 ? 5'b00001 : | ||
(PixelCount<154 ? 5'b00010 : | ||
(PixelCount<176 ? 5'b00100 : | ||
(PixelCount<198 ? 5'b01000 : | ||
(PixelCount<220 ? 5'b10000 : 5'b00000 ))))); | ||
|
||
assign LCD_G = (PixelCount<220)? 6'b000000 : | ||
(PixelCount<242 ? 6'b000001 : | ||
(PixelCount<264 ? 6'b000010 : | ||
(PixelCount<286 ? 6'b000100 : | ||
(PixelCount<308 ? 6'b001000 : | ||
(PixelCount<330 ? 6'b010000 : | ||
(PixelCount<352 ? 6'b100000 : 6'b000000 )))))); | ||
|
||
assign LCD_B = (PixelCount<352)? 5'b00000 : | ||
(PixelCount<374 ? 5'b00001 : | ||
(PixelCount<396 ? 5'b00010 : | ||
(PixelCount<418 ? 5'b00100 : | ||
(PixelCount<440 ? 5'b01000 : | ||
(PixelCount<462 ? 5'b10000 : 5'b00000 ))))); | ||
|
||
endmodule |