EmbDev.net

Forum: FPGA, VHDL & Verilog VHDL error when else


von Hareesh M. (Company: Mindteck) (hareeshp)


Rate this post
useful
not useful
hi,
1
 library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
entity req is
5
  port(fpga_clk: in std_logic;
6
      evt_pwr_en: in std_logic;
7
      ifc_we_n : inout std_logic;
8
      hreset_n : inout std_logic;
9
      pwr_rst_n :  in std_logic;
10
      ifc_ad8_15 : inout std_logic_vector( 7 downto 0);
11
      sensevdd_en_n : out std_logic;
12
      iopwr_en : out std_logic;
13
      iopwr_en_n : out std_logic;
14
      ddrpwr_en : out std_logic;
15
      ddrpwr_en_n : out std_logic;  
16
      vdd_en : out std_logic;
17
      vdd_en_n : out std_logic;
18
      vcore_en : out std_logic;
19
      evt_pwr_ok : out std_logic;
20
      v3v3_pgood: in std_logic);
21
end req;
22
architecture power of req is
23
signal tier_cnt: std_logic_vector(19 downto 0);
24
signal tier_cnt_int:std_logic;
25
signal tier : std_logic_vector(3 downto 0);
26
signal vcore_en_cnt: std_logic_vector(9 downto 0);
27
signal pwr_gd_cnt : std_logic_vector(19 downto 0);
28
signal pwr_ok_cnt:  std_logic_vector(19 downto 0);
29
signal rst_holf_f : std_logic;
30
signal req_rst_r : std_logic;
31
signal req_cop_trst_r  : std_logic;
32
signal cfg_egn_use0 : std_logic;
33
signal cpu_rst_n : std_logic;
34
signal pwr_rst_cnt : std_logic_vector(9 downto 0);
35
signal rcw_config_word : std_logic_vector( 7 downto 0);
36
begin
37
38
pon_rst_n <= (pwr_rst_n  when pwr_ok_cnt(19) = '1' else '1') when v3v3_pgood and pwr_gd_cnt(19) = '1' else pwr_rst_n;
39
40
process(tier_cnt_int)
41
begin
42
  if(rising_edge(tier_cnt_int)) then
43
    if(v3v3_pgood = '0') then
44
      tier_cnt(3 downto 0)  <= "1111";
45
    else
46
      tier(3) <= tier(2);
47
      tier(2) <= tier(1);
48
      tier(1) <= tier(0);
49
      tier(0) <= evt_pwr_en;
50
    end if;
51
  end if;
52
end process;
53
54
process(fpga_clk) 
55
begin
56
  if(rising_edge(fpga_clk)) then
57
    if(v3v3_pgood = '0') then
58
      vcore_en_cnt <= (others => '0');
59
    else
60
      if(vcore_en_cnt > "0110000000") then
61
        vcore_en_cnt <= "1111111111";
62
      else
63
        vcore_en_cnt <= vcore_en_cnt + 1;
64
      end if;
65
    end if;
66
  end if;
67
end process;
68
process(fpga_clk) 
69
begin
70
  if(rising_edge(fpga_clk)) then
71
    if(v3v3_pgood = '0') then
72
      pwr_gd_cnt <= (others => '0');
73
    else
74
      if(pwr_gd_cnt > x"08000") then
75
        pwr_gd_cnt <= (others => '1');
76
      else
77
        pwr_gd_cnt <= pwr_gd_cnt + 1;
78
      end if;
79
    end if;
80
  end if;
81
end process;
82
83
process(fpga_clk) 
84
begin
85
  if(rising_edge (fpga_clk)) then
86
    if( (not(cpu_rst_n) or (rst_holf_f) or (hreset_n and (not(req_rst_r)) and req_cop_trst_r  ))= '1') then
87
      cfg_egn_use0 <= ifc_we_n;
88
    end if;
89
  end if;
90
end process;
91
92
process(fpga_clk)
93
begin
94
  if(rising_edge(fpga_clk)) then
95
    if(pwr_rst_n = '0') then
96
      rcw_config_word <= ifc_ad8_15;
97
    end if;
98
  end if;
99
end process;  
100
end power;

the code above shows an error like

Error (10500): VHDL syntax error at req.vhd(38) near text "when"; 
expecting ")", or ","

von user (Guest)


Rate this post
useful
not useful
because for when statement there is no (), here is an example:

