CANpack code generation Problem for MCU without floating-point math capabilities

조회 수: 3 (최근 30일)
real32_T outValue = 0;
{
real32_T result =aa;
result =bb;
outValue = roundf(result);
"This facility may not be available on configurations of the EWL that run on platforms
that do not have floating-point math capabilities. "
--EWL C Reference Manual.pdf

채택된 답변

Walter Roberson
Walter Roberson 2023년 9월 17일
편집: Walter Roberson 2023년 9월 17일

roundf has been part of the C standard library since C99. However it expects floating point input and returns floating point output, which is a problem if you are using a system that does not have floating point hardware.

On a system that does not have floating point hardware, you have two choices:

  • you can carefully write your code to only operate on the int* and uint* classes; or
  • you can convert your code to use fixed-point arithmetic with the Fixed-Point Toolbox. The fixed point toolbox can emulate many floating-point operations in software, including potentially to greater precision than double precision floating point. However, transcendental functions such as trig functions or log generally have to be rewritten; search for CORDIC for those.
  댓글 수: 1
zhichao li
zhichao li 2023년 9월 17일
thanks!
use fixed-point arithmetic is a good solution,I will test!
now I just delete the roundf, Refer to older versions of code generation(15b)

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

추가 답변 (1개)

zhichao li
zhichao li 2023년 9월 17일
I solved it by modify the function in can_helpers.tlc
%function roundRealValue(inVar, outVar, dataType)
%openfile buffer
%switch dataType
%case "real32_T"
%% %<outVar> = roundf(%<inVar>); //before
%<outVar> = %<inVar>;
%break
%case "real_T"
%case "real64_T"
%% %<outVar> = round(%<inVar>); //before
%<outVar> = %<inVar>;
%break
%endswitch
%closefile buffer
%return buffer
%endfunction

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by