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.

When ....else ==> red flip to green ??

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Guys,

I'm beginner on VHDL and playing with VGA,
I want to flip green to red with one statement of VHDL, is that possible ?

I tried with combining :

Code:
red <= '1' when vert_scan > 10 and vert_scan < 515 and horz_scan >= 100 and horz_scan < 350 else '0';
grn <= '1' when vert_scan > 20 and vert_scan < 525 and horz_scan >= 200 and horz_scan < 450 else '0';

but it didn't work, is there anyway to combine it on one statement ?

Any ideas ?

Thanks
 

Re: When ....else ==&gt; red flip to green ??

A flip-flop must to be described under a clocked process.

Code:
process (clock) is
begin
  if rising_edge (clock) then -- can also be "if falling edge (clock)"
    
    if ( vert_scan > 10 and vert_scan < 515 and horz_scan >= 100 and horz_scan < 350 ) then
      red <= '1' ;
    else 
      red <= '0' ;
    end if ;
    
    if vert_scan > 20 and vert_scan < 525 and horz_scan >= 200 and horz_scan < 450
      grn <= '1' ;
    else 
      grn <= '0' ;
    end if ;

  end if ;
end process ;

- - - Updated - - -

BTW:

It's good practice to assign a reset value to the "grn" & "red" signals.

Code:
process (clock,reset) is
begin
  if reset = '1' then
    grn <= '0' ; -- or '1'
    red <= '0' ; -- or '1' 
  elsif rising_edge (clock) then -- can also be "if falling edge (clock)"
    
    if ( vert_scan > 10 and vert_scan < 515 and horz_scan >= 100 and horz_scan < 350 ) then
      red <= '1' ;
    else 
      red <= '0' ;
    end if ;
    
    if vert_scan > 20 and vert_scan < 525 and horz_scan >= 200 and horz_scan < 450
      grn <= '1' ;
    else 
      grn <= '0' ;
    end if ;

  end if ;
end process ;
 
  • Like
Reactions: js

    js

    Points: 2
    Helpful Answer Positive Rating
but it didn't work
Means exactly what? You can perform a conditional assignment in combinational code as shown. The signal usually shows glitches when more than one input bit changes at the same time, this happens quite often for a binary counter. Assigning the result unter clock control is one possible way to avoid glitches, but not generally required.
 

Re: When ....else ==&amp;gt; red flip to green ??

how can I create a counter for a 1 second delay ?

- - - Updated - - -

I have made :
Code:
process (clk) is
	begin
	  if rising_edge (clk) then -- can also be "if falling edge (clock)"
		 
		 if ( vert_scan > 10 and vert_scan < 515 and horz_scan >= 100 and horz_scan < 350 ) then
			red <= '1' ;
		 else 
			red <= '0' ;
		 end if ;
		 
		 if vert_scan > 20 and vert_scan < 525 and horz_scan >= 200 and horz_scan < 450 then
			grn <= '1';
		 else 
			grn <= '0';
		 end if;

	  end if;
	end process;

It can be compiled successfully, I'm going to try on the board now....and see what it does

- - - Updated - - -

I have a progress it's not flipping but combining between red and green, please have a look on my photo...
IMG_20140803_191501.jpg
Thanks
 

According to the code you have a 100 pixel wide red bar, 150 red+green (yellow) and 100 green. That's what I see in the photo.
 

how can I make flip between green and red ? Visible flip flop between red and green ?
 

how can I make flip between green and red ? Visible flip flop between red and green ?
What do you mean?
 

I think the OP wants to be able to swap the color bars of read and green....i.e. if the display currently shows reg-green swap to show the bars as green-red.
 

I think the OP wants to be able to swap the color bars of read and green....i.e. if the display currently shows reg-green swap to show the bars as green-red.
I already explained why the screen shows a yellow bar. It's what the code commands. There's also a blue bar, but no code for the blue VGA output shown.

It seems obvious what you would do to remove the yellow bar. I'm also under the impression that it should be easy to get arbitrary colour sequences by writing a few code lines.

The question however is unclear, do you want green to red or red to green? How about the blue bar?
 

I intentionally ignored the yellow bar, as I assume the OP wants to start with red-yellow-green-black-blue and wants to change to green-yellow-red-black-blue after 1 second and then back to the original color sequence after another 1 second. Given what they've so far described.

Now depending on the clock available...


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
constant FREQ_OF_CLK_IN_HZ = 25000000; -- 25 MHz clock
signal second : std_logic;
signal sec_cnt : unsigned;
signal swap : std_logic;
 
process (clk, rst) is
begin
  if rst = '1' then
    sec_cnt <= 0;
    second <= '0';
  elsif rising_edge (clk) then
    if sec_cnt < FREQ_OF_CLK_IN_HZ - 1 then
      sec_cnt <= sec_cnt + 1;
      second <= '0';
    else
      sec_cnt <= 0;
      second <= '1';
    end if;
  end if;
end process;
 
-- swap color every 1 second
process (clk) is
  if rst = '1' then
    swap <= '0'
  elsif rising_edge (clk) then
    if second = '1' then
      swap <= not swap;
    end if;
  end if;
end process;
 
-- use the swap signal to decide which color ordering is being sent.
process (clk) is
begin
  if rst = '1' then
    red <= '0'
    grn <= '0'
  elsif rising_edge (clk) then
    if ( vert_scan > 10 and vert_scan < 515 and horz_scan >= 100 and horz_scan < 350 ) then
      if swap = '0' then
        -- start off as red (swap = '0' after reset) red-yellow-green
        red <= '1';
        grn <= '0';
      else
        -- switch to green-yellow-red
        red <= '0';
        grn <= '1';
      end if;
    end if ;
    if vert_scan > 20 and vert_scan < 525 and horz_scan >= 200 and horz_scan < 450 then
      if swap = '0' then
        -- start off as red (swap = '0' after reset) red-yellow-green
        red <= '0';
        grn <= '1';
      else
        -- switch to green-yellow-red
        red <= '1';
        grn <= '0';
      end if;
    end if;
  end if;
end process;



If my assumptions are correct that should do what the OP wants (with corrections for any typos/syntax errors).

Regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top