error with if generate

Guest #3634020
Rate this post
• ▲ useful
▼ not useful
Hi all,

I got some errors when I try to compile the following code:
1
library IEEE;
2
use IEEE.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
use IEEE.std_logic_unsigned.all;
5

6
library peb_lib;
7
use peb_lib.all;
8

9
entity adc_simu is
10
     
11
  port(  CLK     : in  std_logic;
12
    MODE    : in real;
13
    OF_out  : out std_logic; -- OF pin
14
    D       : out std_logic_vector(13 downto 0)
15
      );
16
    
17
end adc_simu;
18

19
architecture archi of adc_simu is  
20

21
component adc
22

23
  generic (RefH, RefL: real;
24
     VDD: real);
25
     
26
  port(  Ain_pos : in real;
27
    Ain_neg : in  real;
28
    CLK     : in  std_logic;
29
    MODE    : in real;
30
    OF_out  : out std_logic; -- OF pin
31
    D       : out std_logic_vector(13 downto 0)
32
      );
33
    
34
end component;
35

36
component square_generator
37

38
  generic(LOW  : real;
39
    HIGH : real);
40
  
41
  port(wave: out real);
42
  
43
end component;
44

45
component triangle_generator
46

47
  generic(AMP: real;
48
    OFFSET: real;
49
    FREQ: real;
50
    PHASE :real);
51
  
52
  port(wave: out real);
53
  
54
end component;
55

56
component sinus_generator
57

58
  generic(AMP    : real;
59
    OFFSET : real;
60
    FREQ   : real;
61
    PHASE  : real);
62

63
  port(sinus: out real);
64
  
65
end component;
66

67
component sawtooth_generator
68

69
  generic(AMP: real;
70
    OFFSET: real;
71
    FREQ: real;
72
    PHASE : real);
73
  
74
  port(sawtooth: out real);
75

76
end component;
77

78
signal plus: real;
79
signal moins: real;
80

81
type waveform is (sinus, triangle, sawtooth, square);
82

83
signal wave_type: waveform := sinus;
84

85
begin
86

87
  TRI:if wave_type = triangle generate
88
              Vplus: triangle_generator 
89
                     generic map (AMP => 1.0,
90
                                  OFFSET => 1.5,
91
                                  FREQ => 100000.0,
92
                                  PHASE => 0.0)
93
                              
94
                     port map (plus);
95
          
96
               Vmoins: triangle_generator
97
                     generic map (AMP => 1.0,
98
                                  OFFSET => 1.5,
99
                                  FREQ => 100000.0,
100
                                  PHASE => 180.0)
101
          
102
                     port map (moins);
103

104
  end generate TRI;
105
      
106
  SQ:if wave_type = square generate
107
               Vplus: square_generator
108
                     generic map (LOW => 1.0,
109
                                  HIGH => 0.000122)    
110

111
                     port map (plus);
112
              
113
               Vmoins: square_generator
114
                      generic map (LOW => 0.000122,
115
                                   HIGH => 0.000244)
116
  
117
                     port map (moins);
118

119
  end generate SQ;
120

121
  SIN: if wave_type = sinus generate
122
                Vplus: sinus_generator
123
                      generic map (AMP => 1.0,
124
                                   OFFSET => 1.5,
125
                                   FREQ => 10000000.0,
126
                                   PHASE => 0.0)
127
             
128
                      port map (plus);
129
  
130
                Vmoins: sinus_generator
131
                      generic map (AMP => 1.0,
132
                                   OFFSET => 1.5,
133
                                   FREQ => 10000000.0,
134
                                   PHASE => 180.0)                  
135
                             
136
                       port map (moins);
137
  
138
  end generate SIN;
139
  
140
  SAW: if wave_type = sawtooth generate
141
                 Vplus: sawtooth_generator
142
                      generic map (AMP => 3.3,
143
                                   OFFSET => 1.65,
144
                                   FREQ => 10000000.0,
145
                                   PHASE => 0.0)
146
        
147
                      port map (plus);
148

149
                 Vmoins: sawtooth_generator
150
                      generic map (AMP => 3.3,
151
                                   OFFSET => 1.65,
152
                                   FREQ => 10000000.0,
153
                                   PHASE => 180.0)
154
             
155
                      port map (moins);
156
  
157
  end generate SAW;
158
       
159
  CAN: adc generic map (RefH => 1.0, RefL => -1.0, VDD => 3.3)
160
  
161
           port map (plus, moins, CLK, MODE, OF_out, D);
162
    
163
end archi;

Errors are:

../RTL/adc_simu.vhdl:
        TRI:            if wave_type = triangle generate
                                   |
ncvhdl_p: *E,ILSGRD (../RTL/adc_simu.vhdl,92|18): illegal reference of a 
signal (WAVE_TYPE) during static elaboration [12.3].
        SQ:             if wave_type = square generate
                                   |
ncvhdl_p: *E,ILSGRD (../RTL/adc_simu.vhdl,102|17): illegal reference of 
a signal (WAVE_TYPE) during static elaboration [12.3].
        SIN:            if wave_type = sinus generate
                                   |
ncvhdl_p: *E,ILSGRD (../RTL/adc_simu.vhdl,112|18): illegal reference of 
a signal (WAVE_TYPE) during static elaboration [12.3].
        SAW:            if wave_type = sawtooth generate
                                   |
ncvhdl_p: *E,ILSGRD (../RTL/adc_simu.vhdl,122|18): illegal reference of 
a signal (WAVE_TYPE) during static elaboration [12.3].

Can you tell me what is wrong in my code please!
Guest #3634068
Rate this post
• ▲ useful
▼ not useful
bob wrote:
> type waveform is (sinus, triangle, sawtooth, square);
>
> signal wave_type: waveform := sinus;

For the condition in your "if...generate" construct you have to use a 
generic or a constant, because both are static values when you are doing 
a synthesis or the simulator compiles your sources.

bob wrote:
> ncvhdl_p: *E,ILSGRD (../RTL/adc_simu.vhdl,122|18): illegal reference of
> a signal (WAVE_TYPE) during static elaboration [12.3].

Read: "You are giving me a signal to decide what I should do, but a 
signal is some thing dynamic and I have to do a static (permanent) 
decision."
Guest #3634177
Rate this post
• ▲ useful
▼ not useful
bob wrote:
> So, if I understand right I have to remplace the type waveform by a
> integer or generic type in the condition?

No. You don't have to replace the type. You can use any type and all the 
types you created yourself.

bob wrote:
> signal wave_type: waveform := sinus;

You have to chance wave_type, you can't use a signal here. You have to 
use a generic (defined in the entity) or in this case simply replace the 
word "signal" with "constant".
Moderator (Company: Titel) #3634181
Rate this post
• ▲ useful
▼ not useful
bob wrote:
> So, if I understand right I have to remplace the type waveform by a
> integer or generic type in the condition?
You understood him wrong. I'm not sure if it works, but try this:
1
constant wave_type: waveform := sinus;

Or try a generic (but then you will have to define a package with your 
data type and include that in your entity)...

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.