VHDL Method Call - vhdl

Is it possible to write a code segment and call it, instead of writing that segment many times? Ie. I want to reuse a segment of code as shown below:
process (currentState)
begin
case currentState is
when requiredCoinsTensAnode => anodes <= "100000";--turn on the tens display
case tensCount is
when "0000" => segDisplay <= "1111110"; --0
when "0001" => segDisplay <= "0110000"; --1
when "0010" => segDisplay <= "1101101"; --2
when "0011" => segDisplay <= "1111001"; --3
when "0100" => segDisplay <= "0110011"; --4
when "0101" => segDisplay <= "1011011"; --5
when "0110" => segDisplay <= "1011111"; --6
when "0111" => segDisplay <= "1110000"; --7
when "1000" => segDisplay <= "1111111"; --8
when others => segDisplay <= "1111011"; --9
end case;
nextState <= requiredCoinsUnitsAnode;--just displayed the tens digit, next we need to display the units digit
when requiredCoinsUnitsAnode => anodes <= "010000";--turn on the units display
case unitsCount is
when "0000" => segDisplay <= "1111110"; --0
when "0001" => segDisplay <= "0110000"; --1
when "0010" => segDisplay <= "1101101"; --2
when "0011" => segDisplay <= "1111001"; --3
when "0100" => segDisplay <= "0110011"; --4
when "0101" => segDisplay <= "1011011"; --5
when "0110" => segDisplay <= "1011111"; --6
when "0111" => segDisplay <= "1110000"; --7
when "1000" => segDisplay <= "1111111"; --8
when others => segDisplay <= "1111011"; --9
end case;
nextState <= insertedCoinsTensAnode;
end case;
end process;

Functions are one option, as ravi has pointed out.
function f_segDisplay (
signal segCount : std_logic_vector(6 downto 0))
return std_logic_vector(3 downto 0) is
begin -- f_segDisplay
case segCount is
when "0000" => return "1111110"; --0
when "0001" => return "0110000"; --1
when "0010" => return "1101101"; --2
when "0011" => return "1111001"; --3
when "0100" => return "0110011"; --4
when "0101" => return "1011011"; --5
when "0110" => return "1011111"; --6
when "0111" => return "1110000"; --7
when "1000" => return "1111111"; --8
when others => return "1111011"; --9
end case;
end f_segDisplay;
process (currentState, tensCount, unitsCount)
begin
case currentState is
when requiredCoinsTensAnode =>
anodes <= "100000"; --turn on the tens display
segDisplay <= f_segDisplay(tensCount);
nextState <= requiredCoinsUnitsAnode;
when requiredCoinsUnitsAnode =>
anodes <= "010000"; --turn on the units display
segDisplay <= f_segDisplay(unitsCount);
nextState <= insertedCoinsTensAnode;
end case;
end process;
Depending on the compiler and options, it may decide to put the function code in-line. This would cause multiple instances of the logic to be placed, much like your original code.
An alternative is that you take the common code out into another process:
p_segdisplay : process (segCount)
begin -- process p_segdisplay
case segCount is
when "0000" => segDisplay <= "1111110"; --0
when "0001" => segDisplay <= "0110000"; --1
when "0010" => segDisplay <= "1101101"; --2
when "0011" => segDisplay <= "1111001"; --3
when "0100" => segDisplay <= "0110011"; --4
when "0101" => segDisplay <= "1011011"; --5
when "0110" => segDisplay <= "1011111"; --6
when "0111" => segDisplay <= "1110000"; --7
when "1000" => segDisplay <= "1111111"; --8
when others => segDisplay <= "1111011"; --9
end case;
end process p_segdisplay;
process (currentState, tensCount, unitsCount)
begin
case currentState is
when requiredCoinsTensAnode =>
anodes <= "100000"; --turn on the tens display
segCount <= tensCount;
nextState <= requiredCoinsUnitsAnode;
when requiredCoinsUnitsAnode =>
anodes <= "010000"; --turn on the units display
segCount <= unitsCount;
nextState <= insertedCoinsTensAnode;
end case;
end process;
BTW: You need tensCount and unitsCount in your sensitivity list.
Abstracting a common resource like this is a useful technique when doing area or power concious designs.
Both should work in the same way, and perfect tools would produce the same logic from the two, but we rarely have perfect tools. Experiment with different styles. Some produce better results on some tools, some on others.

Yes, you can use functions in VHDL.
check http://www.csee.umbc.edu/portal/help/VHDL/design.html#funcd
http://www.pldworld.com/_hdl/1/www.ireste.fr/fdl/vcl/lesd/les_3.htm

That code is probably best in a function or procedure.
An entity is another way to encapsulate code in VHDL.

Related

Is there a way to create a loop inside a case statement on vhdl?

