How to make sure a clocked operation happens just once in Vhdl

Electrical Engineering Asked by runo on December 17, 2020

title may be a bit confusing but what I try to do is to take data from ram/modify it and put that data back to the ram. I want all of this to happen just for the operation(Brightness/Contrast) time when I enable the system instead of happening over and over to the point where data becomes deformed. Here is the code. I want write_enable(which enables writing to ram) to stay at 1 just for the operation(in a window which I call cursor) time then go back to 0 even if enable is 1. This is some image processing and I change brightness and contrast of the image in a window I call cursor. This change must happen for all pixels inside cursor just once. I tried many things(complex control mechanism) but failed due to vivado’s unused element removal issue.I am totally out of idea on how to do that. How can I construct such a control mechanism??? I put commends(from here/to here) to show where this problem takes place.

rst is input
clk and clk2 are different clock signals
done is signal
data_in_ram is ram input
output_of_operation is output of change of Brightness or contrast operation
data_rom is output of rom
PICTURE_WIDTH_HEIGHT is length of my square picture (250*250)
pos_x and pos_y are signals that denote pixel coordinates
cursor_pos_x and cursor_pos_y are upper-left coordinate of the window or cursor
length is length of the square window or cursor
clk is 25Mhz
clk2 is 50Mhz. this is chosen 50 due to ram's read latency(2 clock cycle)

The ram and rom below are constructed using block memory generator.

Reading_Writing_Resetting_Ram: process(clk2,clk,rst) is

    if rst = '1' then    
      done <= '0';
    elsif rising_edge(clk) then    
        if done = '0' then
            if address_rom < conv_std_logic_vector((PICTURE_WIDTH_HEIGHT*PICTURE_WIDTH_HEIGHT),16) then
                write_enable <= '1';
                data_in_ram <= data_rom;
                address_ram <= address_rom;
                address_rom <= address_rom + 1;
                address_rom <= (others => '0');
                write_enable <= '0';
                done <= '1';
            end if;
            -------------------------------------part above is for resetting ram
        else --if done = '1' --From here    
            if ( pos_x >= cursor_pos_x ) and (pos_x < cursor_pos_x + length) and ( pos_y >= cursor_pos_y) and (pos_y < cursor_pos_y + length) then --if within cursor

                address_ram <=(conv_std_logic_vector((pos_x + pos_y*PICTURE_WIDTH_HEIGHT),16));
                data_in_ram <= output_of_operation;   

                if enable = '1' then    
                    write_enable <= '1';
                    write_enable <= '0';    
                end if; -- enable    
            else --if out of cursor -- to here
                -------------------------- part below is for reading from ram
                write_enable <= '0';

                if (pos_x < PICTURE_WIDTH_HEIGHT) and (pos_y <PICTURE_WIDTH_HEIGHT) and (pos_x >= 0) and (pos_y >= 0) then -- if within picture

                    address_ram <=(conv_std_logic_vector((pos_x + pos_y*PICTURE_WIDTH_HEIGHT),16));

                end if; 
            end if; 
        end if; 
    end if;    
end process;

This code below is used for second condition for write_enable but vivado removes this components.

Adjusting_enable2: process(rst,clk,cursor_pos_x,cursor_pos_y,enable,cursor_mode,current_cursor_mode,c_cursor_pos_x,c_cursor_pos_y) is
if (rst = '1') or (cursor_mode /= current_cursor_mode) or (c_cursor_pos_x /= cursor_pos_x) or (c_cursor_pos_y /= cursor_pos_y)  then

enable2 <= '1';
c_cursor_pos_x <= cursor_pos_x;
c_cursor_pos_y <= cursor_pos_y;
counter_for_enable2 <= 0;

elsif rising_edge(clk) then

if enable ='1' then


counter_for_enable2 <= counter_for_enable2 + 1;


enable2 <= '0';

end if;
end if;
end if;
end process;

One Answer

Assuming you haven't(?)... I think you should draw your design before you type, you will get much more out of the experience and suffer less issues like you have been posting... nonetheless, you stated:

I want write_enable(which enables writing to ram) to stay at 1 just for the operation(in a window which I call cursor) time then go back to 0 even if enable is 1

Not sure if it solves your overall issue, but based on this sentence, it translates to AND'ing cursor and enable.

combinatorial: write_enable = cursor and enable;

inside a clocked process: write_enable <= cursor and enable;

Answered by CapnJJ on December 17, 2020

Add your own answers!

Related Questions

Why X0 equals zero?

1  Asked on January 25, 2021 by omar


What’s the catch with FRAM?

4  Asked on January 25, 2021 by david-given


Best-practices for potting a high-voltage circuit

3  Asked on January 25, 2021 by adam-v-steele


How to find True power dissipated and apparent power?

2  Asked on January 25, 2021 by michael-scott


Connecting MAX9814 to Speaker

0  Asked on January 24, 2021 by ajisu


Power Dissipation of Diode

2  Asked on January 24, 2021


Atmega32u4 USB 2.0 Routing Check

1  Asked on January 23, 2021 by adam-lee


Bench Power Supply Current Rating

2  Asked on January 22, 2021


Scaling a 0-90 ohm range to 10-520

1  Asked on January 21, 2021 by michael-lowry


12V DC to 12V AC (50 Hz) converter / inverter for low loads (< 1A)

5  Asked on January 21, 2021 by paul-weber


Can I use 1 to 2 power adaptor to measure current with multimeter

3  Asked on January 20, 2021 by abdullah-muhanna


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP