As I mentioned on the other PWM thread: How can I increase the PWM frequency i.e. at PIN 6? - UNO R4 / UNO R4 WiFi - Arduino Forum
I was wondering if we could go the other way and run at a lower speed. In this case 50 hz. So I thought I would try it.
So I created a new branch in my fork of the library:
PaulStoffregen/PWMServo: Control RC Servo motors with interrupt-resilient PWM (github.com)
Which is currently up at: KurtE/PWMServo at UNOR4 (github.com)
Will later do a Pull request back to the master version.
The code is using the PwmOut objects (pwm.h). I am assuming that some form of this object will continue and is not a transitory implementation detail, that will be removed ![]()
Why would one use the PWMServo over the normal Servo library? The PWM Servo library uses PWM, which does not rely on using interrupts. So less likely to have jitters. Downside, uses up more resources, may have less resolution, and more limited choice of pins
So far I have only tested this using the example sketch sweep on WIFI pin 5. Will play a little more on other pins. I am curious about how much difference it would make in running on 32 bit timers versus 16 bit timers.
From the other thread, I believe the full set of PWM pins on the MINIMA is:
| Pin | ~ | RA4M1 | Timer | same timer |
|---|---|---|---|---|
| 3 | ~ | P104 | GTIOC1B | 11 |
| 5 | ~ | P102 | GTIOC2B | 4 |
| 6 | ~ | P106 | GTIOC0B | 7 |
| 9 | ~ | P303 | GTIOC7B | 8 |
| 10 | ~ | P112 | GTIOC3B | 13 |
| 11 | ~ | P109 | GTIOC1A | 3 |
| 0 | P301 | GTIOC4B | 1 | |
| 1 | P302 | GTIOC4A | 0 | |
| 2 | P105 | GTIOC1A | D 11 | |
| 4 | P103 | GTIOC2A | 5 | |
| 7 | P107 | GTIOC0A | 6 | |
| 8 | P304 | GTIOC7A | 9 | |
| 12 | P110 | GTIOC1B | D 3 | |
| 13 | P111 | GTIOC3A | 10 | |
| 18 | P101 | GTIOC5A | 19 | |
| 19 | P100 | GTIOC5B | 18 | |
| 20 | P500 | GTIOC2A | D 4 |
On the WiFI, I will update with complete list, but the list on the cheat sheet Arduino UNO R4 WiFi Cheat Sheet | Arduino Documentation is probably reasonably complete. Not sure if it may also have some duplicate pins not marked. By duplicate I mean that they have the same timer as another pin already in the table.
Updated:
| WIFI | ~ | RA4M1 | GPT | Same Timer |
|---|---|---|---|---|
| 3 | ~ | P105 | GTIOC1A | 2 |
| 5 | ~ | P107 | GTIOC0A | 4 |
| 6 | ~ | P111 | GTIOC3A | 7 |
| 9 | ~ | P303 | GTIOC7B | 8 |
| 10 | ~ | P103 | GTIOC2A | 13 |
| 11 | ~ | P411 | GTIOC6A | 12 |
| 0 | P301 | GTIOC4B | 1 | |
| 1 | P302 | GTIOC4A | 0 | |
| 2 | P104 | GTIOC1B | 3 | |
| 4 | P106 | GTIOC0B | 5 | |
| 7 | P112 | GTIOC3B | 6 | |
| 8 | P304 | GTIOC7A | 9 | |
| 12 | P410 | GTIOC6B | 11 | |
| 13 | P102 | GTIOC2B | 10 | |
| 18 | P101 | GTIOC5A | 19 | |
| 19 | P100 | GTIOC5B | 18 |
If necessary, will update later.
Other notes:
The 32 bit timers are thos on Timers 0 and 1. For example pin 5 in the WIFI is 32 bits (D5 P107 GTIOC0A). Whereas times 2-7 are 16 bit timers.
Changing the frequency of one of the pins on a timer, updates it for all of the pins on the same timer. i.e. if you change it for pin 5 on the WIFI, it also changes it for Pin 4.
Wish the PwmOut object allowed you to set the pin number, outside of the constructor, such that it could be included into the servo object and not need to do a new of it, during the begin process.
Now to continue playing.
