Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Community Forums
- :
- Forums
- :
- Hardware Development
- :
- AI Engine, DSP IP and Tools
- :
- Error with MCODE block

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

thijscraenmehr

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-07-2011 04:59 AM

6,780 Views

Registered:
05-19-2011

Error with MCODE block

Hi,

This is the MCODE that I'm using:

function angle = CalcAngle(tau)

c = 340.29;

Fs = 44100;

d = 0.02;

angle = cos(((c*tau)/Fs)/d)^(-1);

And this is the error I'm having:

Error("CalcAngle.m"): Syntax error: Encountered "^" at line 5, column 28.

What am I doing wrong? Or am I doing something that is not possible with the MCODE block?

Thanks in advance,

Thijs

0
Kudos

Reply

8 Replies

thijscraenmehr

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-07-2011 07:42 AM - edited 06-07-2011 08:05 AM

6,744 Views

Registered:
05-19-2011

Does this maybe have to do anything with the fact that the mcode blocks do not support algorithmic MATLAB functions?

If this is true, how do I get my mfile (which works perfectly) to VHDL?

0
Kudos

Reply

eilert

Teacher

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-08-2011 12:43 AM

6,731 Views

Registered:
08-14-2007

Hi Thijs,

your doubts are reasonable.

you should read abourt the restrictions that apply to synthesizable mcode for the system generator.

Just to get an idea of what you are doing:

Everything in system generator works with HDL-compatible fixed point types.

In your code you have defined two values c and d with fractional digits.

So, what type should they be?

Float/double? Not suported in sysgen!

Fixed Point?

If so, unsigned or signed?

And how many bits?

And then...how many fractional bits?

Then you have this mathematical operation.

While the multiplications could be done quite easy, the divisions would cause trouble,

not to speak about the high level functions like ^ and cos.

And all of this is required to be done combinatorical?

Remember that you are about to design some real hardware.

It's different from writing some software, with lots of functions in the background all mixed up in a huge memory with lots of time to perform the desired action. (milliseconds are a little eternity for todays CPUs)

Instead you are dealing with thousands of logic elements, all eager to do their job at the same time, and you are the one who needs to define when precisely each elements operation is allowed so their combined action results in something useful.

For MCODE blocks there are special functions available, each representing some element of the xilinx blockset.

These functions begin with a "x" followed by their operations name. They can help you to perform complex operations inside a MCODE block. Also, maybe some of your variables need to be declared as "persistent", so they become registers.

Some hint: for cos and other mathematical operations, the CORDIC block can be helpful.

Have a nice synthesis

Eilert

0
Kudos

Reply

thijscraenmehr

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-08-2011 01:54 AM - edited 06-08-2011 03:57 AM

6,733 Views

Registered:
05-19-2011

Hi Eilert,

Thank you for your reply.

I will be working this day to try and make it working :)

I also read something about AccelDSP:

AccelDSP™ synthesis tool is a high-level MATLAB® language based tool for designing DSP blocks for Xilinx FPGAs (http://www.xilinx.com/tools/acceldsp.htm)

Could this be useful in my case? I do have a license for ISE Design Suite 12.1

With kind regards,

Thijs

0
Kudos

Reply

thijscraenmehr

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-08-2011 05:26 AM

6,717 Views

Registered:
05-19-2011

Hi all,

This is still not working for me, and I don't know what I'm doing wrong here.

I did use the CORDIC blocks and some other blocks to make it easier vor the MCODE block.

I have attached my .mdl file, so if anyone here is able to tell me what I'm doing wrong?

Im a beginner with the Xilinx blockset and programming FPGA's.

Thanks in advance,

Thijs

0
Kudos

Reply

eilert

Teacher

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-09-2011 12:30 AM

6,706 Views

Registered:
08-14-2007

Hi,

the AccelDSP tool is no longer part of the ISE Tools.

I think it has been discontinued after ISE 11.x.

Have a nice synthesis

Eilert

0
Kudos

Reply

eilert

Teacher

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-09-2011 12:36 AM

6,707 Views

Registered:
08-14-2007

Hi Thjis,

that's a nice model, but quite useless without the m-files for the mcode blocks.

They are not embedded in the model.

Maybe you could provide them too? :-)

Have a nice synthesis

Eilert

0
Kudos

Reply

thijscraenmehr

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-09-2011 03:43 AM

6,702 Views

Registered:
05-19-2011

The M-files that I was using for the blocks, is written in text above the blocks.

So for example MCode1 (fastfourrier), it is:

function z = Fastfourrier(x)

z = fft(x)

I'm now using the FFT xilinx block and others, but I'm still having problems with 'abs' and 'conj'

Is it smart to use sqrt(x^2) to get 'abs(x)'?

And how do I get the conjugated part of an array, without the function conj(x)?

Thanks in advance,

Thijs

0
Kudos

Reply

eilert

Teacher

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-15-2011 06:17 AM

6,654 Views

Registered:
08-14-2007

Hi,

my guess was that the codes you wrote above the blocks should serve as some kind of documentation, since high level matlab functions like fft(x) just don't work in an mcode block, so I thought that you already have some self created low level mcode-mfile which is synthesizable.

The same that applies to fft(x) also holds for sqrt(x^2), abs(x) and conj(x).

abs(x) might look like this in synthesizable m-code:

if x<0 then

x=(not x) + 1; % be aware of the data types! This example works only for numbers without fractional parts

end

As you can see, it's the two's complement conversion algorithm.

So if you need to conjugate an array, recreate the formula and do it element for element.

Just for get about all the high level functions you have in matlab. this is hardware sysnthesis, and all the functions you can use are in the xilinx library which is also represented in the xilinx blockset in a graphical way for use with simulink.

Have a nice synthesis

Eilert