Request for Replace Custom Function with Optimized Lookup Table example
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear All,
But I came across the below error message every time.
============= Step3: Generate Fixed Point Code ==============
### Generating Fixed Point MATLAB Code mlhdlc_replacement_exp_fixpt using Proposed Types
### Generating Fixed Point MATLAB Design Wrapper mlhdlc_replacement_exp_wrapper_fixpt
### Generating Mex file for ' mlhdlc_replacement_exp_wrapper_fixpt '
??? Function 'log' is not defined for values of class 'embedded.fi'.
Error in ==> mlhdlc_replacement_exp_fixpt Line: 15 Column: 8
Code generation failed: View Error Report
Build failed.
Use help codegen for more information on using this command.
Function name 'mlhdlc_replacement_exp' specified more than once.
Use help codegen for more information on using this command.
Error using codegen
Actually, I want to make a custom hdl code by using "log" function.
Would you please help me how to to that example ?
Or Would you please give me example code?
I used with the script
clear
clc
clear design_name testbench_name fxpCfg hdlcfg interp_degree
design_name = 'mlhdlc_replacement_exp';
testbench_name = 'mlhdlc_replacement_exp_tb';
interp_degree = 0;
fixed point converter config
fxpCfg = coder.config('fixpt');
fxpCfg.TestBenchName = 'mlhdlc_replacement_exp_tb';
fxpCfg.TestNumerics = true;
% specify this - for optimized HDL
fxpCfg.DefaultWordLength = 40;
fxpCfg.ProposeWordLengthsForDefaultFractionLength = true;
fxpCfg.DefaultFractionLength = 30;
% %% exp - replacement config
% mathFcnGenCfg = coder.approximation('log');
% % generally use to increase accuracy; specify this as power of 2 for optimized HDL
% mathFcnGenCfg.NumberOfPoints = 1024;
% mathFcnGenCfg.InterpolationDegree = interp_degree; % can be 0,1,2, or 3
% fxpCfg.addApproximation(mathFcnGenCfg);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %saturateExp = @(x) 1/(1+exp(-x));
% saturateExp = @(y) log(u)*0.4342944819;
% mathFcnGenCfg = coder.approximation('Function','saturateExp',...
% 'CandidateFunction', saturateExp,...
% 'NumberOfPoints',50,'InputRange',[0,10]);
% fxpCfg.addApproximation(mathFcnGenCfg);
saturateExp = @(x) 1/(1+exp(-x));
custAppx = coder.approximation('Function','saturateExp',...
'CandidateFunction', saturateExp,...
'NumberOfPoints',50,'InputRange',[0,10]);
fxpCfg.addApproximation(custAppx);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HDL config object
hdlcfg = coder.config('hdl');
hdlcfg.TargetLanguage = 'Verilog';
hdlcfg.DesignFunctionName = design_name;
hdlcfg.TestBenchName = testbench_name;
hdlcfg.GenerateHDLTestBench=true;
hdlcfg.ConstantMultiplierOptimization = 'auto'; %optimize out any multipliers from interpolation
hdlcfg.PipelineVariables = 'y u idx_bot x x_idx';%
hdlcfg.InputPipeline = 2;
hdlcfg.OutputPipeline = 2;
hdlcfg.RegisterInputs = true;
hdlcfg.RegisterOutputs = true;
codegen('-float2fixed',fxpCfg,'-config',hdlcfg,'mlhdlc_replacement_exp')
0 Commenti
Risposte (1)
Walter Roberson
il 9 Feb 2018
2 Commenti
Walter Roberson
il 9 Feb 2018
I meant more to follow up to the parts about writing replacement functions. You probably do not have a double precision core available for your FPGA, so you are going to have to provide your own log function.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

