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,
Internet Explorer 11,
Safari. Thank you!
AR# 23346: 8.1 AccelDSP Synthesis Tool - When Is a Persistent Variable Mapped to a Register?
8.1 AccelDSP Synthesis Tool - When Is a Persistent Variable Mapped to a Register?
In AccelDSP, sometimes MATLAB persistent variables are latched on a clock edge and sometimes they are not. Why?
Whether or not a MATLAB variable is latched on a clock edge is dependent upon the data flow within the MATLAB statement list. Thus, if one has MATLAB of the form
[c] = my_func(a); persistent b; if isempty(b) b = 0; end b = a; c = b;
then "b" need not be mapped to a FF/Latch, even though "b" is a persistent variable. In this simple example, the data flow does not require any value to be "stored" in order to determine the output "c."
However, if the last two lines are switched, we have
[c] = my_func(a); persistent b; if isempty(b) b = 0; end c = b; b = a;
In this MATLAB, the assignment to "c" requires a "previous" value of "b." Then "b" is overwritten after the assignment to "c." In this case, the persistent variable "b" will be latched on the clock edge so that we can retain its value for the "next" call to the function, "my_func." The key is the order of the MATLAB statements. In this case, "b" must be persistent in order to simulate in MathWorks.