Hello
I have problems, Namely I don't know why my function isn't acting. I wanted to write function, which will execute translation of types real to std_logic_vector. I did two arrays which between them compares and result I get variable std_logic_vector but I don't know why " if(pay_extra = pay_real(i))" don't works, when pay_extra = 0.1 to 1.0.
this is function and arrays:
and call function this way:
pay_extra_out<=To_StdLogicVector(przelicz(abs(money-pay)));
where example: money = 2.0 and pay = 1.8 ;
Thanks for help
BTW.I am apologizing for my meager language
I have problems, Namely I don't know why my function isn't acting. I wanted to write function, which will execute translation of types real to std_logic_vector. I did two arrays which between them compares and result I get variable std_logic_vector but I don't know why " if(pay_extra = pay_real(i))" don't works, when pay_extra = 0.1 to 1.0.
this is function and arrays:
Code:
-----------------------------------------------------
function przelicz(var: real) return bit_vector is
variable mon: bit_vector(4 downto 0);
begin
for i in pay_bit'range loop
if(var=pay_real(i))
then mon:= pay_bit(i);
end if;
end loop;
return mon;
end;
-----------------------------------------------------
type tab_pay_bit is array(positive range<>) of bit_vector(4 downto 0);
constant pay_bit : tab_pay_bit :=(
"00000", --0.0
"00001", --0.1
"00010", --0.2
"00011", --0.3
"00100", --0.4
"00101", --0.5
"00110", --0.6
"00111", --0.7
"01000", --0.8
"01001", --0.9
"01010", --1.0
"01011", --1.1
"01100", --1.2
"01101", --1.3
"01110", --1.4
"01111", --1.5
"10000", --1.6
"10001", --1.7
"10010", --1.8
"10011", --1.9
"11000" --2.0
);
type tab_pay_real is array(positive range<>) of Real;
constant pay_real : tab_pay_real(1 to 21) :=(
0.0,
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.7,
0.8,
0.9,
1.0,
1.1,
1.2,
1.3,
1.4,
1.5,
1.6,
1.7,
1.8,
1.9,
2.0
);
-----------------------------------------------------
-----------------------------------------------------
and call function this way:
pay_extra_out<=To_StdLogicVector(przelicz(abs(money-pay)));
where example: money = 2.0 and pay = 1.8 ;
Thanks for help
BTW.I am apologizing for my meager language