Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

It adds 3 and subtracts 1 instead of adding just 1

Hi!

I'm pretty new with vhdl and Quartus II and maybe this question is too obvious, but I spent three days on it and I cannot understand yet why is not working... I made a silly program, just adding one to a number, and just send one bit to the output. I tried to simulate it. There are no errors on Analysis & Synthesis, and no errors on EDA Netlist Writer. But the simulation is wrong (I don't obtain what I should)

1. I make a reset and "nombre" should be "0101010101", instead it is "0000000".

2. It should add 1 to this variable at each rising edge clock. Instead sometimes it adds 3 and then subtracts 1.

I cannot understand what's happening. I know it should be a really silly mistake from me, because this program is too simple, but I cannot find it. Moreover I've done a more complicated program and I had no problems. Can anybody help me, please?

Hier there is the code:

------------------------------------------------------------------------

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

library altera;

use altera.altera_primitives_components.all;

entity prova1 is

port

(

-- Input ports

clk : in std_logic;

reset : in std_logic;

-- Output ports

sortida : out std_logic

);

end prova1;

-- Library Clause(s) (optional)

-- Use Clause(s) (optional)

architecture arch_prova1 of prova1 is

signal nombre : std_logic_vector(9 downto 0):="0101010101";

begin

pr1: process(clk,reset,nombre)

begin

if reset='1' then

nombre<="0101010101";

else

if(rising_edge(clk)) then

nombre<=nombre+1;

else

nombre<=nombre;

end if;

end if;

end process pr1;

-- Add the library and use clauses before the design unit declaration

ff_sortida : DFF

port map (

d => nombre(4),

clk => clk,

clrn => not(reset),

prn => '1',

q => sortida

);

end arch_prova1;

34 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    And try also to be sure that, form a hardware point of view, the logic is reset during the board power-up (using a simple RC circuit or some safer reset ICs which you can find in the market).

    --- Quote End ---

    A reliable power-up reset can also be achieved by using the FPGA internal reset, possibly supplemented by a delay. As long as no other reset sources are intended in the design, the external reset isn't actually necessary. Of course it does no harm to provide it anyway and keep it for possible design extensions.

    The signal nombre is initialized to the same state in FPGA internal power-up reset as by the external reset input. This also happens implicitely, if the initialisation expression is removed from the signal declaration.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Quartus will issue the sensitivity list warning whenever you read the value of an externally declared signal within a process UNLESS the read occurs under a clock-edge. In your case, you're reading "count" when you say count <= count. This read occurs in the else branch, so it's outside the clock edge. Prior posts indicated the correct recommendation - just avoid the unnecessary else branch.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If you dig through the Quartus synthesis documents then you will find that, as previously mentioned by some of the eminent VHDL chaps in this thread, the default value in the signal declaration is used by Quartus as a reset value.

    But I have learnt from various VHDL courses that I have been on, that some synthesis tools ignore the default signal value and therefore for these tools you have to use a reset signal.

    Whether you stick with default signal values or incorporate a reset signal (which you could generate internally), is up to you but just bear in mind that default signal values may not result in portable code.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I am agree, I may add

    If you use an external reset, you'd better resynchronize reset (and often with delay block) and incorporate it.

    To resume, it is better writing "if reset" statement in synchronous process to initialize values.