cancel
Showing results for 
Search instead for 
Did you mean: 
606 Views
Registered: ‎03-23-2020

VGA Controller : flickering between colours

Board used :  Basys2

ColourIn input in the code is provided by 8 input switches

I am attaching a few pictures of my monitor 

the flickering is always between two colours.

i have used a DCM block in code where the input frequency is 100Mhz and output is 86.95 which is close to the required frequency i.e 86.86Mhz

.the resolution that i am using is 1366*768. i have previously tried using 800*600 and 640*480 also still the same issue. It has to be something with my code because i use the same monitor and VGA cable as my secondary monitor.

 

Here is my code :

module VgaController(
input Clk50,
input [7:0]ColourIn,
output H_Sync,
output V_Sync,
output reg DisplayArea,
output reg [7:0]Colour,
output reg [10:0]CounterX,
output reg [9:0]CounterY,
output reg CounterXMaxed
);

wire Clk;

TEST DCM50to25 (
.CLKIN_IN(Clk50),
.CLKFX_OUT(Clk),
.CLKIN_IBUFG_OUT(CLKIN_IBUFG_OUT),
.CLK0_OUT(CLK0_OUT)
);

initial begin
CounterX = 0;
CounterY = 0;
end

reg Temp_H_Sync;
reg Temp_V_Sync;

//CounterX
always @ (posedge Clk)
begin
if(CounterXMaxed)
begin
CounterX = 0;
end
else
CounterX = CounterX + 1;
end

//CounterY
always @ (posedge Clk)
begin
if(CounterXMaxed)
begin
CounterY = CounterY + 1;
end
if(CounterY == 795)
begin
CounterY = 0;
end
end

//Condtion for CounterXMaxed
always @ (posedge Clk)
begin
if(CounterX == 1800)
CounterXMaxed = 1;
else
CounterXMaxed = 0;
end



//Conditions for generating H_Sync
always @ (posedge Clk)
begin
if(CounterX >= 1438 & CounterX <= 1582)
begin
Temp_H_Sync = 0;
end
else
begin
Temp_H_Sync = 1;
end
end

//Conditions for generating V_Sync
always @ (posedge Clk)
begin
if(CounterY >= 769 & CounterY <= 772)
begin
Temp_V_Sync = 0;
end
else
begin
Temp_V_Sync = 1;
end
end

always @ (posedge Clk)
begin
if ((CounterX <1366) & (CounterY <768))
DisplayArea = 1;
else
DisplayArea = 0;
end

assign H_Sync = ~ Temp_H_Sync;
assign V_Sync = ~ Temp_V_Sync;

parameter WhiteColour = 8'b1;
parameter SomeColour = 8'b11110000;
parameter ThirdColour = 8'b11100011;

always @ (posedge Clk)
begin
if (DisplayArea)
//Colour conditions will come here
//Colour = ColourIn;
if(CounterX < 200 | CounterX > 568)
Colour = SomeColour;
else if(CounterY < 300)
Colour = ThirdColour;
else
Colour = ColourIn;
else
//Colour to display when display area is inactive
Colour = 0;
end
endmodule

 

ucf file : 

NET "Colour<0>" LOC = "C14"; //Exact colour going to VGA
NET "Colour<1>" LOC = "D13"; //port
NET "Colour<2>" LOC = "F13";
NET "Colour<3>" LOC = "F14";
NET "Colour<4>" LOC = "G13";
NET "Colour<5>" LOC = "G14";
NET "Colour<6>" LOC = "H13";
NET "Colour<7>" LOC = "J13";

NET "ColourIn<0>" LOC="P11";
NET "ColourIn<1>" LOC="L3";
NET "ColourIn<2>" LOC="K3";
NET "ColourIn<3>" LOC="B4";
NET "ColourIn<4>" LOC="G3";
NET "ColourIn<5>" LOC="F3";
NET "ColourIn<6>" LOC="E2";
NET "ColourIn<7>" LOC="N3";

NET "Clk50" LOC = "B8";

NET "Clk50" CLOCK_DEDICATED_ROUTE = FALSE;
PIN "DCM50to25/DCM_SP_INST.CLKIN" CLOCK_DEDICATED_ROUTE = FALSE;

NET "H_Sync" LOC = "J14"; //Horizontal Synch output
NET "V_Sync" LOC = "K13"; //Vertical Synch output

 

Tags (1)
IMG_20200325_225726.jpg
IMG_20200325_225730.jpg
IMG_20200325_225706.jpg
IMG_20200325_225734.jpg
0 Kudos
24 Replies
Highlighted
Mentor
Mentor
576 Views
Registered: ‎06-16-2013

Re: VGA Controller : flickering between colours

Hi @malviyayash18 

 

Did you meet your constraint ?

