Challenge - 5 Problems
Single-port RAM Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this VHDL process for a single-port RAM?
Consider a single-port RAM with 4 words of 8 bits each. The process below writes data when write_enable is '1' and reads data otherwise. What is the value of data_out after the rising edge of clk when write_enable='1', address=2, and data_in="10101010"?
VHDL
process(clk) type ram_type is array (0 to 3) of std_logic_vector(7 downto 0); variable ram : ram_type := (others => (others => '0')); begin if rising_edge(clk) then if write_enable = '1' then ram(to_integer(unsigned(address))) := data_in; data_out <= data_in; else data_out <= ram(to_integer(unsigned(address))); end if; end if; end process;
Attempts:
2 left
💡 Hint
Remember that when write_enable is '1', the data is written and output immediately.
✗ Incorrect
When write_enable is '1', the process writes data_in to the RAM at the given address and outputs data_in immediately on data_out.
❓ Predict Output
intermediateWhat is the output of this VHDL code reading from single-port RAM?
Given the same RAM as before, if write_enable='0', address=1, and the RAM content at address 1 is "11001100", what will data_out be after the rising edge of clk?
VHDL
process(clk) type ram_type is array (0 to 3) of std_logic_vector(7 downto 0); variable ram : ram_type := ("00000000", "11001100", "10101010", "11110000"); begin if rising_edge(clk) then if write_enable = '1' then ram(to_integer(unsigned(address))) := data_in; data_out <= data_in; else data_out <= ram(to_integer(unsigned(address))); end if; end if; end process;
Attempts:
2 left
💡 Hint
When write_enable is '0', the RAM outputs the stored data at the address.
✗ Incorrect
Since write_enable is '0', the process reads the RAM content at address 1, which is "11001100".
🔧 Debug
advancedIdentify the error in this single-port RAM VHDL code snippet
This VHDL code is intended to implement a single-port RAM. What error will occur when compiling or simulating this code?
VHDL
process(clk) type ram_type is array (0 to 3) of std_logic_vector(7 downto 0); variable ram : ram_type := (others => (others => '0')); begin if rising_edge(clk) then if write_enable = '1' then ram(address) := data_in; data_out <= data_in; else data_out <= ram(address); end if; end if; end process;
Attempts:
2 left
💡 Hint
Check the type of 'address' and how it is used as an index.
✗ Incorrect
The 'address' signal is usually a std_logic_vector and must be converted to integer using to_integer(unsigned(address)) before indexing the RAM array.
📝 Syntax
advancedWhich option correctly declares a single-port RAM signal in VHDL?
You want to declare a RAM signal with 16 words of 8 bits each. Which declaration is syntactically correct?
Attempts:
2 left
💡 Hint
Remember that arrays must be declared as types before signals can use them.
✗ Incorrect
Option A correctly declares a type for the RAM array and then declares a signal of that type with initialization.
🚀 Application
expertHow many clock cycles are needed to write and then read a value from this single-port RAM?
Given a synchronous single-port RAM with one clock input, write_enable, address, data_in, and data_out signals, how many clock cycles does it take to write a value to address 5 and then read it back at address 5?
Attempts:
2 left
💡 Hint
Consider that writing happens on one clock edge and reading the updated data requires another clock edge.
✗ Incorrect
Writing the data occurs on the first clock cycle when write_enable is '1'. Reading the data back requires the next clock cycle with write_enable '0' to output the stored value.
