Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Fatal error VHDL

Status
Not open for further replies.

Kgonz

Newbie level 5
Joined
Mar 9, 2023
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
221
Hi im pretty knew to VHDL and im trying to simulate the code that i wrote for an SPI master but when i go to wave simulations in model sim the most important waveforms dont show up MOSI, MISO, and SS. the only reason that i see that they might not be appearing is because i receive a fatal error warning
"Fatal error in Process line__36 at C:/questasim_2019.1/examples/SPI_practice.vhd line 58 # "

however im not sure what issue its having with line 58

Ive attached a copy of my code and the TB

Code for SPI Master

Code:
library ieee;

use ieee.std_logic_1164.all;



entity fsm_spi is

port( clk, rst, rd_enable, miso: in std_logic;

mosi, ss, sclk: out std_logic );

end entity;



architecture logic_flow of fsm_spi is

type state is (st_idle, st0_txRead, st1_txAddress,

st2_rxData);

signal present_state, next_state: state;

signal data_read: std_logic_vector(7 downto 0) ;

constant read1 : std_logic_vector(7 downto 0)   :="11101100";

constant address: std_logic_vector(23 downto 0) :="110101101101011011010110";

constant max_length: natural:=24;

signal data_index: natural range 0 to max_length -1;

signal timer: natural range 0 to max_length-1;

begin



process(clk, rst)

