Forum Discussion
Altera_Forum
Honored Contributor
11 years ago --- Quote Start --- CAn you post the full code. Your snippet has all sorts of type errors. --- Quote End --- yes below is the entire code library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use IEEE.math_real.all; -- for UNIFORM, TRUNC functions USE ieee.numeric_std.ALL; -- for TO_UNSIGNED function use ieee.STD_LOGIC_UNSIGNED.all; use ieee.std_logic_textio.all; entity ADwgn is port ( diginp:in std_logic_vector(11 downto 0); digiop:out std_logic_vector(11 downto 0); x:inout integer; result:out std_logic_vector(11 downto 0); lo_val:out integer ); end; architecture a of ADwgn is subtype unsigned is integer range 0 to 255; signal y1,R,y: unsigned := 0; signal rst_n: std_logic:='1'; signal N: integer:=12; signal middle: integer:=0; signal c:real; signal rand_wave: std_logic_vector(11 downto 0); signal rand: integer:=0; signal mean: integer:=1; signal variance:integer:= 2; begin process(rst_n) variable RandomVal : real ; variable DataSent : integer ; -- Random integer value in range 0..256 -- Declare seeds and initialize -- Uniform uses seeds as state information, -- so initialize only once variable DataSent_seed1 : positive := 7 ; -- Seed values for random generator variable DataSent_seed2 : positive := 1 ; VARIABLE stim: std_logic_vector(11 DOWNTO 0); -- Random 12-bit stimulus begin if rst_n='0' then x<=0; elsif rst_n='1' then for i in 1 to 10 loop -- Generate a value between 0.0 and 1.0 (non-inclusive) uniform(DataSent_seed1, DataSent_seed2, RandomVal) ; -- Convert to integer in range of 0 to 255 DataSent := integer(trunc(RandomVal*256.0)) ; stim := std_logic_vector(to_unsigned(DataSent, stim'LENGTH)); -- convert to std_logic_vector lo_val<=i; end loop; x<=unsigned(DataSent); --tmp_a<= x; y<=N/2; y1<=(x-y); -- set mean to 0 PROBLEM WITH CODE AT THIS LINE result<=stim; rst_n<='0'; middle<= (12/N); c<=sqrt(real(middle)); --rand<=unsigned(real(x)*c); -- PROBLEM ARISES HERE ALSO --R<=integer(rand); -- rand_wave<=std_logic_vector(to_unsigned(R,rand_wave'LENGTH)) ; -- adjust variance to 1 -- rand_wave<=std_logic_vector(to_unsigned(x, rand_wave'LENGTH)) end if; digiop<=diginp xor stim; --x' <= mean + (sqrt(real(variance)) * x) end process; end; --When the algorithm finishes, X will be our unit normal random. --X can be further modified to have a particular mean and variance, e.g.: Thanks