tried to search for answer on something I don't quite understand, but
found little. Maybe I don't know the right keywords to search for:
In an SPI I have an internal data register called data_int which looks
like this:
process(clk,reset)
begin
if reset = '1' then
....
elsif rising_edge(clk) then
.....
data_int <= data_int(8 downto 0) & SDATA
.....
end if;
end process;
DATA <= data_int;
DATA and SDATA are ports on the entity and both DATA and data_int are
std_logic_vector(8 downto 0) and SDATA is serial data from slave SPI
of std_logic type.
When simulating with modelsim, I see that data_int is updated on the
rising edge of clk. data, on the other hand, is updated on the
following falling edge of clk. This I don't understand. I also tried
data <= data_int after 1 ns;
but that just delayed the update of data 1 ns after the falling edge
of clk. My code doesn't have any timing resolution statements, and I
don't know if modelsim has something by default, and I haven't found
anything about this half-cycle delay in any of the books I have.
Svenn Are Bjerkem wrote:
> Hi,
>
> tried to search for answer on something I don't quite understand, but
> found little. Maybe I don't know the right keywords to search for:
>
> In an SPI I have an internal data register called data_int which looks
> like this:
>
> process(clk,reset)
> begin
> if reset = '1' then
> ....
> elsif rising_edge(clk) then
> .....
> data_int <= data_int(8 downto 0) & SDATA
> .....
> end if;
> end process;
> DATA <= data_int;
>
> DATA and SDATA are ports on the entity and both DATA and data_int are
> std_logic_vector(8 downto 0) and SDATA is serial data from slave SPI
> of std_logic type.
>
> When simulating with modelsim, I see that data_int is updated on the
> rising edge of clk. data, on the other hand, is updated on the
> following falling edge of clk. This I don't understand. I also tried
> data <= data_int after 1 ns;
> but that just delayed the update of data 1 ns after the falling edge
> of clk. My code doesn't have any timing resolution statements, and I
> don't know if modelsim has something by default, and I haven't found
> anything about this half-cycle delay in any of the books I have.
>
> Anybody have a pointer to what I am missing here?
>
> --
> Svenn
That looks wrong. Data should update 1 delta after data_int, i.e. after
the rising edge of the clock.
The only conclusion I can reach is that the code you have posted is not
the code you are simulating :-)
Please cut and paste exactly the same code you are simulating into your
message.
regards
Alan
P.S. I bet that your code actually looks like this
On Aug 12, 7:02 pm, Alan Fitch <alan.fi...@spamtrap.com> wrote:
> Please cut and paste exactly the same code you are simulating into your
> message.
>
Yeah, I wanted to avoid that, as the code is not finished. There are
things not working according to spec, and things that may be
completely wrong, it is the first step on a journey, but I have this
simulation problem that I do not get around, so here you go. Help me,
don't use it against me :-)
port (
-- external interface
SDATA : in std_logic;
SCLK : out std_logic;
CS_N : out std_logic;
-- internal interface
CLK : in std_logic;
RESET : in std_logic;
DATA : out std_logic_vector(9 downto 0);
DATA_REQ : in std_logic;
DATA_RDY : out std_logic
);
component spi_ad7273
port (
SDATA : in std_logic;
SCLK : out std_logic;
CS_N : out std_logic;
CLK : in std_logic;
RESET : in std_logic;
DATA : out std_logic_vector(9 downto 0);
DATA_REQ : in std_logic;
DATA_RDY : out std_logic);
end component;
component ad7273
port (
sdata : out std_logic;
sclk : in std_logic;
cs_n : in std_logic);
end component;
-- component ports
signal SDATA : std_logic;
signal SCLK : std_logic;
signal CS_N : std_logic;
signal CLK : std_logic := '0';
signal RESET : std_logic;
signal DATA : std_logic_vector(9 downto 0);
signal DATA_REQ : std_logic;
signal DATA_RDY : std_logic;
-- waveform generation
WaveGen_Proc: process
begin
-- insert signal assignments here
data_req <= '0';
reset <= '0';
wait for 50 ns;
reset <= '1';
wait for 50 ns;
reset <= '0';
wait for 55 ns;
data_req <= '1';
wait for 500 ns;
data_req <= '0';
wait;
end process WaveGen_Proc;
entity ad7273 is
port(
sdata : out std_logic;
sclk : in std_logic;
cs_n : in std_logic
);
end entity;
architecture rtl of ad7273 is
signal sdata_int : std_logic := 'Z';
signal sdata_reg : std_logic_vector(9 downto 0) := "1010101010";
begin
process(sclk,cs_n)
variable i : integer := 0;
begin
if sclk'event and sclk = '0' then
if cs_n = '0' then
sdata_int <= not sdata_reg(i mod 10);
i := i + 1;
else
i := 0;
sdata_int <= 'Z';
end if;
end if;
end process;
sdata <= sdata_int;
end rtl;
On Tue, 12 Aug 2008 23:31:46 -0700 (PDT), Svenn Are Bjerkem
<[email protected]> wrote:
>On Aug 12, 7:02 pm, Alan Fitch <alan.fi...@spamtrap.com> wrote:
>> Please cut and paste exactly the same code you are simulating into your
>> message.
>>
>
>Yeah, I wanted to avoid that, as the code is not finished. There are
>things not working according to spec, and things that may be
>completely wrong, it is the first step on a journey, but I have this
>simulation problem that I do not get around, so here you go. Help me,
>don't use it against me :-)
And your code is exactly as Alan guessed; and unlike your first posting.
Why it does what it does should now become painfully clear.
Brian Drummond wrote:
> On Tue, 12 Aug 2008 23:31:46 -0700 (PDT), Svenn Are Bjerkem
> <[email protected]> wrote:
>
>> On Aug 12, 7:02 pm, Alan Fitch <alan.fi...@spamtrap.com> wrote:
>>> Please cut and paste exactly the same code you are simulating into your
>>> message.
>>>
>> Yeah, I wanted to avoid that, as the code is not finished. There are
>> things not working according to spec, and things that may be
>> completely wrong, it is the first step on a journey, but I have this
>> simulation problem that I do not get around, so here you go. Help me,
>> don't use it against me :-)
>
> And your code is exactly as Alan guessed; and unlike your first posting.
>
> Why it does what it does should now become painfully clear.
>
> - Brian
Actually I'd guessed the assignment was inside the process and so was
being assigned on both edges.
The problem's even easier than that, the process is negative edge
triggered! (clk'event and clk = '0')
Brian Drummond wrote:
> On Tue, 12 Aug 2008 23:31:46 -0700 (PDT), Svenn Are Bjerkem
> <[email protected]> wrote:
>
>> On Aug 12, 7:02 pm, Alan Fitch <alan.fi...@spamtrap.com> wrote:
>>> Please cut and paste exactly the same code you are simulating into your
>>> message.
>>>
>> Yeah, I wanted to avoid that, as the code is not finished. There are
>> things not working according to spec, and things that may be
>> completely wrong, it is the first step on a journey, but I have this
>> simulation problem that I do not get around, so here you go. Help me,
>> don't use it against me :-)
>
> And your code is exactly as Alan guessed; and unlike your first posting.
>
> Why it does what it does should now become painfully clear.
>
> - Brian
Actually I'd guessed the assignment was inside the process and so was
being assigned on both edges.
The problem's even easier than that, the process is negative edge
triggered! (clk'event and clk = '0')
On Wed, 13 Aug 2008 15:01:11 +0100, Alan Fitch <[email protected]>
wrote:
>Brian Drummond wrote:
>> And your code is exactly as Alan guessed; and unlike your first posting.
>>
>> Why it does what it does should now become painfully clear.
>>
>> - Brian
>
>Actually I'd guessed the assignment was inside the process and so was
>being assigned on both edges.
>
>The problem's even easier than that, the process is negative edge
>triggered! (clk'event and clk = '0')
>
Heh, you were looking at:
architecture rtl of ad7273
and I was looking at:
architecture rtl of spi_ad7273
which is...
p_ad7273_spi : process(RESET, CLK)
variable bit_count : integer := 0; -- counts shifted bits
begin
if (RESET = '1') then
data_int <= (others => '0');
elsif CLK'event and CLK = '1' then
...
end if;
DATA <= data_int after 1 ns;
end process;
.... just as you described.
The other negative edge triggered process appears to be a bonus.
On Aug 14, 2:23 am, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
> On Wed, 13 Aug 2008 15:01:11 +0100, Alan Fitch <alan.fi...@spamtrap.com>
> wrote:
>
> >Brian Drummond wrote:
> >> And your code is exactly as Alan guessed; and unlike your first posting.
>
> >> Why it does what it does should now become painfully clear.
>
> >> - Brian
>
> >Actually I'd guessed the assignment was inside the process and so was
> >being assigned on both edges.
>
> >The problem's even easier than that, the process is negative edge
> >triggered! (clk'event and clk = '0')
>
> Heh, you were looking at:
> architecture rtl of ad7273
The entity that I will use later is the spi_ad7273. the entity ad7273
is a model of the AD-converter that I am talking to and will be used
only for testing spi_ad7273.
On Aug 13, 1:28 pm, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
> On Tue, 12 Aug 2008 23:31:46 -0700 (PDT), Svenn Are Bjerkem
>
> <svenn.bjer...@googlemail.com> wrote:
> >On Aug 12, 7:02 pm, Alan Fitch <alan.fi...@spamtrap.com> wrote:
> >> Please cut and paste exactly the same code you are simulating into your
> >> message.
>
> >Yeah, I wanted to avoid that, as the code is not finished. There are
> >things not working according to spec, and things that may be
> >completely wrong, it is the first step on a journey, but I have this
> >simulation problem that I do not get around, so here you go. Help me,
> >don't use it against me :-)
>
> And your code is exactly as Alan guessed; and unlike your first posting.
>
> Why it does what it does should now become painfully clear.
>
I lick my wounds. Moving the assignments out of the process solved the
problem, as expected, and I don't really know why they were in there
at all. Must have been sleeping while typing and later got so code
blind that I didn't see it. Well it is always good to have somebody
review the code, and then the real code and not some here-is-what-I-
think-I-have-done snippet. Thanks a lot to you guys.
Brian Drummond wrote:
> On Wed, 13 Aug 2008 15:01:11 +0100, Alan Fitch <[email protected]>
> wrote:
>
>> Brian Drummond wrote:
>
>>> And your code is exactly as Alan guessed; and unlike your first posting.
>>>
>>> Why it does what it does should now become painfully clear.
>>>
>>> - Brian
>> Actually I'd guessed the assignment was inside the process and so was
>> being assigned on both edges.
>>
>> The problem's even easier than that, the process is negative edge
>> triggered! (clk'event and clk = '0')
>>
>
> Heh, you were looking at:
> architecture rtl of ad7273
>
> and I was looking at:
> architecture rtl of spi_ad7273
> which is...
>
> p_ad7273_spi : process(RESET, CLK)
> variable bit_count : integer := 0; -- counts shifted bits
> begin
> if (RESET = '1') then
> data_int <= (others => '0');
> elsif CLK'event and CLK = '1' then
> ...
> end if;
> DATA <= data_int after 1 ns;
> end process;
> .... just as you described.
>
> The other negative edge triggered process appears to be a bonus.
>
> - Brian
>
Ooh, well spotted, I must read more carefully in future...
Alan