Found an unsupported unbounded loop structure.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello there, I'm working at a very long program, and I got the following error, when I tried to convert it to HDL coder.
The program successfully passed the fixed point conversion, but still I got the following while I converting it to HDL code.
the biggest problem is Matlab can't point which loop has this problem.
"Found an unsupported unbounded loop structure. This loop may be user written or automatically generated due to the use of specific vector expressions or functions. For more information on unsupported loop structures, please refer to the documentation."
here is my code:
for nj=1:2:228
if (UPDN(toll2(nj))==1 && beh(toll2(nj))==1);
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=Combined_S7(tp);
end
nj=nj+1;
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=DAC_shift(tp);
end
end
if (UPDN(toll2(nj))==0 && beh(toll2(nj))==1);
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=DAC_shift(tp);
end
nj=nj+1;
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=Combined_S7(tp);
end
end
if (UPDN(toll2(nj))==0 && beh(toll2(nj))==0);
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=Combined_S7(tp);
end
current_Combined_S7=DAC_shift(toll2(nj-1))-Delta/4;
current_Combined_S7=fi(current_Combined_S7,true,16,16);
nj=nj+1;
for tp=toll2(nj):1:toll2(nj+1)
Combined_S7_tam(tp)=current_Combined_S7;
fd(tp)=Combined_S7_tam(tp);
end
end
if (UPDN(toll2(nj))==1 && beh(toll2(nj))==0);
Current_Combined_S7_tam=DAC_shift(toll2(nj1));
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=Current_Combined_S7_tam;
fd(tp)=Combined_S7_tam(tp);
end
nj=nj+1;
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=Combined_S7(tp);
end
end
nj=nj+1;
end
1 commentaire
Walter Roberson
le 9 Juin 2015
In a duplicate version of the question the code was revised to
for nj=1:2:228
if (UPDN(toll2(nj))==1 && beh(toll2(nj))==1);
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=Combined_S7(tp);
end
nj=nj+1;
for tp=toll2(nj):1:toll2(nj+1);
Combined_S7_tam(tp)=DAC_shift(tp);
end
end
nj=nj+1;
end
Réponses (2)
Walter Roberson
le 9 Juin 2015
You should not modify your loop control variables inside your "for" loop. Your for loop is over "nj" but you are changing "nj" inside the loop. In normal MATLAB that has a defined meaning: the change is "undone" as soon as the next iteration starts, as if you had no modified the loop control variable. In generated code you run into a conflict.
If you want to "skip" iterations of the loop by adjusting the loop control variable then use a "while" loop:
nj = 1;
while nj <= 228
... code that might change nj and if it doesn' then
nj = nj + 2;
end
0 commentaires
Tim McBrayer
le 9 Juin 2015
You have many loops of the form:
for tp=toll2(nj):1:toll2(nj+1);
...
end
While you do not show the definition of toll2, it seems to be a variable. But, it doesn't matter; the same issues remain if toll2 is a constant. This loop is unbounded; that is, the number of iterations the loop will execute is not statically determinable. On one run this may execute only one time based off the values in toll2. The very next iteration of the outer loop of nj may execute the loop 2, or 10, or 1000 times. There is no way for HDL Coder to determine this.
Hardware implementations of a loop are conceptually done by unrolling the loop and implementing each loop iteration in hardware. (There are techniques to use less chip area in exchange for a longer latency.) If you do not know how many times a loop must execute, it's exceedingly difficult to create hardware for that behavior.
This is exactly what your code is doing in multiple places. In order to be supported for HDL code generation, each loop must have statically derminable bounds. All your inner loop bounds are specified by data in toll2; even if toll2 is a constant array, the number of inner loop iterations can vary during each outer iteration.
In addition, Walter's comment is correct. You are incrementing the outer iteration variable nj. This also is not supported for HDL code generation for reasons that I hope are clear after this explanation. One last caveat is that while loops are not generally support for HDL codegen either; their loop count is typically not statically determinable, particularly if you have a non-constant loop step size.
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!