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

Unor4 timer period updates #116

Merged
merged 7 commits into from
Jan 9, 2024

Conversation

KurtE
Copy link

@KurtE KurtE commented Sep 2, 2023

Should resolve: #113

Instead of fixed 100us timer, it now changes the timer period on the fly
to get better granularity.

And like most other Servo implementations, it also only starts one servo at a time, to help minimize current surge to try to start all of the servos at the same time.

I have done some testing with one and two servos with the sweep, where the 2nd servo is 180-pos...

I also found that the FSP using AGT timer was completely busted. I know what is going on and have it working with some core changes. Will create PR to fix that issue.

Instead of fixed 100us timer, it now changes the timer period on the fly
to get better granularity.

And like most other Servo implementations, It also only starts one servo at a time, to help minimize current surge to try to start all of the servos at the same time.

I have done some testing with one and two servos with the sweep, where the 2nd servo is 180-pos...
Note FSP->AGT timer code is completely busted

Will produce PR to hopefully fix it.
@CLAassistant
Copy link

CLAassistant commented Sep 2, 2023

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

github-actions bot commented Sep 2, 2023

Memory usage change @ 604d84f

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 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7 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 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0 0 0.0 0 0.0
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:mbed_portenta:envie_m7 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,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0
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:mbed_portenta:envie_m7,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

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Sep 3, 2023
@iabdalkader
Copy link
Contributor

Hi @KurtE thank you for sending this, I've tested these changes and they do fix the issue it seems. However, we need to keep the FSP/HW specific code out of the library, so can you please add a function that disables the buffer to the core ? In there we can check if it's GPT or AGT, and for the updateClockPeriod, why can't you use set_period_us ? If you need a different function you can also send it to the core.

Note please remove all debugging code and the extra empty lines that were added between functions, and please try to match the existing coding style (space before and after =, and between cast and type).

Removed the #ifdef print code.

Also removed a couple of extra blank lines that were added.
Found a couple places where I cut and pasted in some variable definitions that did not have spaces around =
@github-actions
Copy link

github-actions bot commented Sep 9, 2023

Memory usage change @ 02c5ee9

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 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7 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 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0 0 0.0 0 0.0
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:mbed_portenta:envie_m7 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,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0
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:mbed_portenta:envie_m7,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

@KurtE
Copy link
Author

KurtE commented Sep 9, 2023

@iabdalkader I did a first pass and removed the debug code, a couple of extra blank lines that were added and a few defines that for some reason did not have blanks around the = in the initializers.

However, we need to keep the FSP/HW specific code out of the library, so can you please add a function that disables the >buffer to the core ? In there we can check if it's GPT or AGT, and for the updateClockPeriod, why can't you use set_period_us ? >If you need a different function, you can also send it to the core.

I Will look into adding new methods to the core as to move the hardware specific code out of this hardware specific section of the servo library. I was trying to avoid the necessity of needing a new core in order to fix the servos. Figured that was why the
core method:

        uint8_t type = 0;
        int8_t channel = FspTimer::get_available_timer(type);

returned the information to you about which type of timer that was reserved as well as which channel. As to allow your client
code to detect such things like, is it GPT or not. And likewise, if it is a 32 bit or 16 bit GPT timer.

set_period_us - works like a sledgehammer. It stops the timer, then sets up the data in the abstraction data type, then runs through the initialization code and then starts up the timer again.

KurtE added a commit to KurtE/ArduinoCore-renesas that referenced this pull request Sep 10, 2023
During code review of changes I made to the Servo library:
arduino-libraries/Servo#116

@iabdalkader requested that I move all of the platform specific timer changes into the core instead of being in the hardware specific sub-directory of the Servo library.

This change adds a method to tell the GPT timer, that when I make a change to the pseriod (set_period(p) ) that I want the change to happen now and not be buffered.

And updated the set_period method to check for this and directly set the not buffered register with the new period.
I moved the code that disables the period buffer into a new member function.  I then checked for this in the set_period(p) call, which will either allow it to go to FSP code, or directly set the appropriate register with the new period.

arduino/ArduinoCore-renesas#131
@github-actions
Copy link

Memory usage change @ 04b9322

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 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7 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 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0 0 0.0 0 0.0
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:mbed_portenta:envie_m7 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,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0
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:mbed_portenta:envie_m7,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

@iabdalkader
Copy link
Contributor

@KurtE Thanks, will review and test this again after the core PR is merged.

@github-actions
Copy link

Memory usage change @ fc280bb

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 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7 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 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0 0 0.0 0 0.0
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:mbed_portenta:envie_m7 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,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0
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:mbed_portenta:envie_m7,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

facchinm pushed a commit to arduino/ArduinoCore-renesas that referenced this pull request Sep 15, 2023
* Add method to allow the GPT Timer period not to be buffered

During code review of changes I made to the Servo library:
arduino-libraries/Servo#116

@iabdalkader requested that I move all of the platform specific timer changes into the core instead of being in the hardware specific sub-directory of the Servo library.

This change adds a method to tell the GPT timer, that when I make a change to the period (set_period(p) ) that I want the change to happen now and not be buffered.

And updated the set_period method to check for this and directly set the not buffered register with the new period.

Co-authored-by: Ibrahim Abdelkader <i.abdalkader@gmail.com>
@iabdalkader
Copy link
Contributor

Hi @KurtE sorry it took so long to get around to this, we've been very busy with some other issues. I see that your changes to the core are now merged, great!

I have some comments on this PR, minor typos, styling etc.. and was about to post a full review, but I noticed a small issue with this, do you see how channels are started sequentially ? I think they should all start at the same time. Not sure if this will be easy to fix, would you like to try ?

image

@KurtE
Copy link
Author

KurtE commented Dec 28, 2023

By design to stagger the starts as to try to minimize the startup current...
At least that is what most of the servo setups I have seen have mentioned.

src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
src/renesas/Servo.cpp Outdated Show resolved Hide resolved
@iabdalkader
Copy link
Contributor

iabdalkader commented Jan 3, 2024

By design to stagger the starts as to try to minimize the startup current...
At least that is what most of the servo setups I have seen have mentioned.

Good point, but I think this is outdated or for an older platform that had hardware issues. It's fine with me either way, unless no one else objects, I think this is good to merge after the review comments are fixed.

KurtE and others added 2 commits January 4, 2024 11:26
Co-authored-by: Ibrahim Abdelkader <i.abdalkader@gmail.com>
Updates the usages of functions or constants that the names were changed
Copy link

github-actions bot commented Jan 6, 2024

Memory usage change @ 27dd79b

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 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7 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 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0 0 0.0 0 0.0
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:mbed_portenta:envie_m7 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,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0
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:mbed_portenta:envie_m7,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

@facchinm facchinm merged commit 962ead5 into arduino-libraries:master Jan 9, 2024
13 checks passed
@KurtE KurtE deleted the unor4_timer_period_updates branch January 10, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

PWM duty cycle range not continuous on UNO R4
5 participants