// FIR example set clock = external "Dummy"; #define WordLength 8 #define NumTaps 7 chan signed WordLength ch_data; chanout signed (2*WordLength) ch_out with { outfile = "firout.txt" }; void main(void) { // Store the coefficients const signed (2*WordLength) Coeff[NumTaps] = { 54, 64, -7, -16, 15, -3, -7 }; // Shift register signed WordLength SR[NumTaps]; // Store the sum signal signed (2*WordLength) Sum[NumTaps]; signed (2*WordLength) result; static unsigned 1 stop = 0; unsigned 4 i; par { unsigned 8 j, k; // Test stimulus - square wave seq { for (k = 0; k < 3; k++ ) { for (j = 0; j < 10; j++ ) ch_data ! 0; for (j = 0; j < 10; j++ ) ch_data ! 127; } stop = 1; } while (!stop) par { // shift input into reg... par (i = 0; i < NumTaps; i++ ) { ifselect (i == 0) ch_data ? SR[0]; else SR[i] = SR[i-1]; } // Calculate the sum par (i = 0; i < NumTaps; i++ ) { ifselect ( i == 0 ) Sum[0] = ( 0@Coeff[0] ) * ( 0@SR[0] ); else ifselect ( i == NumTaps-1 ) ch_out ! ( Sum[i-1] + ( 0@Coeff[i] ) * ( 0@SR[i] ) ) / 100; else Sum[i] = Sum[i-1] + ( 0@Coeff[i] ) * ( 0@SR[i] ); } } } delay; // for sim }