Altera_Forum
Honored Contributor
15 years agoNew to VHDL: Understanding timer.vhd implementation
I'm an old hand at C/C++ just getting my feet wet with VHDL. In the course of my learning, I've used the SOPC builder to create a simplified system that included a timer. Part of the emitted VHDL code for the timer includes the following snippet:
control_wr_strobe <= (chipselect AND NOT write_n) AND to_std_logic((((std_logic_vector'("00000000000000000000000000000") & (address)) = std_logic_vector'("00000000000000000000000000000001"))));
process (clk, reset_n)
begin
if reset_n = '0' then
control_register <= std_logic'('0');
elsif clk'event and clk = '1' then
if std_logic'(control_wr_strobe) = '1' then
control_register <= writedata(0);
end if;
end if;
end process;
In simulating this with ModelSim and 'manually' driving chipselect, write_n, etc., it appears that the write into the control register by writedata(0) does not occur unless I extend the assertions of the signal lines (chipselect, write_n, address) so they last for at least two rising edges of 'clk'. My understanding is that because all of this is concurrent, on the first iteration (assuming the chipselect, write_n get asserted with the rising edge of 'clk'), ModelSim will not evaluate the "if std_logic'(control_wr_strobe) = '1' then" statement to true.. at least not on the first 'delta' iteration. This is because all of the processes and the implied process driving the value to control_wr_strobe occur at the same time. It won't be until after the delta time in the simulation following the rising edge event that control_wr_strobe will be actually evaluated to a '1'. By this time, it's too late - the rising clock edge has been evaluated and will not cause the process(clk,reset_n) to be scheduled again. Instead, it's necessary to keep chipselect & write_n asserted so that on the *next* rising clk edge the control_register is updated. Is this line of thought correct? Further, this is looking at things from a simulation mindset. When things are synthesized, is this same timing required? In other words, the chipselect and write_n lines will need to be held for at least two clock cycles to be properly executed. Does this mean that the Avalon MM Slave interface requires at least 1 wait cycle for a write? I believe this is the case, but was hoping for confirmation. Thanks! --tim