Hi - first post here, I am trying to describe a counter which accepts an address and increments by 1 each cycle. The problem is that the counter always starts at 0 even when reset is '0'. I have attached the code below. Can anybody see where I am going wrong? I thought that by assigning the value 'a' to 'temp_address' in the process that it would work as expected. Any feedback welcome - thanks. entity c1_new_address is generic (n: integer := 14); port (a: in std_logic_vector((n-1) downto 0); clk, reset: in std_logic; w: out std_logic_vector((n-1) downto 0)); end c1_new_address; architecture Behavioral of c1_new_address is signal temp_address: std_logic_vector((n-1) downto 0); begin process(clk, reset) begin if reset = '1' then temp_address <= (others => '0'); elsif rising_edge(clk) then temp_address <= a; temp_address <= conv_std_logic_vector((conv_integer(temp_address) + 1), 14); end if; w <= temp_address; end process; end Behavioral;
There are two 'assignments' to temp_address: temp_address <= a; temp_address <= conv_std_logic_vector((conv_integer(temp_address) + 1), 14); Which one should get calculated. As far as I know, the 'compiler' takes the last one and ignores all previous. Meaning the you will always get temp_address <= conv_std_logic_vector((conv_integer(temp_address) + 1), 14); and temp_address <= a; is discarded.
I thought that as a process runs statements sequentially that both assignments should get run in the order that they are in => on the rising edge, temp is assigned the ip value and it is incremented on the next statement. I also tried assigning the value 'a' to temp_address outside the process so that the same value doesn't get assigned to temp_address during each run of the process with the ip address still not being assigned to temp_address.
Hello David, have you try this way: temp_address <= conv_std_logic_vector((conv_integer(a) + 1), 14); In this case there is only one statement. Regards, mifi
> I thought that as a process runs statements sequentially that both > assignments should get run in the order that they are in The assignments do not run, and they are not executed. You are thinking in sequential software (like Basic or C). In real hardware all of your statements are executed at the exactly same time (at the moment the clock signal rises). Having fixed that, you must have a look for the behaviour of signals in a VHDL process: they don't change their values until the end of the process. And then the last assignment "wins" and the signal gets its new value. Here X never ever will have another value than 7, because thats the last assignment to this signal:
1 | process (A) begin |
2 | X <= 1; |
3 | X <= A+3; |
4 | X <= 7; |
5 | end process; |
Here X never will increment, but just store the value of A:
1 | process (clk) begin |
2 | if rising_edge(clk) then |
3 | X <= 7; |
4 | X <= X+1; |
5 | X <= A; |
6 | end if; |
7 | end process; |
And here X will simply count up:
1 | process (clk) begin |
2 | if rising_edge(clk) then |
3 | X <= 7; |
4 | X <= X+1; |
5 | end if; |
6 | end process; |
@ mifi - I used your method and it worked a treat. @ Lothar - That was a simple and effective way of explaining the assignment operation in a process. Thank you gentlemen.
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.