Fixing VHDL Syntax Error: Creating Up/Down Counter

  • Thread starter ineedmunchies
  • Start date
  • Tags
    Error
In summary, the conversation discusses creating an Up/Down counter with outputs for both units and tens, which can be displayed on 7 segment displays. The attempted solution provided through VHDL code includes syntax errors and issues with using quotation marks for binary values. The conversation concludes with the individual gaining a better understanding of VHDL and resolving the errors in the code.
  • #1
ineedmunchies
45
0

Homework Statement


Creating an Up/Down counter with an output for both units and tens. (which can then be displayed on 7 segnment displays)


Homework Equations





The Attempt at a Solution



Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity UpDownCount is
  port(Clk, UpDown, reset: in std_logic;
  unit, tens: out std_logic_vector(3 downto 0)
  );
End UpDownCount;

Architecture behv2 of UpDownCount is
signal units1, tens1: unsigned(3 downto 0);
begin
  
  process(UpDown, Clk, reset)
  variable CountUnits, CountTens : unsigned (3 downto 0);
  begin
      
  if (Clk'event and UpDown='1') then
     ****if CountUnits ='1111' then
      CountTens := CountTens + '1';
    else
     ****CountUnits := CountUnits + '1';  
    end if;
  elsif (Clk'event and UpDown='0') then
    if CountUnits = '0000' then
      CountTens := CountTens - '1';
    else CountUnits := CountUnits - '1';
  end if;
end if;
  end process
end architecture

The two lines with the stars are the ones where there are errors apparently. For the first one it says there is a syntax error near " ' ", and the second one it says it is expecting an "end" near "elseif". So I'm thinking is there a problem with my if-then statements? Do I need to use parenthesis to wrap the code that's included in the then part? I know its probably something quite simple, but I can't figure it out.
 
Physics news on Phys.org
  • #2
I've got very limited experience with VHDL (and don't have a simulator installed), but rather than CountUnits = '1111', try using CountUnits = "1111". Same goes for CountUnits ='0000'. Did this help?
 
  • #3
It did indeed, I forgot that youe need to use " when dealing with 0000 instead of just 0 etc.
Thank you! There's also a ton of other mistakes in there, but I cleared them up too.
 

1. What is a VHDL syntax error?

A VHDL syntax error is an error that occurs when the syntax or structure of the VHDL code is incorrect. Syntax errors can prevent a VHDL program from being successfully compiled and executed.

2. How do I know if I have a syntax error in my VHDL code?

Most VHDL compilers will display an error message when a syntax error is encountered. The error message will usually include information about the specific line of code where the error occurred and the type of error.

3. What is an up/down counter in VHDL?

An up/down counter is a type of counter in VHDL that can count both upwards and downwards. It is commonly used in digital circuits to keep track of the number of times a specific event has occurred.

4. How do I fix a syntax error in my VHDL code?

The first step in fixing a syntax error is to carefully review the error message and identify the line of code where the error occurred. Then, check the syntax of that line of code and make any necessary corrections. It may also be helpful to consult online resources or ask for help from more experienced VHDL programmers.

5. Can a syntax error affect the functionality of my VHDL program?

Yes, a syntax error can prevent a VHDL program from being successfully compiled and executed, which means it will not function as intended. It is important to fix any syntax errors in your code to ensure proper functionality.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
11K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • General Engineering
Replies
3
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Electrical Engineering
Replies
6
Views
2K
  • General Engineering
Replies
2
Views
4K
  • Electrical Engineering
Replies
2
Views
27K
Back
Top