UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor sarahleony
Visitor
160 Views
Registered: ‎08-31-2018

Sysgen Mcode output error spreading code

Hi all,

I am trying to write code to an mcode block with this function: 

function [z] = spreading(din)
persistent pr_sig, pr_sig = xl_state(zeros(1, 9),din);
pr_sig(1) = 1;
pr_sig(2) = 1;
pr_sig(3) = 0;
pr_sig(4) = 1;
pr_sig(5) = 1;
pr_sig(6) = 0;
pr_sig(7) = 0;
pr_sig(8) = 1;
persistent data1, data1 = xl_state(ones(1, 9),din);
persistent data2, data2 = xl_state(zeros(1, 9),din);

if din == 1
for i=1:8
data1(i) = xl_xor(data1(i),pr_sig(i));
z = data1(i);
end

else
for i=1:8
data2(i) = xl_xor(data2(i),pr_sig(i));
z = data2(i);
end
end

Essentially I want to take the input bit and my pseudo-random array (pr_sig) and bitwise XOR them together. Then I want to send the output out. This performs Direct sequence spreading. I know you can't output arrays, but I thought maybe this code would work. However I get this error:

output z is not assigned through all possible paths. A misspelling or a switch statement without otherwise statement may cause this error.

 

Anyone know what I am doing wrong?

 

Thank you for your time!!

0 Kudos
2 Replies
Moderator
Moderator
119 Views
Registered: ‎08-16-2018

Re: Sysgen Mcode output error spreading code

You should have one return value for z. 

Note that, in the below code, the value of 'z' is constant, but it is inside the loop, therefore code will generate the same error. 

 

function [z] = spreading(din)

for i = 1:8
    z = 1;  
end

 

 

There should be one return value at the end of execution e.g. 

function [z] = spreading(din)

y = 0
for i = 1:8
    y = i;
end

z = y; 
0 Kudos
Visitor sarahleony
Visitor
114 Views
Registered: ‎08-31-2018

Re: Sysgen Mcode output error spreading code

Hello,

Thank you for the prompt response. Unfortunately that won't work for me because for every input (din) I would like to output 8 different bits (z(8)). I am trying to insert spread spectrum this way. Is there another way to do this? Based on the code edits I would only output 1 value...

0 Kudos