a <= '1' when c = '1' else
     '0' when d = '1' else
     '0';

von Hareesh M. (Company: Mindteck) (hareeshp)


Rate this post
useful
not useful
user wrote:
> because for when statement there is no (), here is an example:
>
> a <= '1' when c = '1' else
>      '0' when d = '1' else
>      '0';

actually in the above code, pon_rst_n will be pwr_rst_n based on the 
value of v3v3_pgood and pwr_gd_cnt(19). But before assignment i have to 
check pwr_rst_n based on the values of pwr_ok_cnt(19).

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Hareesh M. wrote:
> the code above shows an error like
A hint: use your text editor to format and indent your code. Then you 
see such things very easy...
1
pon_rst_n <= (pwr_rst_n  when pwr_ok_cnt(19) = '1'                  else
2
             '1')        when v3v3_pgood and pwr_gd_cnt(19) = '1'   else
3
             pwr_rst_n;
Easy to see: one useless '(' in the first line and one wrong ')' in the 
second line...

And this is almost unreadable:
1
    if( (not(cpu_rst_n) or (rst_holf_f) or (hreset_n and (not(req_rst_r)) and req_cop_trst_r  ))= '1') then
Are you sure it is doing what you want?
I could write it this way:
1
    if  cpu_rst_n='0'  or
2
        rst_holf_f='1' or
3
        hreset_n='1' and req_rst_r='0' and req_cop_trst_r='1' then
In my opinion now everybody recogizes what he will get with one short 
blink...

: Edited by Moderator
von Hareesh M. (Company: Mindteck) (hareeshp)


Rate this post
useful
not useful
Lothar M. wrote:
> Hareesh M. wrote:
>> the code above shows an error like
> A hint: use your text editor to format and indent your code. Then you
> see such things very easy...
>
1
> pon_rst_n <= (pwr_rst_n  when pwr_ok_cnt(19) = '1'                  else
2
>              '1')        when v3v3_pgood and pwr_gd_cnt(19) = '1'   else
3
>              pwr_rst_n;
4
>
>
> And this is almost unreadable:
>
1
>     if( (not(cpu_rst_n) or (rst_holf_f) or (hreset_n and 
2
> (not(req_rst_r)) and req_cop_trst_r  ))= '1') then
3
>
> Are you sure it is doing what you want?
> I could write it this way:
>
1
>     if  cpu_rst_n='0'  or
2
>         rst_holf_f='1' or
3
>         hreset_n='1' and req_rst_r='0' and req_cop_trst_r='1' then
4
>
> In my opinion now everybody recogizes what he will get with one short
> blink...

i corrected the when else statement error, but now it is showing 
"v3v3_pgood" does not agree with "boolean" type.

and thanks for you help that "if" statement.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Hareesh M. wrote:
> i corrected the when else statement error, but now it is showing
> "v3v3_pgood" does not agree with "boolean" type.
Try this:
1
pon_rst_n <= pwr_rst_n  when pwr_ok_cnt(19)='1'                      else
2
             '1'        when v3v3_pgood='1' and pwr_gd_cnt(19)='1'   else
3
             pwr_rst_n;

Hareesh M. wrote:
> but now it is showing "v3v3_pgood" does not agree with "boolean" type.
Please start thinking for yourself about those messages before 
posting. Usually such errors are easy to locate...
We solved this "problem" about different types (std_logic ist not 
boolean) a few days ago. Do you remember?

: Edited by Moderator
von Hareesh M. (Company: Mindteck) (hareeshp)


Rate this post
useful
not useful
hi,
i still have some issue with when else statement,
1
 ifc_ad8_15 <= "ZZZZZZZZ" when cpu_rst_n and (not rst_hold_f) and (req_rst_r when (req_md_r = "11") else '1') = '1' 
2
          else rcw_src(0 to 7) when boot_override_r = '1' else "ZZZZZZZZ";

showing the same error
Error (10500): VHDL syntax error at req.vhd(556) near text "when"; 
expecting ")", or ","
Error (10500): VHDL syntax error at req.vhd(556) near text ")"; 
expecting ";"

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Get all the parenthesis right and correct the logical problems leading 
to syntax problems, then it will be ok.

See, what I wrote in the post before your last (that about "start 
thinking yourself" and remind the comment about "readability" of code). 
It will help to solve that problem...

: Edited by Moderator
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.