I would like to know if there is a way to create a loop inside a case statement in vhdl.
Currently I have this code
CASE A1 IS
WHEN "00000" => RD1 <= REG0;
WHEN "00001" => RD1 <= REG1;
WHEN "00010" => RD1 <= REG2;
WHEN "00011" => RD1 <= REG3;
WHEN "00100" => RD1 <= REG4;
WHEN "00101" => RD1 <= REG5;
WHEN "00110" => RD1 <= REG6;
WHEN "00111" => RD1 <= REG7;
WHEN "01000" => RD1 <= REG8;
WHEN "01001" => RD1 <= REG9;
WHEN "01010" => RD1 <= REG10;
WHEN "01011" => RD1 <= REG11;
WHEN "01100" => RD1 <= REG12;
WHEN "01101" => RD1 <= REG13;
WHEN "01110" => RD1 <= REG14;
WHEN "01111" => RD1 <= REG15;
WHEN "10000" => RD1 <= REG16;
WHEN "10001" => RD1 <= REG17;
WHEN "10010" => RD1 <= REG18;
WHEN "10011" => RD1 <= REG19;
WHEN "10100" => RD1 <= REG20;
WHEN "10101" => RD1 <= REG21;
WHEN "10110" => RD1 <= REG22;
WHEN "10111" => RD1 <= REG23;
WHEN "11000" => RD1 <= REG24;
WHEN "11001" => RD1 <= REG25;
WHEN "11010" => RD1 <= REG26;
WHEN "11011" => RD1 <= REG27;
WHEN "11100" => RD1 <= REG28;
WHEN "11101" => RD1 <= REG29;
WHEN "11110" => RD1 <= REGZLO;
WHEN "11111" => RD1 <= REGZHI;
WHEN OTHERS => RD1 <= (OTHERS => '0');
END CASE;
As you can see the only thing that changes from one statement to the next is the number of the REG asigned to RD1. Couldn't the fact that it always matches the value of A1 (except on the last 2 cases but those can be done separately) be used to make a loop so that all the statements don't have to be written?
Thank you.
Is there a way to create a loop inside a case statement
No, you can not, at least not in the way I think you want to do it.
It would not make sense because if you can use a loop you can use the loop variable as selector/index or you can derive the value from it.
A case is intended for non-regular and/or sparse selection.
You can of course place a loop inside a case like this:
WHEN "01100" => for ...
But I am pretty sure that is not what you where referring to.
-- Why have 30 different signals when 1 will do?
type reg_a is array(0 to 29) of std_logic_vector(?? downto 0);
signal reg_s : reg_a;
-- Don't use a loop when you can just index into an array
if (unsigned(A1) < 30) then
RD1 <= reg_s(TO_INTEGER(unsigned(A1)));
else if (A1 = "11110") then
RD1 <= REGZLO;
else
RD1 <= REGZHI;
end if;

VHDL Morse Code Decoder - Parse Error, Unexpected Process, Expecting If

I'm working on a project for Digital Electronics in VHDL that consists of a button or paddle that takes an input from a user and converts that to an ASCII code output on a 17-segment display. My problem is that it is throwing the error Parse error, unexpected PROCESS, expecting IF even though my if statements should all have an END.
The error appears on the third to last line of the code below, where it reads
end process
This is for a Xilinx Coolrunner ii CPLD chip. I've already tried a bunch of different fixes from other solutions as well as running through my entire program and making sure the if statements I do have are closed. I have it localized (at least I think so) to the process below:
Checker: process(clock) begin
if(rising_edge(clock)) then
if(BTN_CNT = 1) then
case morse_code(0 downto 0) is
when "0" => LED_16SEGLETTER <= "00110000011111111"; --E
when "1" => LED_16SEGLETTER <= "00111111111011011"; --T
when others => LED_16SEGLETTER <= "00000000000000001"; --something rando
end case;
else if(BTN_CNT = 2) then
case morse_code(1 downto 0) is
when "00" => LED_16SEGLETTER <= "00110011111011011"; --I
when "01" => LED_16SEGLETTER <= "00001100001111111"; --A
when "10" => LED_16SEGLETTER <= "11001100110110111"; --N
when "11" => LED_16SEGLETTER <= "11001100110101111"; --M
when others => LED_16SEGLETTER <= "00000000000000001"; --something weird
end case;
else if(BTN_CNT = 3) then
case morse_code(2 downto 0) is
when "000" => LED_16SEGLETTER <= "00100010001111111"; --S
when "001" => LED_16SEGLETTER <= "11000000111111111"; --U
when "010" => LED_16SEGLETTER <= "00011100001110111"; --R
when "011" => LED_16SEGLETTER <= "11001100111110101"; --W
when "100" => LED_16SEGLETTER <= "00000011111011011"; --D
when "101" => LED_16SEGLETTER <= "11111100011100111"; --K
when "110" => LED_16SEGLETTER <= "00100000101111111"; --G
when "111" => LED_16SEGLETTER <= "00000000111111111"; --O
when others => LED_16SEGLETTER <= "00000000000000001"; --something weird
end case;
else if(BTN_CNT = 4) then
case morse_code(3 downto 0) is
when "0000" => LED_16SEGLETTER <= "11001100001111111"; --H
when "0001" => LED_16SEGLETTER <= "11111100111101101"; --V
when "0010" => LED_16SEGLETTER <= "00111100011111111"; --F
when "0100" => LED_16SEGLETTER <= "11110000111111111"; --L
when "0110" => LED_16SEGLETTER <= "00011100001111111"; --P
when "0111" => LED_16SEGLETTER <= "11000001111111111"; --J
when "1000" => LED_16SEGLETTER <= "00000011101011011"; --B
when "1001" => LED_16SEGLETTER <= "11111111110100101"; --X
when "1010" => LED_16SEGLETTER <= "00110000111111111"; --C
when "1011" => LED_16SEGLETTER <= "11011110001111011"; --Y
when "1100" => LED_16SEGLETTER <= "00110011111101101"; --Z
when "1101" => LED_16SEGLETTER <= "00000000111110111"; --Q
when others => LED_16SEGLETTER <= "00000000000000001"; --something weird
end case;
else if(BTN_CNT = 5)then
case morse_code(4 downto 0) is
when "11111" => LED_16SEGLETTER <= "00000000111101101"; --0
when "01111" => LED_16SEGLETTER <= "11001111111101111"; --1
when "00111" => LED_16SEGLETTER <= "00010001001111111"; --2
when "00011" => LED_16SEGLETTER <= "00000011101111111"; --3
when "00001" => LED_16SEGLETTER <= "11001110001111111"; --4
when "00000" => LED_16SEGLETTER <= "00100010001111111"; --5
when "10000" => LED_16SEGLETTER <= "01100000001111111"; --6
when "11000" => LED_16SEGLETTER <= "00001111111111111"; --7
when "11100" => LED_16SEGLETTER <= "00000000001111111"; --8
when "11110" => LED_16SEGLETTER <= "00000110001111111"; --9
when others => LED_16SEGLETTER <= "00000000000000001"; --something weird
end case;
else if(BTN_CNT = 6) then
case morse_code(5 downto 0) is
when "010101" => LED_16SEGLETTER <= "11111111111111110"; --FullStop
when "110011" => LED_16SEGLETTER <= "11111111111110111"; --Comma
when "001100" => LED_16SEGLETTER <= "00011111101111010"; --Query
when others => LED_16SEGLETTER <= "00000000000000001"; --something weird
end case;
else
LED_16SEGLETTER <= "00000000000000001";
end if;
end if;
end process;
end arc;
This process is supposed to find the correct 16-segment output for a specific dot/dash combination. This is hopefully the last thing I need to have done before the whole program can be implemented onto the CPLD.
As a footnote, I'm pretty sure I have all the syntax right at least for this process itself.
Replace all the statements in the code that have the tipe of:
else if(BTN_CNT = 2) then
with:
elsif(BTN_CNT = 2)
that is the correct statement. Well I had a similar problem and that´s the way I fixed.

