【发布时间】:2014-03-15 00:00:57
【问题描述】:
问题
我正在一个包中编写一个函数,它为测试台转换一些值。我想检查输出是否超过最大值,如果是,我想将其设置为该最大值。我累的是以下几点:
-- vec_in: 0...1023, returns -14...23.5 dB
function conv_dac602_scale (
vec_in : std_logic_vector)
return real is
variable val_in, dB : real := 0.0;
constant lower : real := -14.0;
constant upper : real := 23.5;
begin -- function conv_dac602_scale
val_in := real(to_integer(unsigned(vec_in)));
dB := (lower+(val_in*((upper-lower)/1024.0)));
return dB when dB <= upper else upper; -- this is the important line! (129)
end function conv_dac602_scale;
当我尝试编译时,出现以下错误:
** Error: myfile.vhd(129): near "when": expecting ';'
** Error: myfile.vhd(260): VHDL Compiler exiting
然后我尝试先将其分配给变量 r:
...
r := dB when dB <= upper else upper; -- this is the important line! (129)
return r;
end function conv_dac602_scale;
这并没有改变结果。我知道我可以改用简单的if/else 子句,但我的问题是为什么我不能使用when 子句。
系统
Modelsim SE 10.0b,VHDL 2008
【问题讨论】: