This example shows how to debug and resolve problems in a DSP implementation using Automation Interface component of the IDE Link.
You use Automation Interface component to automate CCS-specific actions such as
running and halting the target application
reading and writing data to and from memory and registers
To show the components, this example implements the algorithm shown in the following figure on a DSP target, and verifies this implementation against a MATLAB simulation of the algorithm. The first stage of the algorithm generates a noisy sinusoid signal. The second stage applies a lowpass FIR filter to the input signal. The third stage computes the spectrum of the filtered signal.
This example is composed of three tasks. Task 1 runs both the MATLAB simulation and the DSP implementation of the algorithm and compares the outputs from each stage of the algorithm. We plot the DSP target output spectrum against the MATLAB simulation output spectrum, which we treat as the reference. The spectra show a discrepancy in the outputs that indicates a problem with the DSP implementation. Task 2 shows one way to reveal this problem and Task 3 applies and tests a solution that does not involve changing the DSP target code.
The data from the DSP target is imported to MATLAB by creating a link to the DSP target and using this link to read from memory the value of a certain DSP variable. The following lines of code show how this is done on a 256-element 16-bit integer variable, 'FilterOutput', that is loaded on the DSP target:
cc = ticcs; addr_FilterOutput = address(cc,'FilterOutput'); filterOutput_tgt = read(cc,addr_FilterOutput,'int16',256);
To access the DSP output after each stage, breakpoints are set at particular lines in the C code. Each breakpoint location corresponds to the end of the previous stage and the start of the next stage (see the following figure). Using the link, the DSP application is run. Every time the DSP halts at a breakpoint, the output data is read.
All the operations described above are automated using the IDE Link. To view the complete code, go to the Appendix.
The next figure shows the results of the DSP implementation and MATLAB simulation after each stage. The three subplots show each stage of the algorithm:
The first subplot shows the noisy sinusoid signal.
The second subplot shows the result of applying the FIR filter to the noisy signal.
The third subplot shows the spectrum of the filtered signal.
The status is displayed in the MATLAB command window.
Looking at the second subplot, you see that the DSP result starts to diverge from the MATLAB simulation result. This divergence indicates there is a problem in the DSP implementation of the filter. The next task shows how you can determine the root of the problem using the IDE Link methods.
This task runs the same script as Task 1 plus some additional lines of code in the filtering stage. Because the DSP result diverged from the MATLAB result in the Apply filter stage, we are going to investigate the filter. The first thing that comes to mind when debugging a filter is to check if the filter coefficients are correct.
In this task, we extract the filter coefficients from the DSP and compare them with the coefficients in the MATLAB simulation. The comparison is done numerically and graphically. The following code implements the comparison:
%- Extract 'filterCoeffs' data from DSP numTaps = 65; filterCoeffsAddr = address(cc,'filterCoeffs'); filterCoeffs_tgt = read(cc,filterCoeffsAddr,'int16',numTaps);
%- Numerically compare the filter coefficients dif = (double(filterCoeffs_tgt) - fix(filterCoeffs*(2^15)))''; dif idx = find(dif~=0); if ~isempty(idx), for i=1 -length(idx), disp(sprintf('\n!!! Coefficient at tap location %d does not match corresponding MATLAB coefficient.\n', idx)); end end %- Graphically compare the filter coefficients plotOutput(4,[1 -prod(filterCoeffsObj.size)],filterCoeffs_tgt,fix(filterCoeffs*(2^15)));
The next figure shows a plot of the simulation filter coefficients versus that of the DSP while the command window displays the difference between the coefficient values. These results show that the DSP target uses the wrong value for the 33rd filter coefficient. From the plot, it appears that the sign of the coefficient is wrong. We correct this implementation error in Task 3.
This task applies and verifies the solution to the problem we identified in Task 2. The solution is to change the value of the DSP filter's 33rd filter coefficient to match the simulation. This solution is normally applied by changing the DSP source code and rebuilding the application. With IDE Link, you can test the solution from MATLAB without changing the DSP code. The following code sample shows how this testing is implemented:
filterCoeffsAddr = address(cc,'filterCoeffs'); filterCoeffs_tgt = read(cc,filterCoeffsAddr,'int16',numTaps); filterCoeffs_tgt(33) = int16(1191); % modify 33rd element write(cc,filterCoeffsAddr,filterCoeffs_tgt);
By running this line of code before the filter is applied to the noisy input signal, the correct value of the 33rd filter coefficient is written to memory.
In the following figure, you see that the DSP filter coefficients now match the MATLAB simulation. Consequently, in the next figure, you see that the output of the DSP application now matches the simulation output. Now that you have tested and verified this solution, you can go ahead and apply this change to the DSP source code.
You can still see small discrepancies in the plot of the spectra. These occur because the MATLAB simulation is implemented in double-precision floating point arithmetic and the DSP code is implemented in fixed-point, thereby introducing quantization errors. The discrepancies are more apparent in the high-frequency region.
C6000™ (C67x™, C64x™, C62x™)
C5000™ (C55x™, C54x™)
C2000™ (C28x™, C27x™, C24x™)
TMS470™ (R2x, R1x)