4

I've got a question about coding an algorithm for a Texas Instruments TMS320C64xx DSP in MATLAB:

I've got a working sloppy implementation of my filter in MATLAB. My goal is to use MATLAB Embedded Coder to convert this algorithm to C which I can then import to Code Composer Studio and load onto the DSP.

To do this, I know there are certain things I need to do to my MATLAB code. For example, I need to pre-allocate space for matrices so it knows what size to make them (unless I want to fuss around with variable sized data). All that massaging of MATLAB code into C'ish code so that MATLAB coder can convert it I more or less understand. However, I have no idea how to make sure that my data types (for example the coefficients of my filter) are fixed point rather than floating point so that MATLAB Embedded Coder will convert my code to C which only involves fixed point data types.

So I guess my overall questions are:

1) If the C64xx is specified as a 32-bit Fixed Point DSP, that means a compiler for it will throw an error if I try to use the float data type?

2) Is there a way to ensure that MATLAB Embedded Coder does not create float data types?

3) Do I need to use the MATLAB Fixed Point Toolbox?

Thank you all, let me know if there is anymore information necessary to answer my question.

NickHalden
  • 1,469
  • 2
  • 20
  • 31

2 Answers2

3

I can only answer to your first question:

The C64xx is a 32 bit fixed point DSP, but the compiler will not complain if you use floating point. The resulting code will run fine but will be (a lot) slower because the floating point operations will be emulated.

The C64xx DSP also can do 16 bit fixed point and mixed 32x16 bit fixed point. The smaller the data-types are that you use, the faster the resulting code will run.

Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221
  • +1. One nit-pick though, it is true that it gets much faster when you go from 32-bit to 16-bit operations, but going from 16-bit to 8-bit does not make it go faster. – Jim Clay Jun 13 '11 at 17:09
  • Thanks Nils and Jim. Why not Jim? Also, I realize you probably won't be able to answer this, but any idea if "a lot slower" will remove the capability to do realtime processing? As you can tell I'm really new to this whole DSP thing. Only ever done simple 8-bit micros before. – NickHalden Jun 13 '11 at 19:11
  • The C64xx has lots of fixed point instructions, but all of them either take 32 or 16 bit inputs (there are exceptions for special cases though). Going down to 8 bits will most likely not give you any more speed. Instead the compiler will pick a 16 bit fixed-point instruction. Not much gained, but precision lost. – Nils Pipenbrinck Jun 13 '11 at 20:53
  • Ah, understood. I've been meaning to go through the instruction set but TI's documentation is so dense I haven't gotten there yet. Is that the reason you had in mind Jim? – NickHalden Jun 14 '11 at 12:15
3
  1. You can use floating point data types but, as the previous answer points out, the DSP will be emulating floats and the execution will be much slower. This type of execution is OK for certain numerical operations where a) you need the precision of floats b) and/or conversion to fixed-point is typically a pain (e.g. square roots) or not feasible always, c) and/or these operations don't occur that often in your program to hog most of the CPU cycles.

  2. Yes. There's a checkbox in the MATLAB Coder configuration setting dialog, under Interface pane, that says "Support only purely-integer numbers". Checking this will ensure that you don't get any floating point data types in the generated code. However, you first need to make sure you use only integer/fixed-point data types in your code. This option just ensures there are not floats generated - it doesn't automatically generate a fixed-point or integer only version of the code from your floating point MATLAB Code.

  3. To truly create a fixed-point C-code, you'd first have to convert your floating point MATLAB code to a fixed-point one. You would need the Fixed-Point Toolbox that let's you specify your variables as a FI object, and define the fixed-point rules of operations using the FIMATH setting. Once you define a 16/32 bit fixed-point data types for all your variables and operations, you can simulate it, analyze the results, and iterate upon it to tweak your settings to minimize your overflows and rounding errors. Then you can generate a truly integer only C code that will behave just as (or very close to) your fixed-point MATLAB behavior. Any differences you may see between your fixed-point MATLAB code and fixed-point C code will primarily be due to those introduced by your target compiler.

The following link to a recorded webinar on this topic should provide a good introduction to this process of using the Fixed-Point Toolbox: http://www.mathworks.com/wbnr38838

HTH.

Arvind-MW
  • 121
  • 2
  • Beautiful, thanks! Any chance you have a point of contact I can reach you at since it seems I'm working with the exact tools you work with? – NickHalden Jun 20 '11 at 18:18
  • @JGord you can look up my profile to see my full name. first name. last name at mathworks.com is my e-mail. I work at MathWorks and manage fixed-point toolbox. I can certainly help you with your problem. – Arvind-MW Jun 24 '11 at 16:44