" Error (10822): HDL error at pong_game.vhd(350): couldn't implement registers for assignments on this clock edge"

I have recently created a pong game in VHDL, the simulation looks pretty and the game behaves well. The game is a 1 vs 1. Each player has a a racket symbolized by two lit leds above and below the led matrix.
The ball is symbolized by lit leds scrolling at the ends of the led matrix and they have to be punched by the rackets displayed by two push buttons ( a left button and a right button for each player).
I'm using a cpld maxII equipped with a 50 Mhz clock. So i divided the frequency to control the scrolling of the leds.
After i have played many games with my little sister (she enjoyed it a lot :D), I decided make it funnier. The idea is to variate the frequency of the scrolling leds after 3,6,9,12,15 pushed balls. When the counter (named cnt_win) is below 3, the scrolling is slow and the frequency is increasing untill the cnt_win reaches 15. When one player fails the counter equals 0 ...
I use many clocks to variate the frequency and made the game more attracive but it doesn't work due to the error " Error (10822): HDL error at pong_game.vhd(350): couldn't implement registers for assignments on this clock edge".
library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity pong_game is
port(
d1 : in std_logic; -- right push button player 1
g1 : in std_logic; -- left push button player 1
d2 : in std_logic; -- " " player 2
g2 : in std_logic; -- " " player 2
clk_50Mhz : in std_logic;
clk_20hz : buffer std_logic :='0';
RST : in std_logic; -- reset button
leds : buffer std_logic_vector (30 downto 1);
led_barre_2 : buffer std_logic_vector (5 downto 1):="00011";
led_barre_1 : buffer std_logic_vector (5 downto 1):="00011"
);
end pong_game;
architecture pong_game_arch of pong_game is
constant position1 : std_logic_vector(5 downto 1) := "00011";
constant position2 : std_logic_vector(5 downto 1) := "00110";
constant position3 : std_logic_vector(5 downto 1) := "01100";
constant position4 : std_logic_vector(5 downto 1) := "11000";
type etat is (led1,led2,led3,led4,led5,led6_1,led7_1_g,led7_1_d,led8_1_g,led8_1_d,led9_1_g,led9_1_d,led10_1,led11_1,led12_1_g,led12_1_d,led13_1_g,led13_1_d,led14_1_g,led14_1_d,led15_1,
led16_1,led17_1_g,led17_1_d,led18_1_g,led18_1_d,led19_1_g,led19_1_d,led20_1,led21_1,led22_1_g,led22_1_d,led23_1_g,led23_1_d,led24_1_g,led24_1_d,led25_1,led26,led27,led28,led29,led30,
led6_2,led7_2_g,led7_2_d,led8_2_g,led8_2_d,led9_2_g,led9_2_d,led10_2,led11_2,led12_2_g,led12_2_d,led13_2_g,led13_2_d,led14_2_g,led14_2_d,led15_2,led16_2,led17_2_g,led17_2_d,led18_2_g,led18_2_d,led19_2_g,led19_2_d,
led20_2,led21_2,led22_2_g,led22_2_d,led23_2_g,led23_2_d,led24_2_g,led24_2_d,led25_2,
led6_init,
led7_init,
led8_init,
led9_init,
led10_init,
led11_init_1,
led11_init_2,
led12_init_1,
led12_init_2,
led13_init_1,
led13_init_2,
led14_init_1,
led14_init_2,
led15_init_1,
led15_init_2, -- Sequence led initiale
led16_init_1,
led16_init_2,
led17_init_1,
led17_init_2,
led18_init_1,
led18_init_2,
led19_init_1,
led19_init_2,
led20_init_1,
led20_init_2,
led21_init,
led22_init,
led23_init,
led24_init,
led25_init,
all_led_loose_on,
all_led_loose_off);
signal etat_present, etat_futur : etat :=led11_init_1; -- etat initial
signal cnt : integer range 11 to 20 :=11; -- Permet de choisir quelle led initial
signal cnt1 : integer range 3 downto 0 :=0; -- gère les positions de led_barre_1
signal cnt2 : integer range 3 downto 0 :=0; -- idem pour led_barre_2
--signal clk_20hz : std_logic :='0'; -- gère les boutons poussoirs gauche-droite
--------- gère les sequences de leds avec 4 signals d'horloge -----------
signal clk_0 : std_logic :='0'; -- niveau lent
signal clk_1 : std_logic :='0'; -- niveau normal
signal clk_2 : std_logic :='0'; -- niveau rapide
signal clk_3 : std_logic :='0'; -- niveau très rapide
signal cnt_clk_20 : std_logic_vector (22 downto 1):= (others=>'0');
signal cnt_clk_0 : std_logic_vector (25 downto 1):= (others=>'0');
signal cnt_clk_1 : std_logic_vector (24 downto 1):= (others=>'0');
signal cnt_clk_2 : std_logic_vector (24 downto 1):= (others=>'0');
signal cnt_clk_3 : std_logic_vector (24 downto 1):= (others=>'0');
--------------------------------------------------------------------------------
-------- choix binaire des fréquences de défilements --------------------------
constant lent : std_logic_vector (1 downto 0) :="00";
constant normal : std_logic_vector (1 downto 0) :="01";
constant rapide : std_logic_vector (1 downto 0) :="10";
constant rapide_v : std_logic_vector (1 downto 0) :="11";
signal choix : std_logic_vector (1 downto 0) :=lent;
signal cnt_win : integer range 15 downto 0 :=0;
begin
diviseur_clk : process(clk_50Mhz)
begin
if rising_edge(clk_50Mhz) then
if cnt_clk_0 < "1011111010111100001000000" then --25.000.000
cnt_clk_0 <= cnt_clk_0+'1';
else
clk_0<=not(clk_0);
cnt_clk_0<= (others => '0');
end if;
if cnt_clk_1 < "111001001110000111000000" then --15.000.000
cnt_clk_1<=cnt_clk_1+'1';
else
clk_1<=not(clk_1);
cnt_clk_1<= (others =>'0');
end if;
if cnt_clk_2 < "100110001001011010000000" then --10.000.000
cnt_clk_2<=cnt_clk_2+'1';
else
clk_2<=not(clk_2);
cnt_clk_2<= (others=>'0');
end if;
if cnt_clk_3 < "11100100111000011100000" then --7.500.000
cnt_clk_3 <= cnt_clk_3+'1';
else
clk_3<=not(clk_3);
cnt_clk_3<= (others=>'0');
end if;
if cnt_clk_20 < "1001100010010110100000" then --2.500.000
cnt_clk_20<=cnt_clk_20+'1';
else
clk_20hz<=not(clk_20hz);
cnt_clk_20<= (others =>'0');
end if;
end if;-- rising_edge
end process diviseur_clk ;
position_1 : process (clk_20hz,d1,g1)
begin
if rising_edge(clk_20hz) then
case cnt1 is
when 0=>
if d1='1' and g1='0' then
led_barre_1<="00110";
cnt1<=1;
end if;
when 1=>
if d1='1' and g1='0' then
led_barre_1<="01100";
cnt1<=2;
elsif d1='0' and g1='1' then
led_barre_1<="00011";
cnt1<=0;
end if;
when 2=>
if d1='1' and g1='0' then
led_barre_1<="11000";
cnt1<=3;
elsif d1='0' and g1='1' then
led_barre_1<="00110";
cnt1<=1;
end if;
when 3 =>
if d1='0' and g1='1' then
led_barre_1<="01100";
cnt1<=2;
end if;
when others =>
end case;
end if;
end process position_1;
position_2 : process (clk_20hz,d2,g2)
begin
if rising_edge(clk_20hz) then
case cnt2 is
when 0=>
if d2='1' and g2='0' then
led_barre_2<="00110";
cnt2<=1;
end if;
when 1=>
if d2='1' and g2='0' then
led_barre_2<="01100";
cnt2<=2;
elsif d2='0' and g2='1' then
led_barre_2<="00011";
cnt2<=0;
end if;
when 2=>
if d2='1' and g2='0' then
led_barre_2<="11000";
cnt2<=3;
elsif d2='0' and g2='1' then
led_barre_2<="00110";
cnt2<=1;
end if;
when 3 =>
if d2='0' and g2='1' then
led_barre_2<="01100";
cnt2<=2;
end if;
when others =>
end case;
end if;
end process position_2;
--end architecture pong_game_arch;
--architecture led_matrix of pong_game is
compteur : process(clk_50Mhz)
begin
if rising_edge(clk_50Mhz) then
if cnt < 20 then
cnt<= cnt+1;
else
cnt<=11;
end if;
end if;
end process compteur ;
initialisation : process(RST,clk_0,clk_1,clk_2,clk_3)
begin
if RST='1' then
case cnt is
when 11 => etat_present <= led11_init_1;
when 12 => etat_present <= led12_init_1;
when 13 => etat_present <= led13_init_1;
when 14 => etat_present <= led14_init_1;
when 15 => etat_present <= led15_init_1;
when 16 => etat_present <= led16_init_2;
when 17 => etat_present <= led17_init_2;
when 18 => etat_present <= led18_init_2;
when 19 => etat_present <= led19_init_2;
when 20 => etat_present <= led20_init_2;
end case ;
else
case choix is
when lent => -- choice of the
-- frequency (the error
-- occurs here )
if rising_edge(clk_0) then
etat_present <= etat_futur;
end if;
when normal =>
if rising_edge(clk_1) then
etat_present <= etat_futur;
end if;
when rapide =>
if rising_edge(clk_2) then
etat_present <= etat_futur;
end if;
when rapide_v =>
if rising_edge(clk_3) then
etat_present <= etat_futur;
end if;
end case ;
end if;
end process initialisation ;
sequence_led : process(etat_present,led_barre_1,led_barre_2)
begin
case etat_present is
-- sequence initiale
when led6_init =>
etat_futur <= led1;
when led7_init =>
etat_futur <= led2;
when led8_init =>
etat_futur <= led3;
when led9_init =>
etat_futur <= led4;
when led10_init =>
etat_futur <= led5;
when led11_init_2 =>
etat_futur <= led6_init;
when led12_init_2 =>
etat_futur <= led7_init;
when led13_init_2 =>
etat_futur <= led8_init;
when led14_init_2 =>
etat_futur <= led9_init;
when led15_init_2 =>
etat_futur <= led10_init;
when led16_init_2 =>
etat_futur <= led11_init_2;
when led17_init_2 =>
etat_futur <= led12_init_2;
when led18_init_2 =>
etat_futur <= led13_init_2;
when led19_init_2 =>
etat_futur <= led14_init_2;
when led20_init_2 =>
etat_futur <= led15_init_2;
when led11_init_1 =>
etat_futur <= led16_init_1;
when led12_init_1 =>
etat_futur <= led17_init_1;
when led13_init_1 =>
etat_futur <= led18_init_1;
when led14_init_1 =>
etat_futur <= led19_init_1;
when led15_init_1 =>
etat_futur <= led20_init_1;
when led16_init_1 =>
etat_futur <= led21_init;
when led17_init_1 =>
etat_futur <= led22_init;
when led18_init_1 =>
etat_futur <= led23_init;
when led19_init_1 =>
etat_futur <= led24_init;
when led20_init_1 =>
etat_futur <= led25_init;
when led21_init =>
etat_futur <= led26;
when led22_init =>
etat_futur <= led27;
when led23_init =>
etat_futur <= led28;
when led24_init =>
etat_futur <= led29;
when led25_init =>
etat_futur <= led30;
-- fin sequence initiale
when led1 =>
if led_barre_1 = position1 then
etat_futur <= led7_1_d;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led2 =>
if led_barre_1 = position1 then
etat_futur <= led8_1_d;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
elsif led_barre_1 = position2 then
etat_futur <= led6_1;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led3 =>
if led_barre_1 = position2 then
etat_futur <= led9_1_d;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
elsif led_barre_1 = position3 then
etat_futur <= led7_1_g;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led4 =>
if led_barre_1 = position3 then
etat_futur <= led10_1;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
elsif led_barre_1 = position4 then
etat_futur <= led8_1_g;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led5=>
if led_barre_1 = position4 then
etat_futur <= led9_1_g;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur<= all_led_loose_on;
cnt_win <= 0;
end if;
when led6_1=>
etat_futur <= led12_1_d;
when led6_2=>
etat_futur <= led2;
when led7_1_g =>
etat_futur <= led11_1;
when led7_1_d=>
etat_futur <= led13_1_d;
when led7_2_g =>
etat_futur <= led1;
when led7_2_d =>
etat_futur <= led3;
when led8_1_g =>
etat_futur <= led12_1_g;
when led8_1_d =>
etat_futur <= led14_1_d;
when led8_2_g =>
etat_futur <= led2;
when led8_2_d =>
etat_futur <= led4;
when led9_1_g =>
etat_futur <= led13_1_g;
when led9_1_d =>
etat_futur <= led15_1;
when led9_2_g =>
etat_futur <= led3;
when led9_2_d =>
etat_futur <= led5;
when led10_1 =>
etat_futur <= led14_1_g;
when led10_2 =>
etat_futur <= led4;
when led11_1 =>
etat_futur <= led17_1_d;
when led11_2 =>
etat_futur <= led7_2_d;
when led12_1_g =>
etat_futur <= led16_1;
when led12_1_d =>
etat_futur <= led18_1_d;
when led12_2_g =>
etat_futur <= led6_2;
when led12_2_d =>
etat_futur <= led8_2_d;
when led13_1_g =>
etat_futur <= led17_1_g;
when led13_1_d =>
etat_futur <= led19_1_d;
when led13_2_g =>
etat_futur <= led7_2_g;
when led13_2_d =>
etat_futur <= led9_2_d;
when led14_1_g =>
etat_futur <= led18_1_g;
when led14_1_d =>
etat_futur <= led20_1;
when led14_2_g =>
etat_futur <= led8_2_g;
when led14_2_d =>
etat_futur <= led10_2;
when led15_1 =>
etat_futur <= led19_1_g;
when led15_2 =>
etat_futur <= led9_2_g;
when led16_1 =>
etat_futur <= led22_1_d;
when led16_2 =>
etat_futur <= led12_2_d;
when led17_1_g =>
etat_futur <= led21_1;
when led17_1_d =>
etat_futur <= led23_1_d;
when led17_2_g =>
etat_futur <= led11_2;
when led17_2_d =>
etat_futur <= led13_2_d;
when led18_1_g =>
etat_futur <= led22_1_g;
when led18_1_d =>
etat_futur <= led24_1_d;
when led18_2_g =>
etat_futur <= led12_2_g;
when led18_2_d=>
etat_futur <= led14_2_d;
when led19_1_g =>
etat_futur <= led23_1_g;
when led19_1_d =>
etat_futur <= led25_1;
when led19_2_g =>
etat_futur <= led13_2_g;
when led19_2_d =>
etat_futur <= led15_2;
when led20_1 =>
etat_futur <= led24_1_g;
when led20_2 =>
etat_futur <= led14_2_g;
when led21_1 =>
etat_futur <= led27;
when led21_2 =>
etat_futur <= led17_2_d;
when led22_1_g =>
etat_futur <= led26;
when led22_1_d=>
etat_futur <= led28;
when led22_2_g =>
etat_futur <= led16_2;
when led22_2_d=>
etat_futur <= led18_2_d;
when led23_1_g =>
etat_futur <= led27;
when led23_1_d =>
etat_futur <= led29;
when led23_2_g =>
etat_futur <= led17_2_g;
when led23_2_d =>
etat_futur <= led19_2_d;
when led24_1_g =>
etat_futur <= led28;
when led24_1_d =>
etat_futur <= led30;
when led24_2_g =>
etat_futur <= led18_2_g;
when led24_2_d =>
etat_futur <= led20_2;
when led25_1 =>
etat_futur <= led29;
when led25_2 =>
etat_futur <= led19_2_g;
when led26 =>
if led_barre_2=position1 then
etat_futur<=led22_2_d;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else --loose
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led27 =>
if led_barre_2=position1 then
etat_futur<=led23_2_d;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
elsif led_barre_2=position2 then
etat_futur<=led21_2;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else --loose
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led28 =>
if led_barre_2=position2 then
etat_futur <= led24_2_d;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
elsif led_barre_2=position3 then
etat_futur <= led22_2_g;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led29 =>
if led_barre_2 = position4 then
etat_futur <= led23_2_g;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
elsif led_barre_2 = position3 then
etat_futur <= led25_2;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when led30 =>
if led_barre_2 = position4 then
etat_futur <= led24_2_g;
if cnt_win < 15 then
cnt_win <= cnt_win + 1;
end if;
else
etat_futur <= all_led_loose_on;
cnt_win <= 0;
end if;
when all_led_loose_on => -- cycle entre ces deux états
etat_futur <= all_led_loose_off; -- jusqu'à ce que RST = '1'
when all_led_loose_off =>
etat_futur <= all_led_loose_on;
end case ;
end process sequence_led ;
affichage_sequence : process(etat_present)
begin
case etat_present is
when led1 =>
leds <= ( 1 => '1', others => '0');
when led2 =>
leds <= ( 2 => '1', others => '0');
when led3 =>
leds <= ( 3 => '1', others => '0');
when led4 =>
leds <= ( 4 => '1', others => '0');
when led5=>
leds <= ( 5 => '1', others => '0');
when led6_1|led6_2|led6_init=>
leds <= ( 6 => '1', others => '0');
when led7_1_d|led7_1_g|led7_2_d|led7_2_g|led7_init =>
leds <= ( 7 => '1', others => '0');
when led8_1_d|led8_1_g|led8_2_d|led8_2_g|led8_init =>
leds <= ( 8 => '1', others => '0');
when led9_1_d|led9_1_g|led9_2_d|led9_2_g|led9_init =>
leds <= ( 9 => '1', others => '0');
when led10_1|led10_2|led10_init =>
leds <= ( 10 => '1', others => '0');
when led11_1|led11_2|led11_init_1|led11_init_2 =>
leds <= ( 11 => '1', others => '0');
when led12_1_g|led12_1_d|led12_2_g|led12_2_d|led12_init_1|led12_init_2 =>
leds <= ( 12 => '1', others => '0');
when led13_1_g|led13_1_d|led13_2_g|led13_2_d|led13_init_1|led13_init_2 =>
leds <= ( 13 => '1', others => '0');
when led14_1_d|led14_1_g|led14_2_g|led14_2_d|led14_init_1|led14_init_2 =>
leds <= ( 14 => '1', others => '0');
when led15_1|led15_2|led15_init_1|led15_init_2 =>
leds <= ( 15 => '1', others => '0');
when led16_1|led16_2|led16_init_1|led16_init_2 =>
leds <= ( 16 => '1', others => '0');
when led17_1_g|led17_1_d|led17_2_g|led17_2_d|led17_init_1|led17_init_2 =>
leds <= ( 17 => '1', others => '0');
when led18_1_g|led18_1_d|led18_2_g|led18_2_d|led18_init_1|led18_init_2 =>
leds <= ( 18 => '1', others => '0');
when led19_1_g|led19_1_d|led19_2_g|led19_2_d|led19_init_1|led19_init_2 =>
leds <= ( 19 => '1', others => '0');
when led20_1|led20_2|led20_init_1|led20_init_2 =>
leds <= ( 20 => '1', others => '0');
when led21_1|led21_2|led21_init =>
leds <= ( 21 => '1', others => '0');
when led22_1_g|led22_1_d|led22_2_g|led22_2_d|led22_init =>
leds <= ( 22 => '1', others => '0');
when led23_1_g|led23_1_d|led23_2_g|led23_2_d|led23_init =>
leds <= ( 23 => '1', others => '0');
when led24_1_g|led24_1_d|led24_2_g|led24_2_d|led24_init =>
leds <= ( 24 => '1', others => '0');
when led25_1|led25_2|led25_init =>
leds <= ( 25 => '1', others => '0');
when led26 =>
leds <= ( 26 => '1', others => '0');
when led27 =>
leds <= ( 27 => '1', others => '0');
when led28 =>
leds <= ( 28 => '1', others => '0');
when led29 =>
leds <= ( 29 => '1', others => '0');
when led30 =>
leds <= ( 30 => '1', others => '0');
when all_led_loose_on =>
leds <= (others =>'1');
when all_led_loose_off =>
leds <= (others =>'0');
end case ;
end process affichage_sequence ;
variation_frequence : process (cnt_win)
begin
case cnt_win is
when 0|1|2|3 => choix <= lent ;
when 4|5|6 => choix <= normal ;
when 7|8|9 => choix <= rapide ;
when 10|11|12 => choix <= normal ;
when 13|14|15 => choix <= rapide_v;
end case;
end process variation_frequence ;
end architecture pong_game_arch;
The error occurs at the process "initialisation".
Besides what user1155120 used said in his comment you also did a very bad thing (unless you're doing ASICs) which is clock gating. You should not derive clocks from combinatorial logic. Only clock sources such as clock pins and PLLs. In my opinion the best way to change the code is to do a rising edge detection on the signals (don't call them clocks) clk_0, clk_1, clk_2 and clk_3. Use these "rising edges" in your if statements (lines 351, 359, 367 and 375). The main problem with this approach is you're adding at least one latency cycle to the flow which might or might not impact your final output. You have to adjust for this somehow.

