User manual

Tutorial: Using the logic estimator
The FirFilter macro contains the code to perform the actual FIR filtering. Before the filter starts
operation, the coefficients which were passed into the
FirFilter macro are stored in the Coeffs[]
array in the FIR interface structure:
par (i = 0; i < Taps; i++)
{
FirPtr->Coeffs[i] = CoeffList[i];
}
After storing the coefficients, the
FirFilter macro enters a while(1) loop which contains several
sequential stages within it. The first stage is to wait for new data to be written to the FIR:
do
{
TempData = FirPtr->Input;
}while (FirPtr->InputValid == 0);
Once new data has been read, the it can be stored in the array holding past data samples – the contents
of the array are shifted in parallel with the new data being stored. In parallel with this, the
InputValid
bit in the FIR interface structure is reset, and the Index and Accumulator variables are initialized.
par
{
DataArray[Taps - 1] = TempData;
par (i = Taps - 1; i != 0; i--)
{
DataArray[i-1] = DataArray[i];
}
FirPtr->InputValid = 0;
Index = 0;
Accumulator = 0;
}
After the array of sample data has been shifted, the next step is to multiply each sample by its
corresponding coefficient, and sum the results. This is done using a loop which indexes through the
array of data, performing a multiply and Accumulate (MAC) on each element. The number of cycles
taken by this loop will be equal to the number of taps in the FIR filter. The code for the MAC loop is show
below.
while (Index != (Taps - 1))
{
par
{
Accumulator += adjs(DataArray[Index],ResultWidth) *
FirPtr->Coeffs[Index];
Index++;
}
}
Having completed the MAC loop, the filtered output is now in the
Accumulator variable, and the only
remaining task is to send it out to the FIR interface structure:
www.celoxica.com
Page 103