24.8.1.1.3 Workflow

  1. Create a module software instance structure for the TC module to store the TC driver state while it is in use.
    struct tc_module tc_instance;
    
    Note: This should never go out of scope as long as the module is in use. In most cases, this should be global.
  2. Configure the TC module.
    1. Create a TC module configuration struct, which can be filled out to adjust the configuration of a physical TC peripheral.
      struct tc_config config_tc;
      
    2. Initialize the TC configuration struct with the module's default values.
      tc_get_config_defaults(&config_tc);
      
      Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    3. Alter the TC settings to configure the counter width, wave generation mode, and the compare channel 0 value.
      config_tc.counter_size    = TC_COUNTER_SIZE_16BIT;
      config_tc.wave_generation = TC_WAVE_GENERATION_NORMAL_PWM;
      config_tc.counter_16_bit.compare_capture_channel[0] = (0xFFFF / 4);
      
    4. Alter the TC settings to configure the PWM output on a physical device pin.
      config_tc.pwm_channel[0].enabled = true;
      config_tc.pwm_channel[0].pin_out = PWM_OUT_PIN;
      config_tc.pwm_channel[0].pin_mux = PWM_OUT_MUX;
      
    5. Configure the TC module with the desired settings.
      tc_init(&tc_instance, PWM_MODULE, &config_tc);
      
    6. Enable the TC module to start the timer and begin PWM signal generation.
      tc_enable(&tc_instance);