2
\$\begingroup\$

I am trying to make an up/down counter on a Basys board. But I have some issues I can't figure out.

My code:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity counter is
 Port (
 clock : in STD_LOGIC;
 clock_osc : in STD_LOGIC;
 reset : in STD_LOGIC;
 count_start : in STD_LOGIC;
 count_out : out STD_LOGIC_VECTOR (3 downto 0);
 AN1 : out STD_LOGIC;
 AN2 : out STD_LOGIC;
 AN3 : out STD_LOGIC;
 AN4 : out STD_LOGIC
 );
end counter;
architecture Behavioral of counter is
 signal count : std_logic_vector (3 downto 0);
 signal count2 : std_logic_vector (3 downto 0);
begin
 countupdown: process (clock, reset, count_start)
 begin
 if (reset = '0') then
 count <= "0000";
 count2 <= "0000";
 elsif (clock='1' and clock'event) then
 if (count_start = '0') then
 count <= count + 1;
 else 
 count2 <= count2 - 1;
 end if;
 end if;
 end process;
 count_out<= count when (clock_osc = '1') else count2;
 AN1<='0' when (clock_osc='1') else '1';
 AN2<='0' when (clock_osc='1') else '1';
 AN3<='1' when (clock_osc='1') else '0';
 AN4<='1' when (clock_osc='1') else '0' ;
end Behavioral;

The errors:

ERROR:HDLParsers:808 - "C:/Users/sana4/Desktop/uni/Digital Design/Counter3/counter.vhd" Line 75. + can not have such operands in this context.
ERROR:HDLParsers:808 - "C:/Users/sana4/Desktop/uni/Digital Design/Counter3/counter.vhd" Line 79. - can not have such operands in this context.
Dave Tweed
184k17 gold badges248 silver badges432 bronze badges
asked Apr 24, 2014 at 10:31
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Please format your code properly, eliminate the extra blank lines, and tell us which lines are line 75 and 79. \$\endgroup\$ Commented Apr 24, 2014 at 10:38

1 Answer 1

5
\$\begingroup\$

I've taken the liberty of cleaning up your listing and formatting it for compactness and readability, so I've undoubtedly messed up the line numbering.

The specific errors you're getting are caused by the fact that you can't do arithmetic on std_logic_vector, e.g., to increment and decrement your counters. At a minimum, you need to include the library ieee.numeric_std in order to allow this. See the answers to this question for additional details.

answered Apr 24, 2014 at 11:21
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.