Changing duty cycle

I have this code that produces a pulse on the adafruit feather m4 express and i can already use the serial monitor to change the frequency. I'd like to know how to change the duty cycle.

const uint8_t outputPin = 5;
volatile bool flag = false;
float currentFreq = 50.0;  // default frequency (Hz)


void TC3_Handler(void) {
  if (TC3->COUNT16.INTFLAG.bit.MC0) {
    TC3->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0;
    flag = true;
  }
}


void setTimerFrequency(float freq) {
  if (freq < 0.1 || freq > 200000) return;


  currentFreq = freq;


  uint32_t compareValue = (120000000.0 / 1024.0) / freq;


  TC3->COUNT16.CC[0].reg = compareValue;
  while (TC3->COUNT16.SYNCBUSY.bit.CC0)
    ;


  Serial.print("Frequency updated to: ");
  Serial.print(freq);
  Serial.println(" Hz");
  Serial.print("CC0 = ");
  Serial.println(compareValue);
}


void setup() {
  Serial.begin(115200);
  delay(1500);
  Serial.println("Booted");
  Serial.println("Enter frequency in Hz:");


  pinMode(outputPin, OUTPUT);


  // ---- Enable clock for TC3 ----
  MCLK->APBBMASK.reg |= MCLK_APBBMASK_TC3;
  GCLK->PCHCTRL[TC3_GCLK_ID].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN_GCLK0;


  TC3->COUNT16.CTRLA.bit.SWRST = 1;
  while (TC3->COUNT16.SYNCBUSY.bit.SWRST)
    ;


  TC3->COUNT16.CTRLA.reg =
    TC_CTRLA_MODE_COUNT16 | TC_CTRLA_PRESCALER_DIV1024;


  TC3->COUNT16.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;


  setTimerFrequency(currentFreq);


  TC3->COUNT16.INTENSET.reg = TC_INTENSET_MC0;
  NVIC_EnableIRQ(TC3_IRQn);


  TC3->COUNT16.CTRLA.bit.ENABLE = 1;
  while (TC3->COUNT16.SYNCBUSY.bit.ENABLE)
    ;


  Serial.println("Timer enabled");
}


void loop() {


  // Toggle pin from ISR flag
  if (flag) {
    flag = false;
    digitalWrite(outputPin, !digitalRead(outputPin));
  }


  // Serial frequency update
  if (Serial.available()) {
    String input = Serial.readStringUntil('\n');
    float newFreq = input.toFloat();


    if (newFreq > 0) {
      setTimerFrequency(newFreq);
    }
  }
}

I ran this on a MKRFOX 1200

// MKRFOX 1200 (SAMS21) timer test - generate 20KHz pulse 30% duty cycle on pin 1

// from g https://github.com/khoih-prog/SAMD_TimerInterrupt

#if !(defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
      || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \
      || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) \
      || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD51__) || defined(__SAMD51J20A__) \
      || defined(__SAMD51J19A__) || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) \
      || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \
      || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \
      || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__))
#error This code is designed to run on SAMD21/SAMD51 platform! Please check your Tools->Board setting.
#endif

/////////////////////////////////////////////////////////////////

// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
// Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
#define TIMER_INTERRUPT_DEBUG 0
#define _TIMERINTERRUPT_LOGLEVEL_ 0

// Select only one to be true for SAMD21. Must must be placed at the beginning before #include "SAMDTimerInterrupt.h"
#define USING_TIMER_TC3 true   // Only TC3 can be used for SAMD51
#define USING_TIMER_TC4 false  // Not to use with Servo library
#define USING_TIMER_TC5 false
#define USING_TIMER_TCC false
#define USING_TIMER_TCC1 false
#define USING_TIMER_TCC2 false  // Don't use this, can crash on some boards

#include "SAMDTimerInterrupt.h"

#define SQUARE_WAVE_PIN 1  // pin to output square wave

#define TIMER_INTERVAL_US 5  // timer interval in uSec

#if (TIMER_INTERRUPT_USING_SAMD21)

#if USING_TIMER_TC3
#define SELECTED_TIMER TIMER_TC3
#elif USING_TIMER_TC4
#define SELECTED_TIMER TIMER_TC4
#elif USING_TIMER_TC5
#define SELECTED_TIMER TIMER_TC5
#elif USING_TIMER_TCC
#define SELECTED_TIMER TIMER_TCC
#elif USING_TIMER_TCC1
#define SELECTED_TIMER TIMER_TCC1
#elif USING_TIMER_TCC2
#define SELECTED_TIMER TIMER_TCC
#else
#error You have to select 1 Timer
#endif

#else

#if !(USING_TIMER_TC3)
#error You must select TC3 for SAMD51
#endif

#define SELECTED_TIMER TIMER_TC3

#endif

// Init selected SAMD timer
SAMDTimer ITimer(SELECTED_TIMER);

// timer interrupt routine - set up 30% duty cycle
volatile int counter, duty_ON = 3, duty_OFF = 10 - duty_ON, duty = 0;
void TimerHandler() {
  counter++;
  if (duty++ < duty_ON)                 // test ON or OFF
    digitalWrite(SQUARE_WAVE_PIN, 1);   // ON
  else
    digitalWrite(SQUARE_WAVE_PIN, 0);   // OFF
  if (duty > 9) duty = 0;               // reset start of duty cycle
}

void setup() {
  pinMode(SQUARE_WAVE_PIN, OUTPUT);
  Serial.begin(115200);
  while (!Serial && millis() < 5000)
    ;
  delay(100);
  Serial.print(F("\nStarting TimerInterruptTest on "));
  Serial.println(BOARD_NAME);
  Serial.println(SAMD_TIMER_INTERRUPT_VERSION);
  Serial.print(F("CPU Frequency = "));
  Serial.print(F_CPU / 1000000);
  Serial.println(F(" MHz"));

  // Interval in microseconds
  if (ITimer.attachInterruptInterval(TIMER_INTERVAL_US, TimerHandler)) {
  } else
    Serial.println(F("Can't set ITimer. Select another freq. or timer"));
}

void loop() {
  // ecery second print interupt counter
  static long timer = millis();
  if (millis() - timer > 1000) {
    timer = millis();
    Serial.println(counter);
    counter = 0;
  }
}

gave 20KHz (period 50uSe) pulses 30% duty cycle

Frequency is how often the cycle occurs.
Duty cycle is the ratio of HIGH-time to LOW-time.

  +-----+     +-----+     +-----+
  |     |     |     |     |     |     |
--+     +-----+     +-----+     +-----+  50% duty

  +-------+   +-------+   +-------+
  |       |   |       |   |       |   |
--+       +---+       +---+       +---+ 75% duty
              ^           ^           ^
            cycle.      cycle       cycle

Spend a bit of time researching PWM, which is built in in most Arduinos.