I guess it seems timing issue...

 

Best regards,

Highlighted
551 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

But the monitor shows the right resolution with exact 60 Hz

0 Kudos
Highlighted
Mentor
Mentor
549 Views
Registered: ‎06-16-2013

Re: VGA Controller : flickering between colours

Hi @malviyayash18 

 

I guess your design has some timing violation.

Would you make sure it ?

 

Best regards,

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
492 Views
Registered: ‎04-09-2019

Re: VGA Controller : flickering between colours

Hello @malviyayash18 ,

I noticed from Your description that, Your Input and Output clock frequencies both are different, So, to manage this CDC I hope You might had used a FIFO in Your design. If Yes, Could You please check, Whether Your FIFO is getting FULL. Because, FIFO Full also will become a cause for the flickering in design. Reason behind this, some pixels will get overwrite (or) will get lost because of this FIFO Full.

So, Could You please check the above scenario at Your end, and let me know the status.

Hope it helps to You.

With Regards,

Ashok.

Highlighted
477 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

I have checked my simulation a lot of time but i couldn't find anything. 

0 Kudos
Highlighted
476 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

 
Annotation 2020-03-26 200400.png
Annotation 2020-03-26 200628.png
Annotation 2020-03-26 200553.png
0 Kudos
Highlighted
474 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

Is this what you were talking about ??
I don't know what is that warning about
0 Kudos
Highlighted
474 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

is this what you were talking about ??

i dont know what the warning is about 

0 Kudos
Highlighted
Scholar
Scholar
465 Views
Registered: ‎05-21-2015

Re: VGA Controller : flickering between colours

@malviyayash18,

Unfortunately, clock crossing issues are things that simulations can't usually detect.  They involve physical realities that ... don't often get simulated well.  You might need to read up on clock domain crossings, and perhaps even asynchronous FIFOs.

Dan

Highlighted
455 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

I have also tried running 800*600 which runs on exactly 50MHz the basys2 board does have a 50Mhz clock so i directly use that clock in my module and i still had the same issue. for a while i thought it was mu monitor issue so i switched to 1366*768 which is the recommend resolution of my monitor.... and still had the same issue.

 

ill surely go through the links you have mentioned . Thank You

0 Kudos
Highlighted
Scholar
Scholar
446 Views
Registered: ‎05-21-2015

Re: VGA Controller : flickering between colours

@malviyayash18,

If you are sticking to a single clock domain, then I'd run your design through a VGA simulator.  If it works in the VGA simulator, then you know will know when you move to hardware that it's a simulation / synthesis mismatch issue like clock domain crossing issues.

That said, some monitors are more picky about their incoming source frequencies, and how close they are to correct one.

Dan

0 Kudos
Highlighted
387 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

Here is my verilog code which runs at 800*600 at 50Mhz clock provided directly from the board.

i tried using the Vga Simulator but i couldn't get it running for my code .

 

code:

module VgaController(
input Clk,
input [7:0]ColourIn,
output H_Sync,
output V_Sync,
output reg DisplayArea,
output reg [7:0]Colour,
output reg [10:0]CounterX,
output reg [9:0]CounterY,
output reg CounterXMaxed
);


reg Temp_H_Sync;
reg Temp_V_Sync;

//CounterX
always @ (posedge Clk)
begin
if(CounterXMaxed)
begin
CounterX = 0;
end
else
CounterX = CounterX + 1;
end

//CounterY
always @ (posedge Clk)
begin
if(CounterXMaxed)
begin
CounterY = CounterY + 1;
end
if(CounterY == 665)
begin
CounterY = 0;
end
end

//Condtion for CounterXMaxed
always @ (posedge Clk)
begin
if(CounterX == 1039)
CounterXMaxed = 1;
else
CounterXMaxed = 0;
end



//Conditions for generating H_Sync
always @ (posedge Clk)
begin
if(CounterX >= 856 & CounterX <= 986)
begin
Temp_H_Sync = 0;
end
else
begin
Temp_H_Sync = 1;
end
end

//Conditions for generating V_Sync
always @ (posedge Clk)
begin
if(CounterY >= 637 & CounterY <= 643)
begin
Temp_V_Sync = 0;
end
else
begin
Temp_V_Sync = 1;
end
end

always @ (posedge Clk)
begin
if ((CounterX <800) & (CounterY <600))
DisplayArea = 1;
else
DisplayArea = 0;
end

assign H_Sync = ~ Temp_H_Sync;
assign V_Sync = ~ Temp_V_Sync;

parameter WhiteColour = 8'b1;
parameter SomeColour = 8'b11110000;
parameter ThirdColour = 8'b11100011;

