16-bit PWM set for Nano R4 out-of-the-box?

I've been looking around to find if the PWM ready of the Nano R4 are all ready set to work in an 16-bit resolution ? I could not find it explicitly in the documentation. However, it seems that some PWM are set with an 8-bit resolution for the UNO R4. Since that they are sharing the same library that would be the case for the Nano R4.

Thanks for any answer.
Donald.

Are you sure that the Nano R4 PWM output can use 16 bits ?

From https://docs.arduino.cc/tutorials/nano-r4/user-manual/

By default, the resolution is 8-bit (0 to 255). You can use analogWriteResolution() to change this, supporting up to 12-bit (0 to 4095) resolution:

I'm certain it can support a 16-bit resolution as per manufacturer's datasheet, see below:

Thanks!

Check which resolutions the Arduino PWM library supports for the R4.

The timers on the Arduino Uno R3 are also capable of 16 bit PWM resolution, but very few people have reason to make use of that capability.

I needed to control a brushless motor (BLDC) or permanent magnet synchronous motor (PMSM) to drive the IGBTs and MOSFETs. A greater resolution means quality output sinewave. It's my understanding that the default resolution is 8-bits. I will then need to adjust the resolution.
Thanks everyone.

Hi @wrigd this example might help for basic 16bit PWM operation:
https://github.com/TriodeGirl/Arduino_UNO_R4_GPT16_Timer7_with_Interrupt

@wrigd and for fast Sine synthesis, see my code in this topic here:

https://forum.arduino.cc/t/waveform-synthesis-on-the-r4/1160999/21

ONE important NOTE, please remember with the R4 Minima or Nano to double-press the reset button to put the board into bootloader-mode each time - BEFORE doing a Code Flash update.

The IDE / programming-mode really doesn't like the fast 44.1 kHz timer interrupt running...

Nope

This example has nothing to do with 16bit resolution PWM

Timer1 has 16 bit PWM resolution. Study the data sheet to learn how to use it.

The Timer1 on Uno R3 has a 16bit counter. ~It is not a PWM resolution.~

You forgot to check the ATmega series data sheet. Get back to us when you've done that, and corrected your mistake.

Thanks for correction.
Yes, the resolution of the timer counter is a maximum PWM resolution too.
Timer1 on R3 CAN produce 16bit PWM.

Please clarify your statement, thanks.

First of all, it is not a hardware Timer PWM, but it is an interrupt based. This is a losing strategy. Using interrupts to PWM generation, you will very quickly hit the maximum interrupt frequency, above which the core will simply be unable to do anything else. As far as I saw in the comments, this happened at frequencies of about 44 kHz in this code, which is, of course, very low.
Using hardware timers, you can increase the frequency by several orders of magnitude.

And secondly, I did not find any mention of high-resolution PWM in the code at all. Correct me if I'm wrong.

Hi. Thank you for your reply, appreciated.

Okay, the timer is running hardware PWM which is updated by interrupt.

I needed to control a brushless motor (BLDC) or permanent magnet synchronous motor (PMSM) to drive the IGBTs and MOSFETs. A greater resolution means quality output sinewave.

To generate a two phase Sine/Cosine or three-phase Sine and ± 120° components requires a regular update, which is done inside the timer interrupt.

For motor control I would expect to run at 20kHz or above to eliminate audible switching noise (unless one is a cat or a dog). The 44.1kHz is because I was using code originally written to generate sines for an audio DAC on a RA4M1EK dev board.

Yes, of course one can use the timers asynchronously at which point the PWM can be much higher as you say.

At the moment I am running a UNO R4 Minima as the controller for a 10kHz rep-rate 1kV capacitor-charger (for a Vector-Inversion-Generator). This is running the timer interrupt at 100kHz - and yes, the USB serial communications still work.

As an aside I have also previously developed a Leonardo ATmega 32u4 based DDS stepper motor controller which runs at a 31.4kHz interrupt rate (in Phase Correst PWM mode) with 8 bit resolution. This uses an updatable table (rather than generating the Sine/Cosine on the fly) to which I can add 3rd, 5th, 7th, and 9th harmonics to compensate for detent-torque at low speeds. I am moving the code across to a R4 board so I can generate all the Sine/Cosines on the fly depending on motor profile.

And secondly…

Line 293:   *GPT167_GTPR   = 0x7FFF;     //
Line 294:   *GPT167_GTPBR  = 0x7FFF;     // 

… which in this example sets the overall PWM timer to 15 bit resolution.

See the RA4M1 datasheet, section 22.2.20 and 22.2.21 for register details.

So yes, perhaps I should add that detail to the comments for clarity. Thanks for pointing this out.

:slight_smile: