Pause of Fractional Seconds in Generated Code

The help file for pause.m says the following in the notes about Code Generation:
The generated code truncates pause delay values to uint32 range during run-time execution.
I believe that means that fractional seconds less than 0.5 s (i.e. pause(0.1) ) will round to zero and no pause will happen in the generated code. Can someone confirm this?
If I am correct about this, is there a work around to do fractional exectuation pauses in generated code?

 채택된 답변

Matthew DiBello
Matthew DiBello 2023년 2월 3일
편집: Matthew DiBello 2023년 2월 6일

0 개 추천

Hi Michael,
Your understanding is incorrect. In code generation, pause supports fractional values. The line from the documentation that you are referring to indicates that the maximum sleep duration is the max value of uint32.
Best,
Matthew

댓글 수: 4

Michael
Michael 2023년 2월 6일
편집: Michael 2023년 2월 6일
Nailed it. Thanks.
coder.cinclude('time.h')
while true
if isdeployed
coder.ceval('usleep',5000)
else
pause(0.005)
end
end
After digging more deeply into this question, I have determined that my initial answer was incorrect. The pause function does support fractional values in code generation. I have updated my answer to be correct.
I apologize for the confusion.
Best,
Matthew
Michael
Michael 2023년 2월 6일
@Matthew DiBello That's interesting because my limited testing so far seem to show significantly higher CPU usage when I used 'pause' rather than the ceval('usleep'...) in my generated code. It seemed to me to be a busy idle while loop (pausing for 0) that was fixed when I started using ceval. I can do more testing with this to confirm.
Either way, I think the pause help file could stand to be updated. Can you make a request of the documentation team to clarify this? Thanks for digging into this.
@Michael - I will follow up with our Documentation team to improve the help file for pause.
The code generation implementation of pause uses nanosleep on POSIX systems and Sleep on Windows systems. If you want to see exactly how it's implemented, you can run non-MEX code generation and then use packNGo to get all the source in one place.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 2월 1일

댓글:

2023년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by