Info

This question is closed. Reopen it to edit or answer.

Convert Code Containing Global Data to Fixed Point

1 view (last 30 days)
Hi, I'm new to use the fixed point converter and HDL coder. I have a problem when I want to convert one of my model function to fixed point because this function is purely defining a global variable "PM" which contains all the parameters in my model. "PM" is a 1*1 structure global variable. I don't know how to convert this function in the fixed point converter. I checked the document for this issue but the situation is a little bit different. I'm using MATLAB 2014b but the document version might be older than this. Also the global variables in the document are not the same data type as mine. So I still can not solve my problems. Basically, my "PM" function is similar the the following, but there are more items in my real function.
%
function [PM]= Parameters(Test)
global PM
%%Constant
PM.R=8.314;
PM.F=96485;
%%Geometry
PM.L=27.6; % Length cm
PM.W=18.5; % Width cm
PM.d=1.47; % Thickness cm
PM.V=PM.L*PM.W*PM.d; % Volume cm
PM.layers=50; %%%%%%%%%%%%%%%Didn't provide%%%%%%%%%%%%%%%
PM.sandwichArea=Test*PM.L*PM.W*PM.layers;
end
Thanks.

Answers (1)

Kiran Kintali
Kiran Kintali on 2 May 2021
Use Persistent Variables instead of Global Variables when translating MATLAB to HDL Code. See doc and best practices in HDL Coder.
web(fullfile(docroot, 'hdlcoder/ug/persistent-variables-1.html?s_tid=doc_srchtitle'))

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!