sukanya28
Junior Member level 2
- Joined
- Oct 1, 2014
- Messages
- 23
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 213
module anymodule(input wire clk,reset,
output wire hsynch,vsynch,
output [2:0] red,
output [2:0] green,
output [1:0] blue,
output video_on);
// defining constants
localparam HD = 800; // horizontal display area
localparam HF = 56; // front porch (right border)
localparam HB = 64; //right porch (left border)
localparam HR = 120; // horizontal retrace
localparam VD = 600; // vertical display area
localparam VF = 37; // front porch (bottom border)
localparam VB = 23; // back porch (top border)
localparam VR = 6; // vertical retrace
//horizontal and vertical counter
reg [9:0] h_count = 0;
reg [9:0] v_count = 0;
wire [9:0] h_end,v_end;
assign h_end = HD+HF+HR+HB-1;
assign v_end = VD+VF+VR+VB-1;
always @(clk)
if(h_count<h_end)
h_count <= h_count+1;
else
h_count <= 0;
always @(*)
if(clk & h_end)
if(v_count<v_end)
v_count <= v_count+1;
else
v_count <= 0;
else
v_count <= v_count;
assign hsynch = ((h_count>= HD+HF-1) && (h_count<=HD+HF+HR+HB-1));
assign vsynch = ((v_count>=VD+VF-1) && (v_count<= VD+VF+VR+VB-1));
assign video_on = ((h_count <HD) && (v_count<VD));
wire [9:0] pixel_x,pixel_y;
assign pixel_x = (video_on)? h_count : 10'b0;
assign pixel_y = (video_on)? v_count : 10'b0;
reg [7:0] coloroutput;
always @(clk)
if(~video_on)
coloroutput <= 0;
else
begin
if( pixel_x<150 && pixel_y<160)
coloroutput[7:5] <= 3'b111;
else if(pixel_x<250 && pixel_y<320)
coloroutput[4:2] <= 3'b111;
else
coloroutput[1:0] <= 2'b11;
end
assign red = (video_on)?coloroutput[7:5] : 3'b000;
assign green = (video_on)?coloroutput[4:2] : 3'b000;
assign blue = (video_on)?coloroutput[1:0] : 3'b000;
endmodule
if (clk & h_end)
always @(*)
if(clk & h_end)
if(v_count<v_end)
v_count <= v_count+1;
else
v_count <= 0;
else
v_count <= v_count;
always @(*)
begin
if(clk)
if(h_end)
h_count = 0;
else
h_count = h_count+1;
else
h_count = h_count;
end
always @(clk)
begin
if(h_end)
if(v_count<v_end)
v_count = v_count+1;
else
v_count = 0;
else
v_count = v_count;
end
module anymodule(input wire clk,reset,
output wire hsynch,vsynch,
output [2:0] red,
output [2:0] green,
output [1:0] blue,
output video_on);
// defining constants
localparam HD = 800; // horizontal display area
localparam HF = 56; // front porch (right border)
localparam HB = 64; //right porch (left border)
localparam HR = 120; // horizontal retrace
localparam VD = 600; // vertical display area
localparam VF = 37; // front porch (bottom border)
localparam VB = 23; // back porch (top border)
localparam VR = 6; // vertical retrace
//horizontal and vertical counter
reg [9:0] h_count = 0;
reg [9:0] v_count = 0;
wire [9:0] h_end,v_end;
assign h_end = HD+HF+HR+HB-1;
assign v_end = VD+VF+VR+VB-1;
always @(*)
begin
if(clk)
if(h_end)
h_count = 0;
else
h_count = h_count+1;
else
h_count = h_count;
end
always @(clk)
begin
if(h_end)
if(v_count<v_end)
v_count = v_count+1;
else
v_count = 0;
else
v_count = v_count;
end
assign hsynch = ((h_count>= HD+HF-1) && (h_count<=HD+HF+HR+HB-1));
assign vsynch = ((v_count>=VD+VF-1) && (v_count<= VD+VF+VR+VB-1));
assign video_on = ((h_count <HD) && (v_count<VD));
wire [9:0] pixel_x,pixel_y;
assign pixel_x = (video_on)? h_count : 10'b0;
assign pixel_y = (video_on)? v_count : 10'b0;
reg [7:0] coloroutput;
always @(clk)
if(~video_on)
coloroutput <= 0;
else
begin
if( pixel_x<150 && pixel_y<160)
coloroutput[7:5] <= 3'b111;
else if(pixel_x<250 && pixel_y<320)
coloroutput[4:2] <= 3'b111;
else
coloroutput[1:0] <= 2'b11;
end
assign red = (video_on)?coloroutput[7:5] : 3'b000;
assign green = (video_on)?coloroutput[4:2] : 3'b000;
assign blue = (video_on)?coloroutput[1:0] : 3'b000;
endmodule
always @(*) begin
if(clk)
if(h_end)
h_count = 0;
else
h_count = h_count+1;
else
h_count = h_count;
end
module counter( input wire clk,reset,
output reg h_count_next , v_count_next
);
// defining constants
localparam HD = 800; // horizontal display area
localparam HF = 56; // front porch (right border)
localparam HB = 64; //right porch (left border)
localparam HR = 120; // horizontal retrace
localparam VD = 600; // vertical display area
localparam VF = 37; // front porch (bottom border)
localparam VB = 23; // back porch (top border)
localparam VR = 6; // vertical retrace
//horizontal and vertical counter
reg [9:0] h_count_reg;
reg [9:0] v_count_reg ;
reg v_sync_reg , h_sync_reg ;
// wire v_sync_next , h_sync_next ;
wire h_end , v_end;
always @ ( posedge clk , posedge reset)
if (reset)
begin
v_count_reg <= 0;
h_count_reg <= 0 ;
end
else
begin
v_count_reg <= v_count_next;
h_count_reg <= h_count_next;
end
assign h_end = (h_count_reg==(HD+HF+HB+HR-1)) ;
assign v_end = (v_count_reg==(VD+VF+VB+VR-1)) ;
// below is the counter used to generate hsynch
always @(*)
if (clk) //50 Mhz pixel clock
if(h_end)
h_count_next = 0 ;
else
h_count_next = h_count_reg + 1;
else
h_count_next = h_count_reg;
//counter used to generate vsynch
always @(*)
if(clk & h_count_reg == h_end)
if(v_count_reg == v_end)
v_count_next = 0;
else
v_count_next = v_count_reg+1;
else
v_count_next = v_count_reg;
endmodule
module counter( input wire clk,reset,
output wire hsync , vsync
);
// defining constants
localparam HD = 800; // horizontal display area
localparam HF = 56; // front porch (right border)
localparam HB = 64; //right porch (left border)
localparam HR = 120; // horizontal retrace
localparam VD = 600; // vertical display area
localparam VF = 37; // front porch (bottom border)
localparam VB = 23; // back porch (top border)
localparam VR = 6; // vertical retrace
//horizontal and vertical counter
reg [9:0] h_count_reg ,h_count_next;
reg [9:0] v_count_reg , v_count_next;
reg v_sync_reg , h_sync_reg ;
wire v_sync_next , h_sync_next ;
wire h_end , v_end;
always @ ( posedge clk , posedge reset)
if (reset)
begin
v_count_reg <= 0;
h_count_reg <= 0 ;
v_sync_reg <= 'b0;
h_sync_reg <= 'b0;
end
else
begin
v_count_reg <= v_count_next;
h_count_reg <= h_count_next;
v_sync_reg <= v_sync_next ;
h_sync_reg <= h_sync_next ;
end
assign h_end = (h_count_reg==(HD+HF+HB+HR-1)) ;
assign v_end = (v_count_reg==(VD+VF+VB+VR-1)) ;
// below is the counter used to generate hsynch
always @(*)
if (clk) //50 Mhz pixel clock
if(h_end)
h_count_next = 0 ;
else
h_count_next = h_count_reg + 1;
else
h_count_next = h_count_reg;
//counter used to generate vsynch
always @(*)
if(clk & h_count_reg == h_end)
if(v_count_reg == v_end)
v_count_next = 0;
else
v_count_next = v_count_reg+1;
else
v_count_next = v_count_reg;
assign h_sync_next = (h_count_reg >= (HD+HF) && h_count_reg <= (HD+HF+HR-1));
assign v_sync_next = (v_count_reg >= (VD+VF) && v_count_reg <= (VD+VF+VR-1));
assign hsync = h_sync_reg;
assign vsync = v_sync_reg;
endmodule
You need to get rid of the combinational always block. Counters should only be used in sequential always blocks.
Code Verilog - [expand] 1 2 3 4 always @(posedge clk) begin counter <= counter + 1'd1; end //etc
if (clk) //50 Mhz pixel clock
if(clk & h_count_reg == h_end)
always @ (posedge clk)
// or
always @ (negedge clk)
// defining constants
localparam HD = 800; // horizontal display area
localparam HF = 56; // front porch (right border)
localparam HB = 64; //right porch (left border)
localparam HR = 120; // horizontal retrace
localparam VD = 600; // vertical display area
localparam VF = 37; // front porch (bottom border)
localparam VB = 23; // back porch (top border)
localparam VR = 6; // vertical retrace
/* These need to change based on your constants above. */
reg [9:0] h_count_reg;
reg [9:0] v_count_reg;
//counter used to generate vsynch
always @ (*)
if(v_end && h_end)
v_count_next = 0;
else
if(h_end)
v_count_next = v_count_reg+1;
else
v_count_next = v_count_reg;
module vga_controller(input wire clk,reset,
output wire hsync,vsync,
output [2:0] red,
output [2:0] green,
output [1:0] blue,
output reg video_on);
// defining constants
localparam HD = 800; // horizontal display area
localparam HF = 56; // front porch (right border)
localparam HB = 64; //right porch (left border)
localparam HR = 120; // horizontal retrace
localparam VD = 600; // vertical display area
localparam VF = 37; // front porch (bottom border)
localparam VB = 23; // back porch (top border)
localparam VR = 6; // vertical retrace
localparam h_end = 1040;
localparam v_end = 666;
//horizontal and vertical counter
reg [10:0] h_count_reg,v_count_reg ;
reg[10:0] h_count_next , v_count_next;
//reg v_sync_reg , h_sync_reg ;
//wire v_sync_next , h_sync_next ;
reg v_sync_next , h_sync_next = 0 ;
always @ ( posedge clk , posedge reset)
if (reset)
begin
v_count_reg <= 0;
h_count_reg <= 0 ;
//v_sync_reg <= 1'b0;
//h_sync_reg <= 1'b0;
end
else
begin
v_count_reg <= v_count_next;
h_count_reg <= h_count_next;
//v_sync_reg <= v_sync_next ;
//h_sync_reg <= h_sync_next ;
end
// horizontal and vertical counters
always @(posedge clk)
begin
if(h_count_reg < h_end-1)
begin
h_count_next <= h_count_reg + 1;
end
else
begin
h_count_next <= 0;
if(v_count_reg < v_end-1)
v_count_next <= v_count_reg + 1;
else
v_count_next <= 0;
end
end
// horizontal and vertical synchronization signals
always @(posedge clk)
if(h_count_reg < HR)
h_sync_next <= 1;
else
h_sync_next <= 0;
//VSync logic
always @(posedge clk)
if(v_count_reg < VR)
v_sync_next <= 1;
else
v_sync_next <= 0;
assign hsync = h_sync_next;
assign vsync = v_sync_next;
reg h_video_on,v_video_on;
//horizontal logic
always @(posedge clk)
if((h_count_reg >= HR + HF) && (h_count_reg< HR + HF + HD))
h_video_on <= 1;
else
h_video_on <= 0;
//Vertical logic
always @(posedge clk)
if((v_count_reg >= VR + VF) && (v_count_reg < VR + VF+ VD))
v_video_on <= 1;
else
v_video_on <= 0;
always @(posedge clk)
if(h_video_on && v_video_on)
video_on <= 1;
else
video_on <= 0;
reg [9:0] pixel_x,pixel_y;
always @(posedge clk)
if(h_video_on)
pixel_x <= h_count_reg - HR - HF;
else
pixel_x <= 0;
always @(posedge clk)
if(v_video_on)
pixel_y <= v_count_reg - VR - VF;
else
pixel_y <= 0;
//color output
reg [7:0] coloroutput;
always @(posedge clk)
if(~video_on)
coloroutput <= 0;
else
begin
if(pixel_y<160)
coloroutput[7:5] <= 3'b111;
else if(pixel_y<320)
coloroutput[4:2] <= 3'b111;
else
coloroutput[1:0] <= 2'b11;
end
assign red = (video_on)?coloroutput[7:5] : 3'b000;
assign green = (video_on)?coloroutput[4:2] : 3'b000;
assign blue = (video_on)?coloroutput[1:0] : 3'b000;
endmodule
module vga_controller(input wire clk,reset,
output wire hsync,vsync,
output [2:0] red,
output [2:0] green,
output [1:0] blue,
output reg video_on);
// defining constants
localparam HD = 800; // horizontal display area
localparam HF = 56; // front porch (right border)
localparam HB = 64; //right porch (left border)
localparam HR = 120; // horizontal retrace
localparam VD = 600; // vertical display area
localparam VF = 37; // front porch (bottom border)
localparam VB = 23; // back porch (top border)
localparam VR = 6; // vertical retrace
localparam h_end = 1040;
localparam v_end = 666;
//horizontal and vertical counter
reg [10:0] h_count_reg,v_count_reg ;
reg[10:0] h_count_next , v_count_next;
//reg v_sync_reg , h_sync_reg ;
//wire v_sync_next , h_sync_next ;
reg v_sync_next , h_sync_next = 0 ;
always @ ( posedge clk , posedge reset)
if (reset)
begin
v_count_reg <= 0;
h_count_reg <= 0 ;
//v_sync_reg <= 1'b0;
//h_sync_reg <= 1'b0;
end
else
begin
v_count_reg <= v_count_next;
h_count_reg <= h_count_next;
//v_sync_reg <= v_sync_next ;
//h_sync_reg <= h_sync_next ;
end
// horizontal and vertical counters
always @(posedge clk)
begin
if(h_count_reg < h_end-1)
begin
h_count_next <= h_count_reg + 1;
end
else
begin
h_count_next <= 0;
if(v_count_reg < v_end-1)
v_count_next <= v_count_reg + 1;
else
v_count_next <= 0;
end
end
// horizontal and vertical synchronization signals
always @(posedge clk)
if(h_count_reg < HR)
h_sync_next <= 1;
else
h_sync_next <= 0;
//VSync logic
always @(posedge clk)
if(v_count_reg < VR)
v_sync_next <= 1;
else
v_sync_next <= 0;
assign hsync = h_sync_next;
assign vsync = v_sync_next;
reg h_video_on,v_video_on;
//horizontal logic
always @(posedge clk)
if((h_count_reg >= HR + HF) && (h_count_reg< HR + HF + HD))
h_video_on <= 1;
else
h_video_on <= 0;
//Vertical logic
always @(posedge clk)
if((v_count_reg >= VR + VF) && (v_count_reg < VR + VF+ VD))
v_video_on <= 1;
else
v_video_on <= 0;
always @(posedge clk)
if(h_video_on && v_video_on)
video_on <= 1;
else
video_on <= 0;
reg [9:0] pixel_x,pixel_y;
always @(posedge clk)
if(h_video_on)
pixel_x <= h_count_reg - HR - HF;
else
pixel_x <= 0;
always @(posedge clk)
if(v_video_on)
pixel_y <= v_count_reg - VR - VF;
else
pixel_y <= 0;
//color output
reg [7:0] coloroutput;
always @(posedge clk)
if(~video_on)
coloroutput <= 0;
else
begin
if(pixel_y<160)
coloroutput[7:5] <= 3'b111;
else if(pixel_y<320)
coloroutput[4:2] <= 3'b111;
else
coloroutput[1:0] <= 2'b11;
end
assign red = (video_on)?coloroutput[7:5] : 3'b000;
assign green = (video_on)?coloroutput[4:2] : 3'b000;
assign blue = (video_on)?coloroutput[1:0] : 3'b000;
[ATTACH=CONFIG]110168._xfImport[/ATTACH]
endmodule
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 if(~video_on) coloroutput <= 0; else // etc // no need to do it like this: assign red = (video_on)?coloroutput[7:5] : 3'b000; // just do something like this: assign red = coloroutput[7:5];
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?