Case statement error message in VHDL

Hello can somebody help me with something thats been bugging me for a while. I have a simple case statement and to the best of my knowledge the syntax is good. see the below code
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
ENTITY D7SEGSEL IS
PORT (
SW :in std_logic_vector(3 DOWNTO 0);
SEG :out std_logic_vector(6 DOWNTO 0)
);
END ENTITY D7SEGSEL;
ARCHITECTURE behavioral OF D7SEGSEL IS
BEGIN
CASE SW IS
WHEN "1000000" => SEG <= "0000";
"1111001" => SEG <= "0001";
"0100100" => SEG <= "0010";
"0110000" => SEG <= "0011";
"0011001" => SEG <= "0100";
"0010010" => SEG <= "0101";
"0000010" => SEG <= "0110";
"1111000" => SEG <= "0111";
"0000000" => SEG <= "1000";
"0011000" => SEG <= "1001";
"0001000" => SEG <= "1010";
"0000011" => SEG <= "1011";
"1000110" => SEG <= "1100";
"0100001" => SEG <= "1101";
"0000110" => SEG <= "1110";
"0001110" => SEG <= "1111";
END CASE;
END ARCHITECTURE behavioral;
its for a simple 7SEG LED driver, each time i compile the code though I get the following error messages:
Error (10500): VHDL syntax error at D7SEGCASE.vhd(19) near text
"CASE"; expecting "end", or "(", or an identifier ("case" is a
reserved keyword), or a concurrent statement
Error (10500): VHDL syntax error at D7SEGCASE.vhd(21) near text "=>"; expecting > "(", or
"'", or "."
Can anyone point out the obvious in what I'm doing wrong
I have already made a decoder for the 7seg with a select/when statement but want to practice the use of case and then make it synchronous with the addition of a clock input
You have a few problems.
You are missing your process statement.
You are missing subsequent "when" after your first condition.
You have reversed your condition and your assignment in your WHEN conditions.
See fixes below:
ARCHITECTURE behavioral OF D7SEGSEL IS
BEGIN
my_case : process(sw, seg)
begin
CASE SW IS
WHEN "0000" => SEG <= "1000000";
WHEN "0001" => SEG <= "1111001";
-- Other Assignments follow...
END CASE;
end process my_case;
END ARCHITECTURE behavioral;
As pointed out by others, there are some problems with your code, but luckily there are different options to implement what you want.
Case (process)
process (SW) is
begin
case SW is
when "0000" => SEG <= "1000000";
when "0001" => SEG <= "1111001";
when "0010" => SEG <= "0100100";
when "0011" => SEG <= "0110000";
when "0100" => SEG <= "0011001";
when "0101" => SEG <= "0010010";
when "0110" => SEG <= "0000010";
when "0111" => SEG <= "1111000";
when "1000" => SEG <= "0000000";
when "1001" => SEG <= "0011000";
when "1010" => SEG <= "0001000";
when "1011" => SEG <= "0000011";
when "1100" => SEG <= "1000110";
when "1101" => SEG <= "0100001";
when "1110" => SEG <= "0000110";
when "1111" => SEG <= "0001110";
when others => SEG <= (others => 'X');
end case;
end process;
When (concurrent)
SEG <= "1000000" when SW = "0000" else
"1111001" when SW = "0001" else
"0100100" when SW = "0010" else
"0110000" when SW = "0011" else
"0011001" when SW = "0100" else
"0010010" when SW = "0101" else
"0000010" when SW = "0110" else
"1111000" when SW = "0111" else
"0000000" when SW = "1000" else
"0011000" when SW = "1001" else
"0001000" when SW = "1010" else
"0000011" when SW = "1011" else
"1000110" when SW = "1100" else
"0100001" when SW = "1101" else
"0000110" when SW = "1110" else
"0001110" when SW = "1111" else
(others => 'X');
Select (concurrent)
d7seg : with SW select
SEG <= "1000000" when "0000",
"1111001" when "0001",
"0100100" when "0010",
"0110000" when "0011",
"0011001" when "0100",
"0010010" when "0101",
"0000010" when "0110",
"1111000" when "0111",
"0000000" when "1000",
"0011000" when "1001",
"0001000" when "1010",
"0000011" when "1011",
"1000110" when "1100",
"0100001" when "1101",
"0000110" when "1110",
"0001110" when "1111",
(others => 'X') when others;
The Select (concurrent) is compact and with few repetitions, and is likely to yield a small implementation, so will be a good choice.
I can't see process in your code.
process(sw,seg)
.
.
.
end process
check if you get after adding it

