ItsyBitsy M4 - Pololu PWM Frequency 20kHz

I am using an Arduino Uno R3 for a project. I want to stabilize the design (no more loose wires) but the only other board I have on hand is the ItsyBitsy M4. There are significant differences between the two, more than I know, but there is one part thus far I have been unable to compensate for, the PWM timer frequency.

I used the Arduino Uno R3 to control this Pololu motor driver Pololu G2 High-Power Motor Driver 24v21

They prepared code to operate the motor driver with an Arduino Uno (code snippet below). Their website says the following regarding the PWM frequency:

PWM frequency
The motor driver supports PWM frequencies as high as 100 kHz, but note that switching losses in the driver will be proportional to the PWM frequency. Typically, around 20 kHz is a good choice for sign-magnitude operation since it is high enough to be ultrasonic, which results in quieter operation.

A pulse on the PWM pin must be high for a minimum duration of approximately 0.5 µs before the outputs turn on for the corresponding duration (any shorter input pulse does not produce a change on the outputs), so low duty cycles become unavailable at high frequencies. For example, at 100 kHz, the pulse period is 10 µs, and the minimum non-zero duty cycle achievable is 0.5/10, or 5%

Inside the code they prepared, it changed timer1 for the Arduino Uno.

 // Set the frequency for timer1.
    #ifdef G2MOTORDRIVER_TIMER1_AVAILABLE
    if (_PWMPin == _PWM_TIMER1_PIN_A || _PWMPin == _PWM_TIMER1_PIN_B)
    {
        /**
         * Timer 1 Phase-Correct PWM configuration
         * prescaler: clockI/O / 1
         * outputs enabled
         * phase-correct PWM
         * top of 400
         *  PWM frequency calculation
         * 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = ~20kHz
         * The Timer/Counter Control Registers TCCRnA and TCCRnB hold the main control bits for the timer.
        **/
        TCCR1A = 0b10100000;
        TCCR1B = 0b00010001;
        ICR1 = 400;

I haven't the slightest idea how to change the ItsyBitsy M4 timer to ~20kHz. The SAMD51 spec sheet was overwhelming and I was not able to find any other specific tutorials. Can you tell me how to change the ItsyBitsy M4 timer1 to a ~20kHz frequency? If you advise that I change a different timer, please let me know which and how.

Or if this is unattainable without extensive work, perhaps I need to stick with the ATmega328 devices. Please advise

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.