Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mbed not using REFRESH_INTERVAL #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

razvanphp
Copy link

@razvanphp razvanphp commented Sep 18, 2024

This pull request refactors the Servo library for mbed-based boards to utilize std::chrono durations instead of manual conversions with floating-point numbers. The 20ms interval was hardcoded for mbed platform only.

Changes:

  • Fix bug on mbed platform of not using REFRESH_INTERVAL at all
  • Modified ServoImpl::start() and ServoImpl::call() to use std::chrono::microseconds.
  • Eliminated floating-point divisions by 0.02f (hardcoded) and 1e6.
  • Ensured backward compatibility by keeping existing functionality intact.

Benefits:

  • Enhanced type safety and precision.
  • Simplified codebase and aligned with other platforms.
  • Facilitates dynamic adjustment of REFRESH_INTERVAL.

Testing:

  • Verified functionality with default REFRESH_INTERVAL of 20000 microseconds.
  • Tested with REFRESH_INTERVAL set to 10000 and 5000 microseconds.
  • Confirmed correct servo operation and signal timing using an oscilloscope.

Notes:

This change aligns the Servo library with the updated mbed OS API that favours std::chrono durations since mbedOS 6.0.0, see

https://github.com/arduino/ArduinoCore-mbed/blob/702daa02e244fb8710b48599f38786a67c590699/cores/arduino/mbed/drivers/include/drivers/Ticker.h#L85-L122

Also do not use deprecated float as parameter, switch to chrono duration
Copy link

Memory usage change @ fab0609

Board flash % RAM for global variables %
arduino:avr:leonardo 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:mega 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:nano 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nano33ble 💚 -448 - -448 -0.05 - -0.05 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 💚 -1868 - -1868 -0.01 - -0.01 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:megaavr:nona4809 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg 0 - 0 0.0 - 0.0 N/A N/A
arduino:samd:mkrzero 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/Knob
flash
% examples/Knob
RAM for global variables
% examples/Sweep
flash
% examples/Sweep
RAM for global variables
%
arduino:avr:leonardo 0 0.0 0 0.0 0 0.0 0 0.0
arduino:avr:mega 0 0.0 0 0.0 0 0.0 0 0.0
arduino:avr:nano 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nano33ble -448 -0.05 0 0.0 -448 -0.05 0 0.0
arduino:mbed_nano:nanorp2040connect -1868 -0.01 0 0.0 -1868 -0.01 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A N/A N/A N/A N/A
arduino:megaavr:nona4809 0 0.0 0 0.0 0 0.0 0 0.0
arduino:sam:arduino_due_x_dbg 0 0.0 N/A N/A 0 0.0 N/A N/A
arduino:samd:mkrzero 0 0.0 0 0.0 0 0.0 0 0.0
Click for full report CSV
Board,examples/Knob<br>flash,%,examples/Knob<br>RAM for global variables,%,examples/Sweep<br>flash,%,examples/Sweep<br>RAM for global variables,%
arduino:avr:leonardo,0,0.0,0,0.0,0,0.0,0,0.0
arduino:avr:mega,0,0.0,0,0.0,0,0.0,0,0.0
arduino:avr:nano,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nano33ble,-448,-0.05,0,0.0,-448,-0.05,0,0.0
arduino:mbed_nano:nanorp2040connect,-1868,-0.01,0,0.0,-1868,-0.01,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:mbed_portenta:envie_m7:target_core=cm4,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:megaavr:nona4809,0,0.0,0,0.0,0,0.0,0,0.0
arduino:sam:arduino_due_x_dbg,0,0.0,N/A,N/A,0,0.0,N/A,N/A
arduino:samd:mkrzero,0,0.0,0,0.0,0,0.0,0,0.0

@CLAassistant
Copy link

CLAassistant commented Sep 18, 2024

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 linked an issue Sep 18, 2024 that may be closed by this pull request
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Sep 18, 2024
@razvanphp

This comment was marked as duplicate.

@arduino-libraries arduino-libraries locked as too heated and limited conversation to collaborators Nov 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warnings when compiling library for Portenta H7
3 participants