04-25-2012 09:42 AM
What is wrong with my code? I want it to wait until a image has finished being read into shared memory and then select a window from this memory by following this mcode.
function Address = addressgenerator(counter)
if counter == 262144
Address = ((512*n)+m);
if m == 100
m = 0;
Solved! Go to Solution.
04-25-2012 01:11 PM
There are some issues with this code. The most important is that this whole MCode function will be "executed" at once per cycle. Well, to be more precise, that code will be synthesized in block that will output only last value of variable Address per one input cycle. So if you would like to output Address values sequentially, then you should calculate and return only one Address value per function call. It means that you need to have persistent (or static in terms of C language) variables n and m in your code.
Please have a look at page 280 of System Generator Reference Guide:
There is a detailed description of MCode block, its restrictions and allowed helper functions (e.g., xl_state()).
Also one should note following:
1. Value of returned variable (Address) should be defined in all branches of conditional code.
2. All loops are unrolled (and there is maximum unroll limit). But as stated above, you don't need loops.
04-27-2012 12:57 PM
I seemed to have nearly finished what I'm doing and sorted everything. Learnt a lot :)
I just have one more question, I need to work out the minimum error so I need some way of producing the abs() function, within mcode. As I need minimum nearest to 0.