Struct in HDL Function

조회 수: 1 (최근 30일)
Maximilian Sgodda
Maximilian Sgodda 2020년 3월 13일
답변: Kiran Kintali 2020년 10월 19일
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

채택된 답변

Kiran Kintali
Kiran Kintali 2020년 10월 19일
Great to know this. Thanks for sharing.

추가 답변 (1개)

Kiran Kintali
Kiran Kintali 2020년 10월 19일
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
  댓글 수: 1
Maximilian Sgodda
Maximilian Sgodda 2020년 10월 19일
Hello Kiran,
actually my question is obsolete. It's working to handover a struct with Type definitions :)
Greets Maxi

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 HDL Coder에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by