Struct in HDL Function
1 view (last 30 days)
Show older comments
Maximilian Sgodda
on 13 Mar 2020
Answered: Kiran Kintali
on 19 Oct 2020
Is it possible to hand over a struct containing definitions for datatypes to cast the algorithm internal? The problem is the following. I created a function, where i can configure all of the used fixed point types in my algorithm. By creating a structure containing this datatype definitions, I can handover this struct to the MainFunction of my Algorithm. By doing this i only have to change the types in the function, if i want to adjust some bit sizes.
Its not working. I get the error message: Main_CodeGen:48 Error Found unsupported dimensions on matrix type at input port: 3, name 'TypeFixed.fix_64', in the file/function Main_CodeGen
function [clk_mic,clk_laser,flagclkMic,Index,Theta_average,R_average,DataValidLockIn,sinusValue,cosinusValue] = Main_CodeGen2(FileData,PhaseIncrement,NFilter,TypeFixed)
% doing the algorithm
end
The call for this function looks like this:
% run bittrue model -> running in a for-loop
[StrSim.clk_mic,StrSim.clk_laser,StrSim.flagclkMIC,StrSim.Index,StrSim.Theta_average,StrSim.R_average,StrSim.DataValidLockIn,...
StrSim.sinusValue,StrSim.cosinusValue] = Main_CodeGen(StrPlot.FileData(StrSim.Index+1),StrSim.PhaseIncrement,StrSim.NFilter,Type);
And the Function defining the types like this:
function Type = myTypes2(Type,Precision)
switch Precision
case 'fixed'
% Numeric Controlled Oscillator
Type.fix_64 = fi([],0,64,0,'CastBeforeSum',1,'MaxProductWordLength',64,'MaxSumWordLength',64,'OverflowAction','Wrap',...
'ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',64,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',64);
% Datatype for amount of Iterations in LockIn -> Filter
Type.fix_32 = fi([],0,32,0,'CastBeforeSum',1,'MaxProductWordLength',32,'MaxSumWordLength',32,'OverflowAction','Wrap',...
'ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',32,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',32);
% Output Lock-In
Type.fix_s_64_61 = fi([],1,64,61,'CastBeforeSum',1,'MaxProductWordLength',64,'MaxSumWordLength',64,'OverflowAction','Saturate',...
'ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',64,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',64);
% sine/cosine table for values
Type.fix_s_32_30 = fi([],1,32,32-2,'CastBeforeSum',1,'MaxProductWordLength',32,'MaxSumWordLength',32,...
'OverflowAction','Saturate','ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',32,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',32);
% pi-Value
Type.fix_s_32_28 = fi([],1,32,32-4,'CastBeforeSum',1,'MaxProductWordLength',32,'MaxSumWordLength',32,...
'OverflowAction','Saturate','ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',32,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',32);
% Output of Average Filter Lock-In
Type.fix_s_64_32 = fi([],1,64,32,'CastBeforeSum',1,'MaxProductWordLength',64,'MaxSumWordLength',64,'OverflowAction','Saturate',...
'ProductFractionLength',64,'ProductMode','KeepLSB','ProductWordLength',64,'RoundingMethod','Nearest',...
'SumFractionLength',64,'SumMode','KeepLSB','SumWordLength',64);
%%% BIT TYPES %%%
% PDM Data, Flags, Counter
Type.fix_bit = fi([],0,1,0,'CastBeforeSum',1,'MaxProductWordLength',8,'MaxSumWordLength',8,'OverflowAction','Saturate',...
'ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',8,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',8);
Type.fix_u_8bit = fi([],0,8,0,'CastBeforeSum',1,'MaxProductWordLength',8,'MaxSumWordLength',8,'OverflowAction','Saturate',...
'ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',8,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',8);
Type.fix_s_8bit = fi([],1,8,0,'CastBeforeSum',1,'MaxProductWordLength',8,'MaxSumWordLength',8,'OverflowAction','Saturate',...
'ProductFractionLength',0,'ProductMode','KeepLSB','ProductWordLength',8,'RoundingMethod','Nearest',...
'SumFractionLength',0,'SumMode','KeepLSB','SumWordLength',8);
end
end
0 Comments
Accepted Answer
More Answers (1)
Kiran Kintali
on 19 Oct 2020
You may find this example useful.
web(fullfile(docroot, 'fixedpoint/gs/manually-convert-a-floating-point-matlab-algorithm-to-fixed-point.html'))
Create a Table of Data Type Definitions
See Also
Categories
Find more on HDL Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!