Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Behavioral but synthesizable implementation of IIR filters in VHDL

371 views
Skip to first unread message

wzab

unread,
Apr 2, 2011, 1:00:48 PM4/2/11
to
Archive-name: iir-fphdl
Submitted-by: wz...@ise.pw.edu.pl (Wojciech M. Zabolotny)

Attached sources implement the IIR filters in VHDL.
The filters are described with behavioral code, but they are
also suitable for synthesis.
Two versions of filters are provided. In the iir_fphdl_sstep
all calculations are done in a single step, so design is really
resources hungry.
In the iir_fphdl_mstep the output value of the filter is calculated
in a few clock cycles (defined by "nsteps"). Therefore the same
multiplier may be used for different calculations in consecutive
clock cycles.

The archive contains my files, which are PUBLIC DOMAIN
and one file which is redistributed under GPL license (fmod.vhd).

To run simulation of filters with GHDL ( http://ghdl.free.fr )
you should create a directory, then donwload and unpack
http://www.vhdl.org/fphdl/vhdl2008c.zip in this directory
and unpack archive with my sources.
To get vhdl2008c compiled with GHDL you should set the write permission
to fixed_pkg_c.vhdl and add the marked line near to begining of the file:

|library IEEE_PROPOSED;
|use IEEE_PROPOSED.fixed_float_types.all;
|use ieee_proposed.math_real_fmod.all; -- <== This line must be added !
|
|package fixed_pkg is

Then run the "comp.sh" script to compile VHDL2008 compatibility library
After that you may run the "filter_test.m" file in Octave, which performs
simulation of the same filter in Octave, and in GHDL - in "single step"
and "multiple steps" configurations. Finally the vim is used to display
step responses of all filters.
In the "filter_test.m" you can modify the parameters of the simulated
filter.
You can also watch the generated ghw files with gtkwave to see
how filters work.

If you want to test synthesis, you should dowmnload and unpack somewhere
http://www.vhdl.org/fphdl/xilinx_11.zip sources.

For synthesis I've used the following sources (contents of the .prj file)

For "multiple steps" configuration:
vhdl ieee_proposed "../fphdl/fixed_float_types_c.vhdl"
vhdl ieee_proposed "../fphdl/fixed_pkg_c.vhdl"
vhdl work "../fixed_prec.vhd"
vhdl work "../iir_fphdl_pkg.vhd"
vhdl work "../iir_fphdl_mstep.vhd"
vhdl work "../filtdef.vhd"
vhdl work "../iir_top_mstep.vhd"

For "single step" configuration:
vhdl ieee_proposed "../fphdl/fixed_float_types_c.vhdl"
vhdl ieee_proposed "../fphdl/fixed_pkg_c.vhdl"
vhdl work "../fixed_prec.vhd"
vhdl work "../iir_fphdl_pkg.vhd"
vhdl work "../iir_fphdl_sstep.vhd"
vhdl work "../filtdef.vhd"
vhdl work "../iir_top_sstep.vhd"

Plese try to synthesize filter defined currently in filter_test.m
into 3s250eft256 device and into 3s500eft256 device to see the difference
between both implementations...

Of course the proposed implementation of IIR filters is far from optimal.
In fact it would be much better to implement them in cascade or parallel
form...

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.9).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `#!/bin/sh' line above, then type `sh FILE'.
#
lock_dir=_sh05039
# Made on 2011-04-02 18:56 CEST by <wzab@wzab>.
# Source directory was `/tmp/send'.
#
# Existing files will *not* be overwritten, unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 380 -rwxr--r-- comp.sh
# 2070 -rwxr--r-- filter_test.m
# 919 -rw-r--r-- fmod.vhd
# 4269 -rw-r--r-- iir_fphdl_mstep.vhd
# 949 -rw-r--r-- iir_fphdl_pkg.vhd
# 1927 -rw-r--r-- iir_fphdl_sstep.vhd
# 3609 -rw-r--r-- iir_tb_mstep.vhd
# 2935 -rw-r--r-- iir_tb_sstep.vhd
# 1865 -rw-r--r-- iir_top_mstep.vhd
# 1739 -rw-r--r-- iir_top_sstep.vhd
# 598 -rw-r--r-- makefile_mstep
# 583 -rw-rw-r-- makefile_sstep
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir ;;
esac
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and
installing GNU `touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir} ; then :
else ${echo} "lock directory ${lock_dir} exists"
exit 1
fi
if mkdir ${lock_dir}
then ${echo} "x - created lock directory ${lock_dir}."
else ${echo} "x - failed to create lock directory ${lock_dir}."
exit 1
fi
# ============= comp.sh ==============
if test -f 'comp.sh' && test "$first_param" != -c; then
${echo} "x - SKIPPING comp.sh (file already exists)"
else
${echo} "x - extracting comp.sh (text)"
sed 's/^X//' << 'SHAR_EOF' > 'comp.sh' &&
#!/bin/bash
mkdir ip
COMP="ghdl -a --std=93c --ieee=standard --workdir=ip --work=ieee_proposed "
$COMP fmod.vhd
$COMP fixed_float_types_c.vhdl
$COMP fixed_pkg_c.vhdl
$COMP float_pkg_c.vhdl
$COMP numeric_std_additions.vhdl
$COMP numeric_std_unsigned_c.vhdl
$COMP standard_additions_c.vhdl
$COMP standard_textio_additions_c.vhdl
$COMP std_logic_1164_additions.vhdl
$COMP env_c.vhdl
SHAR_EOF
(set 20 11 04 02 14 59 47 'comp.sh'
eval "${shar_touch}") && \
chmod 0744 'comp.sh'
if test $? -ne 0
then ${echo} "restore of comp.sh failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'comp.sh': 'MD5 check failed'
) << \SHAR_EOF
4b2651241fc15115403b7b6b1dc2192c comp.sh
SHAR_EOF
else
test `LC_ALL=C wc -c < 'comp.sh'` -ne 380 && \
${echo} "restoration warning: size of 'comp.sh' is not 380"
fi
fi
# ============= filter_test.m ==============
if test -f 'filter_test.m' && test "$first_param" != -c; then
${echo} "x - SKIPPING filter_test.m (file already exists)"
else
${echo} "x - extracting filter_test.m (text)"
sed 's/^X//' << 'SHAR_EOF' > 'filter_test.m' &&
#!/usr/bin/octave
% Public domain script written by Wojciech M. Zabolotny
% wz...@ise.pw.edu.pl
% To show simulation of IIR filters implemented in VHDL
%
% Generate the filter
%[b,a]=cheby1(6,0.5,0.2);
[b,a]=cheby1(7,0.5,0.2);
% Set the number of integer and fractional bits
ibits = 16;
fbits = 20;
% Set number of clock cycles used to update the output
% of the "multistep" implementation
nsteps = 4;
% Extract lengths of a and b
[x,nb]=size(b);
[x,na]=size(a);
% Generate the step response of the filter
sr=filter(b,a,ones(100,1));
% Write the step response to the file
save "-ascii" output_octave.txt sr
X
% Now generate the fixed_prec package for GHDL simulations
s=["package fixed_prec_pkg is"];
s=[s;"constant ibits : integer := " num2str(ibits) ";"];
s=[s;"constant fbits : integer := " num2str(fbits) ";"];
s=[s;"end fixed_prec_pkg;"];
fo=fopen("fixed_prec.vhd","w");
fdisp(fo,s)
fclose(fo)
X
% Now generate the filtdef package for GHDL simulations
s=[
"library ieee;";
"use ieee.std_logic_1164.all;";
"use ieee.numeric_std.all;";
"use std.textio.all;";
"library ieee_proposed;";
"use ieee_proposed.fixed_pkg.all;";
"use work.fixed_prec_pkg.all;";
"use work.iir_fp_pkg.all;";
"package filtdef is"];
s=[s;"constant nsteps : integer := " num2str(nsteps) ";"];
s=[s;"constant na : integer := " num2str(na) ";"];
s=[s;"constant nb : integer := " num2str(nb) ";"];
l=["constant a_coeffs : T_IIR_COEFFS(0 to na-1) := ("];
for i = 1:na
X l=[l "tfs(" num2str(a(i),"%10.10e") ")"];
X if (i ~= na )
X l=[l,","];
X endif;
endfor
l=[l ");"];
s=[s;l];
l=["constant b_coeffs : T_IIR_COEFFS(0 to nb-1) := ("];
for i = 1:nb
X l=[l "tfs(" num2str(b(i),"%10.10e") ")"];
X if (i ~= nb)
X l=[l ","];
X endif;
endfor
l=[l,");"];
s=[s;l;"end filtdef;"];
fo=fopen("filtdef.vhd","w");
fdisp(fo,s)
fclose(fo)
% Finally run the testbenches
system("make -f makefile_sstep clean")
system("make -f makefile_sstep")
system("make -f makefile_mstep clean")
system("make -f makefile_mstep")
% Compare results
system("xterm -e vim -O output_sstep.txt output_octave.txt output_mstep.txt")
X
X
X
SHAR_EOF
(set 20 11 04 02 18 52 34 'filter_test.m'
eval "${shar_touch}") && \
chmod 0744 'filter_test.m'
if test $? -ne 0
then ${echo} "restore of filter_test.m failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'filter_test.m': 'MD5 check failed'
) << \SHAR_EOF
288c749d9b75e5c5bf311bfab7eed25b filter_test.m
SHAR_EOF
else
test `LC_ALL=C wc -c < 'filter_test.m'` -ne 2070 && \
${echo} "restoration warning: size of 'filter_test.m' is not 2070"
fi
fi
# ============= fmod.vhd ==============
if test -f 'fmod.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING fmod.vhd (file already exists)"
else
${echo} "x - extracting fmod.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'fmod.vhd' &&
---
-------------------------------------------------------------------------------
-- MATH_REAL / MOD function - (c)2007 Christophe CURIS
-- Provided as-is as a workaround for GHDL's missing MOD operator on reals
-- Code is GPL.
-------------------------------------------------------------------------------
X
package math_real_fmod is
X
function "MOD"(X, Y: in REAL ) return REAL;
X
end math_real_fmod;
X
package body math_real_fmod is
X
function SYS_fmod(X: REAL; Y: REAL) return REAL;
attribute foreign of SYS_fmod : function is "VHPIDIRECT fmod";
X
function "MOD"(X, Y: in REAL ) return real is
begin
if (Y = 0.0) then
report Y'instance_name & " Y=0.0 not allowed for MOD operator"
severity ERROR;
return 0.0;
else
return SYS_fmod(X, Y);
end if;
end;
X
function SYS_fmod (X: REAL; Y: REAL) return REAL is
begin
report "ERROR: Call to 'fmod' instead of FOREIGN body"
severity FAILURE;
end SYS_fmod;
X
end math_real_fmod;
SHAR_EOF
(set 20 09 04 23 09 10 58 'fmod.vhd'
eval "${shar_touch}") && \
chmod 0644 'fmod.vhd'
if test $? -ne 0
then ${echo} "restore of fmod.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'fmod.vhd': 'MD5 check failed'
) << \SHAR_EOF
2d68c879a8cbab25a457635277b80751 fmod.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'fmod.vhd'` -ne 919 && \
${echo} "restoration warning: size of 'fmod.vhd' is not 919"
fi
fi
# ============= iir_fphdl_mstep.vhd ==============
if test -f 'iir_fphdl_mstep.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING iir_fphdl_mstep.vhd (file already exists)"
else
${echo} "x - extracting iir_fphdl_mstep.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'iir_fphdl_mstep.vhd' &&
-- This is PUBLIC DOMAIN code written by Wojciech M. Zabolotny
-- wz...@ise.pw.edu.pl
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use std.textio.all;
library work;
use work.fixed_prec_pkg.all;
use work.iir_fp_pkg.all;
entity dsp_sys is
X
-- nsteps - describes in how many steps we would like to have the results calculated...
-- so the result will be updated every nsteps clocks.
-- We have a clock signal - and clock0 signal which requires all blocks to read
-- the input data. All outputs should be also stable when clock0 is high
-- (so that the next block is able to read the stable data)
X
X generic (
X ibits : integer := 7;
X fbits : integer := 5;
X nsteps : integer := 1;
X na : integer := 3;
X nb : integer := 3;
X a_coeffs : T_IIR_COEFFS;
X b_coeffs : T_IIR_COEFFS
X );
X port (
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X clk0 : in std_logic;
X rst : in std_logic
X );
X
end dsp_sys;
X
architecture beh of dsp_sys is
X
-- It is important, that during all update cycle input signal remains stable
X
X constant order : integer := maximum(na, nb);
X -- jmax defines how many results we can calculate simultaneously...
X constant jmax : integer := (order+(nsteps-1))/nsteps;
X
X type T_DEL_LINE is array (natural range<>) of sfixed(ibits downto -fbits);
X signal del_line : T_DEL_LINE(0 to order-2) := (others => (others => '0'));
X signal s_out_smp : sfixed(ibits downto -fbits) := (others => '0');
X signal s_in_smp : sfixed(ibits downto -fbits) := (others => '0');
X signal step_cnt : integer range 0 to nsteps := 0;
X signal first : integer range -jmax to order := 0;
X signal tmp2 : sfixed(ibits downto -fbits) := (others => '0');
begin -- beh
X
X s_out_smp <= resize(del_line(0)+in_smp*b_coeffs(0), ibits, -fbits);
X out_smp <= s_out_smp;
X
X xyz : process (rst, clk)
X variable tmp : sfixed(ibits downto -fbits);
X variable s : line;
X variable i : integer;
X begin -- process
X if rst = '0' then -- asynchronous reset (active low)
X del_line <= (others => (others => '0'));
X step_cnt <= 0;
X first <= order - 1;
X elsif clk'event and clk = '0' then -- rising clock edge
X if clk0 = '1' then
X step_cnt <= 0;
X s_in_smp <= in_smp;
X first <= order - 1;
X elsif step_cnt < nsteps then
X -- To keep the output stable during the whole evaluation, we start from
X -- the last delay
X for j in 1 to jmax loop
X -- We perform jmax cycles, starting from the last delay elements
X -- number of updated node
X i := first + 1 - j;
X -- we have to remember the previous value of last updated delay
X -- as it is needed in the next cycle
X tmp := to_sfixed(0, ibits, -fbits);
X -- if this is not the first cycle, we need to start from the value of
X -- the previous delay line (in the first cycle for j=1
X -- i = order-1, so this case is eliminated by the next if!)
X if i > 0 and i < order-1 then
X if j = 1 then
X tmp := tmp2; -- we have to use the previous value
X -- of the delay updated as last in the
X -- previous cycle
X else
X tmp := del_line(i);
X end if;
X end if;
X if i > 0 and i < nb then
X tmp := resize(tmp + s_in_smp * b_coeffs(i), ibits, -fbits);
X end if;
X if i > 0 and i < na then
X tmp := resize(tmp - s_out_smp * a_coeffs(i), ibits, -fbits);
X end if;
X if i > 0 and i <= order-1 then
X if j = jmax then
X tmp2 <= del_line(i-1);
X end if;
X del_line(i-1) <= tmp;
X end if;
X end loop; -- i
X if step_cnt < nsteps-1 then
X first <= first-jmax;
X end if;
X step_cnt <= step_cnt+1;
X else
X -- step_cnt = nsteps
X null; -- don't do anything, just wait for clk0='1'
X end if;
X end if;
X end process;
X
end beh;
SHAR_EOF
(set 20 11 04 02 18 53 26 'iir_fphdl_mstep.vhd'
eval "${shar_touch}") && \
chmod 0644 'iir_fphdl_mstep.vhd'
if test $? -ne 0
then ${echo} "restore of iir_fphdl_mstep.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'iir_fphdl_mstep.vhd': 'MD5 check failed'
) << \SHAR_EOF
3919084c271ab6b3e456c86fef525d15 iir_fphdl_mstep.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'iir_fphdl_mstep.vhd'` -ne 4269 && \
${echo} "restoration warning: size of 'iir_fphdl_mstep.vhd' is not 4269"
fi
fi
# ============= iir_fphdl_pkg.vhd ==============
if test -f 'iir_fphdl_pkg.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING iir_fphdl_pkg.vhd (file already exists)"
else
${echo} "x - extracting iir_fphdl_pkg.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'iir_fphdl_pkg.vhd' &&
-- This is PUBLIC DOMAIN code written by Wojciech M. Zabolotny
-- wz...@ise.pw.edu.pl
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use work.fixed_prec_pkg.all; -- defines ibits and fbits
X
package iir_fp_pkg is
X
X type T_IIR_COEFFS is array (natural range <>) of sfixed(ibits downto -fbits);
X function maximum (
X left, right : integer) -- inputs
X return integer;
X
X function tfs (
X val : real)
X return sfixed;
X
end iir_fp_pkg;
X
package body iir_fp_pkg is
X
X function maximum (
X left, right : integer) -- inputs
X return integer is
X begin -- function max
X if left > right then return left;
X else return right;
X end if;
X end function maximum;
X
X function tfs (
X val : real)
X return sfixed is
X begin
X return to_sfixed(val, ibits, -fbits);
X end function tfs;
X
X
end iir_fp_pkg;
SHAR_EOF
(set 20 11 04 02 18 54 01 'iir_fphdl_pkg.vhd'
eval "${shar_touch}") && \
chmod 0644 'iir_fphdl_pkg.vhd'
if test $? -ne 0
then ${echo} "restore of iir_fphdl_pkg.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'iir_fphdl_pkg.vhd': 'MD5 check failed'
) << \SHAR_EOF
65d9efe66f26ab27c083985f92a9686b iir_fphdl_pkg.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'iir_fphdl_pkg.vhd'` -ne 949 && \
${echo} "restoration warning: size of 'iir_fphdl_pkg.vhd' is not 949"
fi
fi
# ============= iir_fphdl_sstep.vhd ==============
if test -f 'iir_fphdl_sstep.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING iir_fphdl_sstep.vhd (file already exists)"
else
${echo} "x - extracting iir_fphdl_sstep.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'iir_fphdl_sstep.vhd' &&
-- This is PUBLIC DOMAIN code written by Wojciech M. Zabolotny
-- wz...@ise.pw.edu.pl
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use std.textio.all;
library work;
use work.fixed_prec_pkg.all;
use work.iir_fp_pkg.all;
X
entity dsp_sys is
X
X generic (
X ibits : integer := 7;
X fbits : integer := 5;
X na : integer := 3;
X nb : integer := 3;
X a_coeffs : T_IIR_COEFFS;
X b_coeffs : T_IIR_COEFFS
X );
X port (
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X rst : in std_logic
X );
X
end dsp_sys;
X
architecture beh of dsp_sys is
X
X
X constant order : integer := maximum(na, nb);
X type T_DEL_LINE is array (natural range<>) of sfixed(ibits downto -fbits);
X signal del_line : T_DEL_LINE(0 to order-1) := (others => (others => '0'));
X
begin -- beh
X
X
X
X process (clk, rst)
X variable s_out_smp : sfixed(ibits downto -fbits) := (others => '0');
X variable tmp, tmp2 : sfixed(ibits downto -fbits);
X variable s : line;
X begin -- process
X if rst = '0' then -- asynchronous reset (active low)
X del_line <= (others => (others => '0'));
X elsif clk'event and clk = '0' then -- rising clock edge
X s_out_smp := resize(del_line(0)+in_smp*b_coeffs(0), ibits, -fbits);
X out_smp <= s_out_smp;
X for i in 1 to order-1 loop
X tmp := to_sfixed(0.0, ibits, -fbits);
X if i < order-1 then
X tmp := del_line(i);
X end if;
X if i < nb then
X tmp := resize(tmp + in_smp * b_coeffs(i), ibits, -fbits);
X end if;
X if i > 0 and i < na then
X tmp := resize(tmp - s_out_smp * a_coeffs(i), ibits, -fbits);
X end if;
X del_line(i-1) <= tmp;
X end loop; -- i
X end if;
X end process;
X
end beh;
SHAR_EOF
(set 20 11 04 02 18 54 17 'iir_fphdl_sstep.vhd'
eval "${shar_touch}") && \
chmod 0644 'iir_fphdl_sstep.vhd'
if test $? -ne 0
then ${echo} "restore of iir_fphdl_sstep.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'iir_fphdl_sstep.vhd': 'MD5 check failed'
) << \SHAR_EOF
5ef971770173ebc76a749a4385bdbeb5 iir_fphdl_sstep.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'iir_fphdl_sstep.vhd'` -ne 1927 && \
${echo} "restoration warning: size of 'iir_fphdl_sstep.vhd' is not 1927"
fi
fi
# ============= iir_tb_mstep.vhd ==============
if test -f 'iir_tb_mstep.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING iir_tb_mstep.vhd (file already exists)"
else
${echo} "x - extracting iir_tb_mstep.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'iir_tb_mstep.vhd' &&
-- This is PUBLIC DOMAIN code written by Wojciech M. Zabolotny
-- wz...@ise.pw.edu.pl
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use std.textio.all;
library work;
use work.fixed_prec_pkg.all;
use work.iir_fp_pkg.all;
use work.filtdef.all;
X
-------------------------------------------------------------------------------
X
entity iir_tb_mstep is
X
end iir_tb_mstep;
X
-------------------------------------------------------------------------------
X
architecture beh1 of iir_tb_mstep is
X
X component dsp_sys
X generic (
X ibits : integer;
X fbits : integer;
X nsteps : integer;
X na : integer;
X nb : integer;
X a_coeffs : T_IIR_COEFFS;
X b_coeffs : T_IIR_COEFFS);
X port (
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X clk0 : in std_logic;
X rst : in std_logic);
X end component;
X
X -- component generics
X file foutp : text is out "output_mstep.txt";
X -- constants below are defined in the Octave generated filtdef package
X --constant ibits : integer := 16;
X --constant fbits : integer := 20;
X --constant na : integer := 3;
X --constant nb : integer := 3;
X --constant a_coeffs : T_IIR_COEFFS(0 to na-1) := (1.00000, -1.98981, 0.99980);
X --constant b_coeffs : T_IIR_COEFFS(0 to nb-1) := (0.0099907, 0.0000e+00, 0.0000e+00);
X --constant nsteps : integer := 2;
X
X -- component ports
X signal in_smp : sfixed(ibits downto -fbits) := (others => '0');
X signal out_smp : sfixed(ibits downto -fbits);
X signal rst : std_logic := '0';
X
X signal fin : real;
X signal fout : real;
X
X -- clock
X signal Clk : std_logic := '1';
X signal clk0 : std_logic := '0';
X signal clk_cnt : integer range 0 to nsteps;
X
begin -- beh1
X
X fin <= to_real(in_smp);
X fout <= to_real(out_smp);
X
X -- component instantiation
X DUT : dsp_sys
X generic map (
X ibits => ibits,
X fbits => fbits,
X nsteps => nsteps,
X na => na,
X nb => nb,
X a_coeffs => a_coeffs,
X b_coeffs => b_coeffs)
X port map (
X in_smp => in_smp,
X out_smp => out_smp,
X clk => clk,
X clk0 => clk0,
X rst => rst);
X
X -- clock generation
X Clk <= not Clk after 10 ns;
X
X p_clk0 : process (clk, rst)
X begin -- process p_clk0
X if rst = '0' then -- asynchronous reset (active low)
X clk_cnt <= 0;
X elsif clk'event and clk = '1' then -- rising clock edge
X if clk_cnt = nsteps then
X clk0 <= '1';
X clk_cnt <= 0;
X else
X clk0 <= '0';
X clk_cnt <= clk_cnt+1;
X end if;
X end if;
X end process p_clk0;
X
X -- waveform generation
X WaveGen_Proc : process
X variable l : line;
X begin
X -- insert signal assignments here
X
X wait until Clk = '1';
X wait for 105 ns;
X rst <= '1';
X wait for 300 ns;
X in_smp <= to_sfixed(1.0, ibits, -fbits);
X while true loop
X if clk0 = '1' then
X write(l, fout);
X writeline(foutp, l);
X end if;
X wait until Clk = '1';
X wait until Clk = '0';
X end loop;
X end process WaveGen_Proc;
X
X
X
end beh1;
X
-------------------------------------------------------------------------------
X
configuration iir_tb_beh1_cfg of iir_tb_mstep is
X for beh1
X end for;
end iir_tb_beh1_cfg;
X
-------------------------------------------------------------------------------
SHAR_EOF
(set 20 11 04 02 18 54 31 'iir_tb_mstep.vhd'
eval "${shar_touch}") && \
chmod 0644 'iir_tb_mstep.vhd'
if test $? -ne 0
then ${echo} "restore of iir_tb_mstep.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'iir_tb_mstep.vhd': 'MD5 check failed'
) << \SHAR_EOF
18b40156582c5ee4ea20598765f996eb iir_tb_mstep.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'iir_tb_mstep.vhd'` -ne 3609 && \
${echo} "restoration warning: size of 'iir_tb_mstep.vhd' is not 3609"
fi
fi
# ============= iir_tb_sstep.vhd ==============
if test -f 'iir_tb_sstep.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING iir_tb_sstep.vhd (file already exists)"
else
${echo} "x - extracting iir_tb_sstep.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'iir_tb_sstep.vhd' &&
-- This is PUBLIC DOMAIN code written by Wojciech M. Zabolotny
-- wz...@ise.pw.edu.pl
X
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use std.textio.all;
library work;
use work.fixed_prec_pkg.all;
use work.iir_fp_pkg.all;
use work.filtdef.all;
-------------------------------------------------------------------------------
X
entity iir_tb is
X
end iir_tb;
X
-------------------------------------------------------------------------------
X
architecture beh1 of iir_tb is
X
X component dsp_sys
X generic (
X ibits : integer;
X fbits : integer;
X na : integer;
X nb : integer;
X a_coeffs : T_IIR_COEFFS;
X b_coeffs : T_IIR_COEFFS);
X port (
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X rst : in std_logic);
X end component;
X
X -- component generics
X file foutp : text is out "output_sstep.txt";
X --Constants below are defined in the octave generated filtdef package
X --constant ibits : integer := 16;
X --constant fbits : integer := 20;
X --constant na : integer := 3;
X --constant nb : integer := 3;
X --constant a_coeffs : T_IIR_COEFFS(0 to na-1) := ( 1.00000, -1.98981, 0.99980);
X --constant b_coeffs : T_IIR_COEFFS(0 to nb-1) := ( 0.0099907, 0.0000e+00, 0.0000e+00);
X
X
X -- component ports
X signal in_smp : sfixed(ibits downto -fbits) := (others => '0');
X signal out_smp : sfixed(ibits downto -fbits);
X signal rst : std_logic := '0';
X signal dout : signed(15 downto 0);
X
X signal fin : real;
X signal fout : real;
X
X signal stime : integer := 0;
X -- clock
X signal Clk : std_logic := '1';
X
begin -- beh1
X
X fin <= to_real(in_smp);
X fout <= to_real(out_smp);
X dout <= to_signed(out_smp * 8192,16);
X -- component instantiation
X DUT: dsp_sys
X generic map (
X ibits => ibits,
X fbits => fbits,
X na => na,
X nb => nb,
X a_coeffs => a_coeffs,
X b_coeffs => b_coeffs)
X port map (
X in_smp => in_smp,
X out_smp => out_smp,
X clk => clk,
X rst => rst);
X
X -- clock generation
X Clk <= not Clk after 10 ns;
X
X -- waveform generation
X WaveGen_Proc: process
X variable l : line;
X begin
X -- insert signal assignments here
X wait until Clk = '1';
X wait for 105 ns;
X rst <= '1';
X wait until Clk = '1';
X wait until Clk = '0';
X in_smp <= to_sfixed(1.0,ibits,-fbits);
X while true loop
X write(l,fout);
X writeline(foutp,l);
X wait until Clk = '1';
X wait until Clk = '0';
X end loop;
X end process WaveGen_Proc;
X
X
X
end beh1;
X
-------------------------------------------------------------------------------
X
configuration iir_tb_beh1_cfg of iir_tb is
X for beh1
X end for;
end iir_tb_beh1_cfg;
X
-------------------------------------------------------------------------------
SHAR_EOF
(set 20 11 04 02 18 55 08 'iir_tb_sstep.vhd'
eval "${shar_touch}") && \
chmod 0644 'iir_tb_sstep.vhd'
if test $? -ne 0
then ${echo} "restore of iir_tb_sstep.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'iir_tb_sstep.vhd': 'MD5 check failed'
) << \SHAR_EOF
6a3bd5342f5d2eff08da119fd8009e01 iir_tb_sstep.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'iir_tb_sstep.vhd'` -ne 2935 && \
${echo} "restoration warning: size of 'iir_tb_sstep.vhd' is not 2935"
fi
fi
# ============= iir_top_mstep.vhd ==============
if test -f 'iir_top_mstep.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING iir_top_mstep.vhd (file already exists)"
else
${echo} "x - extracting iir_top_mstep.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'iir_top_mstep.vhd' &&
-- This is PUBLIC DOMAIN code written by Wojciech M. Zabolotny
-- wz...@ise.pw.edu.pl
X
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use std.textio.all;
library work;
use work.fixed_prec_pkg.all;
use work.iir_fp_pkg.all;
use work.filtdef.all;
X
-------------------------------------------------------------------------------
X
entity iir_top_mstep is
X port(
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X clk0 : in std_logic;
X rst : in std_logic);
end iir_top_mstep;
X
-------------------------------------------------------------------------------
X
architecture beh1 of iir_top_mstep is
X
X component dsp_sys
X generic (
X ibits : integer;
X fbits : integer;
X nsteps : integer;
X na : integer;
X nb : integer;
X a_coeffs : T_IIR_COEFFS;
X b_coeffs : T_IIR_COEFFS);
X port (
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X clk0 : in std_logic;
X rst : in std_logic);
X end component;
begin
X -- component instantiation
X DUT : dsp_sys
X generic map (
X ibits => ibits,
X fbits => fbits,
X nsteps => nsteps,
X na => na,
X nb => nb,
X a_coeffs => a_coeffs,
X b_coeffs => b_coeffs)
X port map (
X in_smp => in_smp,
X out_smp => out_smp,
X clk => clk,
X clk0 => clk0,
X rst => rst);
X
end beh1;
X
-------------------------------------------------------------------------------
X
configuration iir_top_beh1_cfg of iir_top_mstep is
X for beh1
X end for;
end iir_top_beh1_cfg;
X
-------------------------------------------------------------------------------
SHAR_EOF
(set 20 11 04 02 18 55 12 'iir_top_mstep.vhd'
eval "${shar_touch}") && \
chmod 0644 'iir_top_mstep.vhd'
if test $? -ne 0
then ${echo} "restore of iir_top_mstep.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'iir_top_mstep.vhd': 'MD5 check failed'
) << \SHAR_EOF
27b6745f1462913f11fd53184d85318d iir_top_mstep.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'iir_top_mstep.vhd'` -ne 1865 && \
${echo} "restoration warning: size of 'iir_top_mstep.vhd' is not 1865"
fi
fi
# ============= iir_top_sstep.vhd ==============
if test -f 'iir_top_sstep.vhd' && test "$first_param" != -c; then
${echo} "x - SKIPPING iir_top_sstep.vhd (file already exists)"
else
${echo} "x - extracting iir_top_sstep.vhd (text)"
sed 's/^X//' << 'SHAR_EOF' > 'iir_top_sstep.vhd' &&
-- This is PUBLIC DOMAIN code written by Wojciech M. Zabolotny
-- wz...@ise.pw.edu.pl
X
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use std.textio.all;
library work;
use work.fixed_prec_pkg.all;
use work.iir_fp_pkg.all;
use work.filtdef.all;
-------------------------------------------------------------------------------
X
entity iir_top_sstep is
X port (
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X rst : in std_logic);
end iir_top_sstep;
X
-------------------------------------------------------------------------------
X
architecture beh1 of iir_top_sstep is
X
X component dsp_sys
X generic (
X ibits : integer;
X fbits : integer;
X na : integer;
X nb : integer;
X a_coeffs : T_IIR_COEFFS;
X b_coeffs : T_IIR_COEFFS);
X port (
X in_smp : in sfixed(ibits downto -fbits);
X out_smp : out sfixed(ibits downto -fbits);
X clk : in std_logic;
X rst : in std_logic);
X end component;
X
begin -- beh1
X
X -- component instantiation
X DUT: dsp_sys
X generic map (
X ibits => ibits,
X fbits => fbits,
X na => na,
X nb => nb,
X a_coeffs => a_coeffs,
X b_coeffs => b_coeffs)
X port map (
X in_smp => in_smp,
X out_smp => out_smp,
X clk => clk,
X rst => rst);
X
end beh1;
X
-------------------------------------------------------------------------------
X
configuration iir_top_beh1_cfg of iir_top_sstep is
X for beh1
X end for;
end iir_top_beh1_cfg;
X
-------------------------------------------------------------------------------
SHAR_EOF
(set 20 11 04 02 18 55 40 'iir_top_sstep.vhd'
eval "${shar_touch}") && \
chmod 0644 'iir_top_sstep.vhd'
if test $? -ne 0
then ${echo} "restore of iir_top_sstep.vhd failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'iir_top_sstep.vhd': 'MD5 check failed'
) << \SHAR_EOF
b0b9c7b346f24d15dd37fb03e844e1d5 iir_top_sstep.vhd
SHAR_EOF
else
test `LC_ALL=C wc -c < 'iir_top_sstep.vhd'` -ne 1739 && \
${echo} "restoration warning: size of 'iir_top_sstep.vhd' is not 1739"
fi
fi
# ============= makefile_mstep ==============
if test -f 'makefile_mstep' && test "$first_param" != -c; then
${echo} "x - SKIPPING makefile_mstep (file already exists)"
else
${echo} "x - extracting makefile_mstep (text)"
sed 's/^X//' << 'SHAR_EOF' > 'makefile_mstep' &&
VHDLS = \
X fixed_prec.vhd \
X iir_fphdl_pkg.vhd \
X filtdef.vhd \
X iir_fphdl_mstep.vhd \
X iir_tb_mstep.vhd \
X
ENTITY=iir_tb_mstep
X
#STD=standard
STD=synopsys
all: ${ENTITY}.ghw
X
reader: ${ENTITY} ${ENTITY}.ghw
X gtkwave ${ENTITY}.ghw {ENTITY}.sav
${ENTITY}: ${VHDLS}
X ghdl -a --std=93c -Pip --ieee=${STD} ${VHDLS}
X ghdl -e --std=93c -Pip -fexplicit --ieee=${STD} ${ENTITY}
${ENTITY}.ghw: ${ENTITY}
X ./${ENTITY} --wave=${ENTITY}.ghw --stop-time=10000ns
# ./${ENTITY} --trace-processes --trace-signals --checks --wave=${ENTITY}.ghw --stop-time=10000ns
clean:
X rm *.o *.vcd *.ghw ${ENTITY}
X
SHAR_EOF
(set 20 11 04 02 18 56 25 'makefile_mstep'
eval "${shar_touch}") && \
chmod 0644 'makefile_mstep'
if test $? -ne 0
then ${echo} "restore of makefile_mstep failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'makefile_mstep': 'MD5 check failed'
) << \SHAR_EOF
6cb4f0f42a9a9d127729d05b4aa49fcc makefile_mstep
SHAR_EOF
else
test `LC_ALL=C wc -c < 'makefile_mstep'` -ne 598 && \
${echo} "restoration warning: size of 'makefile_mstep' is not 598"
fi
fi
# ============= makefile_sstep ==============
if test -f 'makefile_sstep' && test "$first_param" != -c; then
${echo} "x - SKIPPING makefile_sstep (file already exists)"
else
${echo} "x - extracting makefile_sstep (text)"
sed 's/^X//' << 'SHAR_EOF' > 'makefile_sstep' &&
VHDLS = \
X fixed_prec.vhd \
X iir_fphdl_pkg.vhd \
X filtdef.vhd \
X iir_fphdl_sstep.vhd \
X iir_tb_sstep.vhd \
X
ENTITY=iir_tb
X
#STD=standard
STD=synopsys
all: ${ENTITY}.ghw
X
reader: ${ENTITY} ${ENTITY}.ghw
X gtkwave ${ENTITY}.ghw {ENTITY}.sav
${ENTITY}: ${VHDLS}
X ghdl -a --std=93c -Pip --ieee=${STD} ${VHDLS}
X ghdl -e --std=93c -Pip -fexplicit --ieee=${STD} ${ENTITY}
${ENTITY}.ghw: ${ENTITY}
X ./${ENTITY} --wave=${ENTITY}.ghw --stop-time=10000ns
# ./${ENTITY} --trace-processes --trace-signals --wave=${ENTITY}.ghw --stop-time=50000ns
clean:
X rm *.o *.vcd *.ghw rm ${ENTITY}
X
SHAR_EOF
(set 20 11 04 02 16 54 50 'makefile_sstep'
eval "${shar_touch}") && \
chmod 0664 'makefile_sstep'
if test $? -ne 0
then ${echo} "restore of makefile_sstep failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'makefile_sstep': 'MD5 check failed'
) << \SHAR_EOF
424eef8beb290666cafc0640705ddc1a makefile_sstep
SHAR_EOF
else
test `LC_ALL=C wc -c < 'makefile_sstep'` -ne 583 && \
${echo} "restoration warning: size of 'makefile_sstep' is not 583"
fi
fi
if rm -fr ${lock_dir}
then ${echo} "x - removed lock directory ${lock_dir}."
else ${echo} "x - failed to remove lock directory ${lock_dir}."
exit 1
fi
exit 0

0 new messages