How to resolve this coding error

Here is my code for writing two decimal numbers on 7 segment. I have used AN0 and AN1. I am getting this really weird error I don't know how to resolve it, is there any problem with my case structure? What does this error mean? any help would be appreciated
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity twosegments is
Port ( clk : in STD_LOGIC;
dig0: in std_logic_vector (3 downto 0);
dig1: in STD_LOGIC_VECTOR (3 downto 0);
segment : out STD_LOGIC_VECTOR (6 downto 0);
anode : out STD_LOGIC_VECTOR (3 downto 0));
end twosegments;
architecture Behavioral of twosegments is
constant prescaler: STD_LOGIC_VECTOR(16 downto 0) := "00000000110010000";
signal prescaler_counter: STD_LOGIC_VECTOR(16 downto 0) := (others => '0');
signal sel: STD_LOGIC_VECTOR (1 downto 0);
signal r_anode: STD_LOGIC_VECTOR (3 downto 0);
begin
anode <= r_anode;
process (clk) begin
if (clk'event and clk = '1') then
prescaler_counter <= prescaler_counter + 1;
if(prescaler_counter = prescaler) then
sel <= sel+1;
prescaler_counter <= (others => '0');
end if;
end if;
end process;
process (sel, dig0,dig1) begin
case sel is
when "00" => r_anode <= "1110";
when "01" => r_anode <= "1101";
--when "10" => r_anode <= "1110";
--when "11" => r_anode <= "1101";
when others => r_anode <= "1111";
end case;
case r_anode is
when "1110" => case "dig0" is
when "0000" => segment <= "0000001"; --0
when "0001" => segment <= "1001111"; --1
when "0010" => segment <= "0010010"; --2
when "0011" => segment <= "0000110"; --3
when "0100" => segment <= "1001100"; --4
when "0101" => segment <= "0100100"; --5
when "0110" => segment <= "0100000"; --6
when "0111" => segment <= "0001111"; --7
when "1000" => segment <= "0000000"; --8
when "1001" => segment <= "0000100"; --9
when others => segment <= "1111111";
end case;
when "1101" => case "dig1" is
when "0000" => segment <= "0000001"; --0
when "0001" => segment <= "1001111"; --1
when "0010" => segment <= "0010010"; --2
when "0011" => segment <= "0000110"; --3
when "0100" => segment <= "1001100"; --4
when "0101" => segment <= "0100100"; --5
when "0110" => segment <= "0100000"; --6
when "0111" => segment <= "0001111"; --7
when "1000" => segment <= "0000000"; --8
when "1001" => segment <= "0000100"; --9
when others => segment <= "1111111"; --off
end case;
when others => segment <= "1111111";
end case;
end process;
end Behavioral;
This is the weird error
FATAL_ERROR:HDLParsers:vhpcstr.c:2040:$Id: vhpcstr.c,v 1.64 2008/12/03 00:28:13 sandeepd Exp $:200 - INTERNAL ERROR... while parsing "E:/Xilinx Projects/twosegs/twosegments.vhd" line 62. Contact your hot line. Process will terminate. For technical support on this issue, please open a WebCase with this project attached at http://www.xilinx.com/support.
There is a syntax error with quotes around dig0 and dig1 signal identifiers, so try to change case "dig0" is to case dig0 is, and case "dig1" is to case dig1 is.
But anyway, the Xilinx parser is not robust enough since it crashes, so it is a good habit to create a WebCase for issues like this, so Xilinx can improve in the future.
I would follow the error message directions. Specifically:
For technical support on this issue, please open a WebCase with this
project attached at http://www.xilinx.com/support

Resources