-- VHDL -- (C) 2000 by M. Thole -- This entity is the interface to architectures calculating -- iterations for a given complex point of the z plane (re, im) ENTITY fractal IS GENERIC ( itmax : INTEGER := 10; -- Max iteration rad: REAL := 4.0 -- Radius of convergence ); PORT ( inx, iny : in REAL; outp : out integer ); END ENTITY fractal; -- This architecture calculates the mandelbrot iteration for a given -- complex point of the z plane (re, im) ARCHITECTURE mandel OF fractal is FUNCTION iterate( re: REAL; im: REAL; itmax: INTEGER; rad: REAL) RETURN INTEGER IS VARIABLE i: INTEGER; VARIABLE xnew, ynew, x, y, xq: REAL; BEGIN i := 0; x := 0.0; y := 0.0; -- check, if initialization phase (Hack!?)!! -- if re = real'left then -- return 0; -- end if; WHILE (i < itmax) AND (x*x + y*y < rad) LOOP xnew := x*x - y * y + re; ynew := 2.0 * x * y + im; x := xnew; y := ynew; i := i+1; END LOOP; RETURN i; END; BEGIN outp <= iterate(inx, iny, itmax, rad); END mandel; ------------------------------------------------------------------------ -- testbench ------------------------------------------------------------------------ entity frac_digital_test is generic ( res : integer := 31); end frac_digital_test; architecture test of frac_digital_test is type integer_vector is array (natural range <>) of integer; type real_vector is array (natural range <>) of real; component fractal GENERIC ( itmax : INTEGER := 10; -- Max iteration rad: REAL := 4.0 -- Radius of convergence ); port ( inx, iny : in REAL; outp : out integer ); end component; signal x : real := 0.0; signal y : real_vector(0 to res) := (others => 0.0); signal oi : integer_vector(0 to res); begin -- test fi: for i in oi'range generate fr : fractal port map ( inx => x, iny => y(i), outp => oi(i)); end generate fi; process begin for i in oi'range loop y(i) <= -1.5+(real(i)/(real(res)/3.0)); end loop; -- i wait; end process; process begin for i in oi'range loop x <= -2.25+(real(i)/(real(res)/3.0)); wait for 1 ns; end loop; -- i wait; end process; end test; ------------------------------------------------------------------------ -- Configuration ------------------------------------------------------------------------ configuration frac_conf of frac_digital_test is for test end for; end frac_conf;