Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

To display a square on monitor ( Verilog vga Basys 2 board )

Status
Not open for further replies.
I'm more referring to the verilog roughly translated version. Hell, for this design it is even not much of an issue given the timings concerned. Plus, a glitchy pixel every now and then in a red block on display demo, noone will notice that either. So for practical purposes the OP is safe using the glitchy clock. Uhm, click.

But from the viewpoint that NOW is the time in the learning phase that habits get formed, it might be a good idea to form the right habit. Especially since doing it the right way is hardly any more work than doing it the wrong way.

Anyways, enough of a sidetrack. Apart from code style + the above it looks good, so give it a try.
 

mrfibble, Did we read the same code?

The lack of an always and the lack of begin/end in the if statement for the next_?... signals will result in the code not even synthesizing. Besides that the counters are all done with rollovers. They will regularly have values beyond the limits for the screen. So instead of bouncing you'll probably end up with something that disappears altogether until it rolls over back into the screen area.

I think giving it a try will just result in more questions.
 

I think giving it a try will just result in more questions.

Exactly! ;) You underestimate my deviously devious wheels within wheels good sir.

Although to be honest, I didn't even notice that lack of begin/end in the always block due to speed reading it. But I did notice other stuff that I could comment on but won't. My thoughts here are that pressing the simulate button is cheap, so simulate often. And then ask. If I were a paid tutor I would take a more direct interacting approach with the student, possibly with pedagogically sound results. But I'm not and so I'm not. ;)
 

I have made certain changes in code. And regarding next_?_location, I want my square to move across two horizontal ends automatically without any change in y coordinates and thus I have now removed that next_y_location counter.This movement could be done in regular intervals to provide a steady movement of the object. Now when movement is desired, appropriate delays must be added to prevent the movement from occuring too fast for the eye to see. So if I use the same clock how can I provide delay in that next_x_location counter.

Code:
reg [10:0] x_location_reg,y_location_reg;
reg [10:0] next_x_location , next_y_location;
localparam sq_y_t = 200;
localparam sq_y_b = 220;



always @(posedge clk,posedge reset)
if(reset)
begin
x_location_reg <= 0; // registers to store the current position
y_location_reg <= 0;
end
else
begin
x_location_reg <= next_x_location;
y_location_reg <=  next_y_location;
end


// counter to count upto 100000 to get time delay of 2ms
reg [18:0] tick_tock;
wire click;

always @(posedge clk or posedge reset)
begin
if(reset)
tick_tock <= 0;
else if ( tick_tock==99999)
tick_tock <= 0;
else
tick_tock <= tick_tock+1;
end

assign click = (tick_tock == 99999)?1'b1 : 1'b0; //click every 2ms

always @(posedge click or posedge reset)
begin
if(reset)
next_x_location <= 0;
else
next_x_location <= next_x_location +1;
end


end
always @(posedge clk , posedge reset)
  if((pixel_x >= x_location_reg  &&  pixel_x <= x_location_reg + 5 ) && (pixel_y >= sq_y_t && pixel_y < sq_y_b))
 box_on <= 1'b1;
 else
 box_on <= 1'b0;
 

You claim to know about clock enables, but then continue to use the following in your code.
Code:
assign click = (tick_tock == 99999)?1'b1 : 1'b0; //click every 2ms
always @(posedge click or posedge reset)
You should write this as an enable then you will still have the 2ms delay for updates to next_x_location.

I'll let you google for the correct verilog template for a clock enabled procedural block.
 

If I use clock divider,will that be alright? For ex-
Code:
reg [23:0] q;
always @(posedge clk or posedge reset)
begin
if(reset)
q<=1;
else
q <= q+1;
end

wire clk381;
assign clk381 = q[16]; // clock of 381.47 Hz or 2.62 ms


and then use this clock in location counter?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top