always @ (posedge Clk)
begin
if (DisplayArea)
//Colour conditions will come here
//Colour = ColourIn;
if(CounterX < 200 | CounterX > 568)
Colour = SomeColour;
else if(CounterY < 300)
Colour = ThirdColour;
else
Colour = ColourIn;
else
//Colour to display when display area is inactive
Colour = 0;
end
endmodule

 

0 Kudos
Highlighted
Mentor
Mentor
342 Views
Registered: ‎06-16-2013

Re: VGA Controller : flickering between colours

Hi @malviyayash18 

 

Are you using analog RGB to connect your monitor on your board ?

If yes, did you make sure phase adjustment value and recovered clock on monitor ?

 

Also, if you want to get more suggestion, would you share the movie file when you are facing this issue.

 

I guess it seems the followings.

 

- CDC issue (somebody already mentioned)

- Timing violation issue (Make sure timing report and/or do simulation with netlist file)

- Phase adjustment or recovered clock issue on monitor, if connected by analog cable.

 

[Additional information]

If you are using DRAM as frame buffer, I suggest you to make sure DDR setting by mode register and clock frequency/noise, too.

 

Best regards,

Highlighted
295 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

I am using a Basys 2 Board which already had a VGA Port and the connections are also make all i have to do i provide RGB values [ parameter Colour = 8'b11110000; ] this way when even the counter is counting in display pixels

I am not using any framebuffer, directly providing RGB Values in the Code.

Link to Video : https://drive.google.com/open?id=1SVv-VyOFGC9XeT78Ki1ZZMGOuHDpdOHp

0 Kudos
Highlighted
Mentor
Mentor
246 Views
Registered: ‎06-16-2013

Re: VGA Controller : flickering between colours

Hi @malviyayash18 

 

Sorry for late reply.

 

I haven't seen your posted movie yet. But I'm sure that it's monitor issue.

Does your have gen-lock function to synchronize input vertical frequency on LCD panel ?

If so, the route cause is what I already mentioned on previous post.

If no, the route cause is gen-lock issue. Change monitor or build gen-lock function with frame buffer in your design.

 

Also you don't know my explanation. Would you share your monitor information ?

 

Best regards,

0 Kudos
Highlighted
Scholar
Scholar
237 Views
Registered: ‎05-21-2015

Re: VGA Controller : flickering between colours

@malviyayash18,

Did you notice how the edges seem to have a fixed and repetitive pattern to them?  It's almost as if the monitor can't quite accept the frequency you are giving it.  (25MHz is only close, it's not really the right frequency.)  Perhaps you might be able to create the "right" frequency and see if it helps?

Dan

Highlighted
Mentor
Mentor
166 Views
Registered: ‎06-16-2013

Re: VGA Controller : flickering between colours

Hi @malviyayash18 

 

I confirmed your posted movie.

Here is additional information.

 

How do you decide your video timing ? Using CVT formula from VESA ?

I strongly recommend to use same video timing VESA.

 

Also, it's malfunction by causing wrong or not proper video timing.

Would you change scaling mode on LCD monitor, if possible ?

You can see different phenomenon, if you can change scaling mode.

 

Best regards,

Highlighted
134 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

Vga Timings  were taken from : http://tinyvga.com/vga-timing

i changed  the scaling mode too still the same issue exists.

0 Kudos
Highlighted
133 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

Its a HP ProDisplay P191
0 Kudos
Highlighted
Scholar
Scholar
124 Views
Registered: ‎05-21-2015

Re: VGA Controller : flickering between colours

@malviyayash18,

Okay, so ... I took a deeper look at the logic you posted above.  You have several errors within your logic.

  1. Clocked logic should only use non-blocking <= assignments, in order to make certain simulation results match hardware synthesis.  If you had run "verilator -Wall -cc VgaController.v" you would have caught these bugs and probably a lot more.
  2. I also recommending using `default_nettype none at the top of any file I work with.  You'll find even more bugs by doing so, although this will force you to define your "input" values are "input wire"s, and your undefined outputs as "output wire"s.
  3. You really don't want to confuse & with && or | with ||.  When comparing two boolean values, you should always use && or ||.  When trying to adjust a bit-vector, use & or |.  In this case, you have several comparisons that should be using && or || and ... you aren't.
  4. Some of the timings you've copied from the table are mis-copied.  Use the language and the tool to your advantage.  Set parameters like H_VISIBLE, H_FRONT_PORCH, H_SYNC_PULSE, H_BACK_PORCH, and H_RAW_PIXELS, and then perform operations on them as necessary.  Do not mix numbers other than 0 and 1 into your logic--everything should be defined as either a parameter or a localparam at the top.
  5. Your code isn't indented above.  If you indent your code, you'll discover an if within an if that doesn't have a begin statement.  While the language standard might be clear on what's supposed to happen, my guess is that you aren't that familiar with the standard.  Do yourself a favor, pay attention to indentation and use it to your advantage.
  6. You are also struggling with several pipeline bugs.  Values you set on one clock cycle, such as CounterXMaxed, aren't available until the next cycle and by that time your pipeline is out of sync.  You can find bugs like this really easily using a simple formal methods check.
  7. Your design has neither reset nor initial statements, yet you depend upon the relationships between several registers within it.
  8. VGA sync pulses are negative logic.  They should be zero during the synch period, one otherwise.  Your Temp_*_Sync signals are correct, whereas your *_Sync signals are not.
  9. Display logic like this is really just a pair of counters.  It's not that hard.  Use formal methods to catch your bugs!  SymbiYosys is open source, freely downloadable, and easy to use.  You would have saved yourself several days of confusion if you had started there.  Here are some formal properties I came up with just looking over your code.


always @(*)
begin
    assert(CounterX <= RAW_HORIZONTAL_PIXELS);
    assert(CounterY <= RAW_VERTICAL_LINES);

    assert(CounterXMaxed == (CounterX >= RAW_HORIZONTAL_PIXELS-1));

    if (counterX < H_VISIBLE)
        assert(Temp_H_Sync);
    else if (CounterX >= (H_VISIBLE + H_FRONT_PORCH + H_SYNC_PULSE))
        assert(Temp_H_Sync);
    else
        assert(!Temp_H_Sync);

    if (CounterX >= H_VISIBLE)
        assert(!DisplayArea);
    else if (CounterY >= V_VISIBLE)
        assert(!DisplayArea);
    else
        assert(DisplayArea);
end

Take a moment and go back over the video article I linked above.  It will walk you through how I applied formal methods to make certain I had my own counters right.  Further, the simulator would have also caught several of these bugs as well, such as the fat-fingered timings that didn't match the spec you were coming from.

Debugging in hardware is hard.  Use the tools you have to your advantage.

Dan

Highlighted
114 Views
Registered: ‎03-23-2020

Re: VGA Controller : flickering between colours

Okay . So i have tried few different codes which are available. I will we providing the links.

1. Is my monitor faulty ?

     No. because i use it as a secondary display through my laptop and it works just fine on 1366x768.

     I thought it might be some resolution issue where my monitor supports only one default resolution or something so i even tried that recommended resolution i.e 1366x768 and same issue continued.

 

2. Can the Cable be an issue ?   

     Again i use the same cable on a daily basis, so no.

 

3. Can something be wrong with the board ?

   i dont know about this,  i dont have a oscilloscope to check the output signals.

   maybe something is wrong with my board ?

 

I will be trying the links sent by @dgisselq to generate the right clock frequency .

 

can someone help me using the VGA Simulator ?? How do i get it working for my Verilog Code

 

0 Kudos
Highlighted
Scholar
Scholar
105 Views
Registered: ‎05-21-2015

Re: VGA Controller : flickering between colours

@malviyayash18,

Given the VESA timings you cited earlier, you are trying to generate video timings for a 50MHz pixel clock.  You shouldn't need any special work to generate this.  If you needed something like 25.175, I might argue that you'd need something special, but 50MHz should be fairly easy to generate.  Just make certain that you do it with a PLL and not logic.  Generating clocks from logic is a common beginner mistake.

Given the level of errors I found above, I'd recommend you start with SymbiYosys instead of the simulator.  It'll be less work to get up and going, and the tool will last you across many projects.  Check out the lesson on basics and the lesson on k-induction in the Verilog slides found here for a discussion of how to get started.  You'll find more project specific details in the VGA article I cited above.

Feel free to ask for more immediate help on IRC.  Freenode's IRC has ##fpga and #yosys channels that you might find valuable for more of a "conversation" than a forum like this allows.

Dan

0 Kudos
Highlighted
Mentor
Mentor
63 Views
Registered: ‎06-16-2013

Re: VGA Controller : flickering between colours

Hi @malviyayash18 

 

>No. because i use it as a secondary display through my laptop and it works just fine on 1366x768.

 

As you mentioned above, your monitor works fine if vertical frequency (fV) is just 60Hz.

It means that this monitor doesn't have any gen-lock function.

So, I suggest you to calculate video timing with fV = (just) 60Hz (like 1366x768). Adjust horizontal total pixel, vertical total line and pixel clock.

Or, I already mentioned you implement gen-lock function by your-self in your design.

 

Best regards,

0 Kudos
Highlighted
Scholar
Scholar
50 Views
Registered: ‎05-21-2015

Re: VGA Controller : flickering between colours

@watari,

It's simpler than that.  Look over the example code he's posted above.  He's not meeting timing.  The required porches, sync lengths, etc. aren't what they are supposed to be.  There's a math error or two in there.

Dan

0 Kudos