begin

    if (rst='1') then

        present_state<= st_idle;

        data_index <= 0;

    elsif (clk'event and clk='0') then

    if(data_index=timer-1) then

        present_state<=next_state;

        data_index <=0;

    else

        data_index <= data_index +1;

    end if;

     end if;

end process;



process(present_state, rd_enable, data_index)

begin

    case present_state is

        when st_idle =>

        ss<='1';

        sclk<='0';

        mosi<='X';

        timer<=1;

    if(rd_enable ='1') then

        next_state<= st0_txRead;

    else

        next_state<= st_idle;

    end if;

    when st0_txRead =>

        ss<='0';

        sclk<=clk;

        timer<=8;

        mosi<= read1(7- data_index);

        next_state<= st1_txAddress;

    when st1_txAddress =>

        ss<='0';

        sclk<=clk;

        timer<=24;

        mosi<= address(23- data_index);

        next_state<= st2_rxData;

    when st2_rxData =>

        ss<='0';

        sclk<=clk;

        timer<=8;

        data_read(7- data_index) <= miso;

        next_state<= st_idle;

    end case;



end process;



end logic_flow;

SPI Master TB

Code:
library IEEE;
use IEEE.Std_logic_1164.all;
entity fsm_spi_tb is
end fsm_spi_tb;

architecture bench of fsm_spi_tb is

component fsm_spi
        port(clk, rst, rd_enable,miso: in std_logic;
             mosi, ss, sclk : out std_logic );
end component;

signal clk, rst, rd_enable: std_logic;
signal mosi, ss, sclk,miso: std_logic ;
constant clock_period: time := 10 ns;
signal stop_the_clock: boolean;

begin
pm : entity work.fsm_spi
port map (clk => clk,
rst => rst,
rd_enable => rd_enable,
mosi => mosi,
ss => ss,
sclk => sclk,
miso => miso);

process -- stimulus
begin
rst<='1';
wait for clock_period;
rst<='0';
rd_enable<='1';
wait for clock_period;
wait for clock_period*32;
rd_enable<='0';
stop_the_clock<=true;
wait;
end process;

process -- clock generation
begin
while not stop_the_clock loop
clk <= '0';
wait for clock_period / 2;
clk <= '1';
wait for clock_period / 2;
end loop;
wait;


end process;
end;
 
Last edited by a moderator:

You don’t show any line numbers, so it’s hard to see where your error is
 

SPI MASTER Code
  1. Code:
    library ieee;
    [*]use ieee.std_logic_1164.all;
    [*]
    
    [*]entity fsm_spi is
    [*]port( clk, rst, rd_enable, miso: in std_logic;
    [*]mosi, ss, sclk: out std_logic );
    [*]end entity;
    [*]
    
    [*]architecture logic_flow of fsm_spi is
    [*]type state is (st_idle, st0_txRead, st1_txAddress,
    [*]st2_rxData);
    [*]signal present_state, next_state: state;
    [*]signal data_read: std_logic_vector(7 downto 0) ;
    [*]constant read1 : std_logic_vector(7 downto 0)   :="11101100";
    [*]constant address: std_logic_vector(23 downto 0) :="110101101101011011010110";
    [*]constant max_length: natural:=24;
    [*]signal data_index: natural range 0 to max_length -1;
    [*]signal timer: natural range 0 to max_length-1;
    [*]begin
    [*]
    
    [*]process(clk, rst)
    [*]begin
    [*]    if (rst='1') then
    [*]        present_state<= st_idle;
    [*]        data_index <= 0;
    [*]    elsif (clk'event and clk='0') then
    [*]    if(data_index=timer-1) then
    [*]        present_state<=next_state;
    [*]        data_index <=0;
    [*]    else
    [*]        data_index <= data_index +1;
    [*]    end if;
    [*]     end if;
    [*]end process;
    [*]
    
    [*]process(present_state, rd_enable, data_index)
    [*]begin
    [*]    case present_state is
    [*]        when st_idle =>
    [*]        ss<='1';
    [*]        sclk<='0';
    [*]        mosi<='X';
    [*]        timer<=1;
    [*]    if(rd_enable ='1') then
    [*]        next_state<= st0_txRead;
    [*]    else
    [*]        next_state<= st_idle;
    [*]    end if;
    [*]    when st0_txRead =>
    [*]        ss<='0';
    [*]        sclk<=clk;
    [*]        timer<=8;
    [*]        mosi<= read1(7- data_index);
    [*]        next_state<= st1_txAddress;
    [*]    when st1_txAddress =>
    [*]        ss<='0';
    [*]        sclk<=clk;
    [*]        timer<=24;
    [*]        mosi<= address(23- data_index);
    [*]        next_state<= st2_rxData;
    [*]    when st2_rxData =>
    [*]        ss<='0';
    [*]        sclk<=clk;
    [*]        timer<=8;
    [*]        data_read(7- data_index) <= miso;
    [*]        next_state<= st_idle;
    [*]    end case;
    [*]
    
    [*]end process;
    [*]
    
    [*]end logic_flow;

SPI Master TB

  1. Code:
    library IEEE;
    [*]use IEEE.Std_logic_1164.all;
    [*]entity fsm_spi_tb is
    [*]end fsm_spi_tb;
    [*]
    
    [*]architecture bench of fsm_spi_tb is
    [*]
    
    [*]component fsm_spi
    [*]        port(clk, rst, rd_enable,miso: in std_logic;
    [*]             mosi, ss, sclk : out std_logic );
    [*]end component;
    [*]
    
    [*]signal clk, rst, rd_enable: std_logic;
    [*]signal mosi, ss, sclk,miso: std_logic ;
    [*]constant clock_period: time := 10 ns;
    [*]signal stop_the_clock: boolean;
    [*]
    
    [*]begin
    [*]pm : entity work.fsm_spi
    [*]port map (clk => clk,
    [*]rst => rst,
    [*]rd_enable => rd_enable,
    [*]mosi => mosi,
    [*]ss => ss,
    [*]sclk => sclk,
    [*]miso => miso);
    [*]
    
    [*]process -- stimulus
    [*]begin
    [*]rst<='1';
    [*]wait for clock_period;
    [*]rst<='0';
    [*]rd_enable<='1';
    [*]wait for clock_period;
    [*]wait for clock_period*32;
    [*]rd_enable<='0';
    [*]stop_the_clock<=true;
    [*]wait;
    [*]end process;
    [*]
    
    [*]process -- clock generation
    [*]begin
    [*]while not stop_the_clock loop
    [*]clk <= '0';
    [*]wait for clock_period / 2;
    [*]clk <= '1';
    [*]wait for clock_period / 2;
    [*]end loop;
    [*]wait;
    [*]
    
    [*]
    
    [*]end process;
    [*]end;
 

SPI Master Module


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
library ieee;
use ieee.std_logic_1164.all;
entity fsm_spi is
port( clk, rst, rd_enable, miso: in std_logic;
mosi, ss, sclk: out std_logic );
end entity;
 
architecture logic_flow of fsm_spi is
type state is (st_idle, st0_txRead, st1_txAddress,
st2_rxData);
signal present_state, next_state: state;
signal data_read: std_logic_vector(7 downto 0) ;
constant read1 : std_logic_vector(7 downto 0)   :="11101100";
constant address: std_logic_vector(23 downto 0) :="110101101101011011010110";
constant max_length: natural:=24;
signal data_index: natural range 0 to max_length -1;
signal timer: natural range 0 to max_length-1;
begin
 
process(clk, rst)
begin
    if (rst='1') then
        present_state<= st_idle;
        data_index <= 0;
    elsif (clk'event and clk='0') then
    if(data_index=timer-1) then
        present_state<=next_state;
        data_index <=0;
    else
        data_index <= data_index +1;
    end if;
     end if;
end process;
 
process(present_state, rd_enable, data_index)
begin
    case present_state is
        when st_idle =>
        ss<='1';
        sclk<='0';
        mosi<='X';
        timer<=1;
    if(rd_enable ='1') then
        next_state<= st0_txRead;
    else
        next_state<= st_idle;
    end if;
    when st0_txRead =>
        ss<='0';
        sclk<=clk;
        timer<=8;
        mosi<= read1(7- data_index);
        next_state<= st1_txAddress;
    when st1_txAddress =>
        ss<='0';
        sclk<=clk;
        timer<=24;
        mosi<= address(23- data_index);
        next_state<= st2_rxData;
    when st2_rxData =>
        ss<='0';
        sclk<=clk;
        timer<=8;
        data_read(7- data_index) <= miso;
        next_state<= st_idle;
    end case;
 
end process;
 
end logic_flow;




SPI Master TB


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
ibrary IEEE;
use IEEE.Std_logic_1164.all;
entity fsm_spi_tb is
end fsm_spi_tb;
 
architecture bench of fsm_spi_tb is
component fsm_spi
port(clk, rst, rd_enable,miso: in std_logic;
mosi, ss, sclk : out std_logic );
end component;
 
signal clk, rst, rd_enable: std_logic;
signal mosi, ss, sclk,miso: std_logic ;
constant clock_period: time := 10 ns;
signal stop_the_clock: boolean;
 
begin
pm : entity work.fsm_spi
port map (clk => clk,
rst => rst,
rd_enable => rd_enable,
mosi => mosi,
ss => ss,
sclk => sclk,
miso => miso);
 
process -- stimulus
begin
rst<='1';
wait for clock_period;
rst<='0';
rd_enable<='1';
wait for clock_period;
wait for clock_period*32;
rd_enable<='0';
stop_the_clock<=true;
wait;
end process;
 
process -- clock generation
begin
while not stop_the_clock loop
clk <= '0';
wait for clock_period / 2;
clk <= '1';
wait for clock_period / 2;
end loop;
wait;
 
end process;
end;



[MODERATOR ACTION]
Added SYNTAX formatting to code
 
Last edited by a moderator:

You did not tell when the error occurs. Is it during compilation, simulation start or run? Usually the simulator gives more information about the fatal error.
 

SPI Master Module

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. entity fsm_spi is
  4. port( clk, rst, rd_enable, miso: in std_logic;
  5. mosi, ss, sclk: out std_logic );
  6. end entity;

  7. architecture logic_flow of fsm_spi is
  8. type state is (st_idle, st0_txRead, st1_txAddress,
  9. st2_rxData);
  10. signal present_state, next_state: state;
  11. signal data_read: std_logic_vector(7 downto 0) ;
  12. constant read1 : std_logic_vector(7 downto 0) :="11101100";
  13. constant address: std_logic_vector(23 downto 0) :="110101101101011011010110";
  14. constant max_length: natural:=24;
  15. signal data_index: natural range 0 to max_length -1;
  16. signal timer: natural range 0 to max_length-1;
  17. begin

  18. process(clk, rst)
  19. begin
  20. if (rst='1') then
  21. present_state<= st_idle;
  22. data_index <= 0;
  23. elsif (clk'event and clk='0') then
  24. if(data_index=timer-1) then
  25. present_state<=next_state;
  26. data_index <=0;
  27. else
  28. data_index <= data_index +1;
  29. end if;
  30. end if;
  31. end process;

  32. process(present_state, rd_enable, data_index)
  33. begin
  34. case present_state is
  35. when st_idle =>
  36. ss<='1';
  37. sclk<='0';
  38. mosi<='X';
  39. timer<=1;
  40. if(rd_enable ='1') then
  41. next_state<= st0_txRead;
  42. else
  43. next_state<= st_idle;
  44. end if;
  45. when st0_txRead =>
  46. ss<='0';
  47. sclk<=clk;
  48. timer<=8;
  49. mosi<= read1(7- data_index);
  50. next_state<= st1_txAddress;
  51. when st1_txAddress =>
  52. ss<='0';
  53. sclk<=clk;
  54. timer<=24;
  55. mosi<= address(23- data_index);
  56. next_state<= st2_rxData;
  57. when st2_rxData =>
  58. ss<='0';
  59. sclk<=clk;
  60. timer<=8;
  61. data_read(7- data_index) <= miso;
  62. next_state<= st_idle;
  63. end case;

  64. end process;

  65. end logic_flow;


SPI Master TB

  1. library IEEE;
  2. use IEEE.Std_logic_1164.all;
  3. entity fsm_spi_tb is
  4. end fsm_spi_tb;

  5. architecture bench of fsm_spi_tb is

  6. component fsm_spi
  7. port(clk, rst, rd_enable,miso: in std_logic;
  8. mosi, ss, sclk : out std_logic );
  9. end component;

  10. signal clk, rst, rd_enable: std_logic;
  11. signal mosi, ss, sclk,miso: std_logic ;
  12. constant clock_period: time := 10 ns;
  13. signal stop_the_clock: boolean;

  14. begin
  15. pm : entity work.fsm_spi
  16. port map (clk => clk,
  17. rst => rst,
  18. rd_enable => rd_enable,
  19. mosi => mosi,
  20. ss => ss,
  21. sclk => sclk,
  22. miso => miso);

  23. process -- stimulus
  24. begin
  25. rst<='1';
  26. wait for clock_period;
  27. rst<='0';
  28. rd_enable<='1';
  29. wait for clock_period;
  30. wait for clock_period*32;
  31. rd_enable<='0';
  32. stop_the_clock<=true;
  33. wait;
  34. end process;

  35. process -- clock generation
  36. begin
  37. while not stop_the_clock loop
  38. clk <= '0';
  39. wait for clock_period / 2;
  40. clk <= '1';
  41. wait for clock_period / 2;
  42. end loop;
  43. wait;


  44. end process;
  45. end;
There doesn't appear to be anything wrong with line 58, or any nearby lines. We need more information.
 

Ive attched a picture of the error message i get during compilation and also what my waveforms come out to look like. ive tried looking for a way to manually insert the MOSI, MISO wave forms but i couldn't find anything

Screenshot 2023-04-04 061724.png


Screenshot 2023-04-04 061949.png
 

You are assigning 24 to an integer with range 0 to 23.
 

why isnt the value zero included as an integer as well? there are 24 values in the range of zero to 23 right?
--- Updated ---

why isnt the value zero included as an integer as well? there are 24 values in the range of zero to 23 right?
Also might you know the reason that my MOSI, MISO and SS lines dont appear in sim is there a manual way to put them in maybe?
 

Your signal 'timer' is of type natural and you have defined the value of it to be within range of 0 to 23. So the compiler shows an error when you are assigning the value 24 to it. Line 58.
It is not about how many values, but about what value.
Please analyze what you have written yourself!
 

why isnt the value zero included as an integer as well? there are 24 values in the range of zero to 23 right?
--- Updated ---


Also might you know the reason that my MOSI, MISO and SS lines dont appear in sim is there a manual way to put them in maybe?
add wave /fsm_spi_tb/mosi
add wave /fsm_spi_tb/miso
add wave /fsm_spi_tb/ss
restart -f
run 100 ns
 

Hi,

'timer' has a range of 0 to 23. 23 is the highest value and so 'timer' cannot be 24. Note that there are 24 counts in 0...23, with 0 being the first and 23 being the 24th. If want to assign the 24th count, then that value will be 23. However, if you want to have 24 counts and expressly show the 24th count as 24, then you would have to changer the range of 'timer' to "1 to 24".
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top