Workflow

  1. 1.
    Create a GCLK generator configuration struct, which can be filled out to adjust the configuration of a single clock generator.
    struct system_gclk_gen_config gclock_gen_conf;
    
  2. 2.
    Initialize the generator configuration struct with the module's default values.
    system_gclk_gen_get_config_defaults(&gclock_gen_conf);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  3. 3.
    Adjust the configuration struct to request the master clock source channel 0 is used as the source of the generator, and set the generator output prescaler to divide the input clock by a factor of 128.
    gclock_gen_conf.source_clock    = SYSTEM_CLOCK_SOURCE_OSC16M;
    gclock_gen_conf.division_factor = 128;
    
  4. 4.
    Configure the generator using the configuration structure.
    system_gclk_gen_set_config(GCLK_GENERATOR_1, &gclock_gen_conf);
    
    Note: The existing configuration struct may be re-used, as long as any values that have been altered from the default settings are taken into account by the user application.
  5. 5.
    Enable the generator once it has been properly configured, to begin clock generation.
    system_gclk_gen_enable(GCLK_GENERATOR_1);
    
  6. 6.
    Create a GCLK channel configuration struct, which can be filled out to adjust the configuration of a single generic clock channel.
    struct system_gclk_chan_config gclk_chan_conf;
    
  7. 7.
    Initialize the channel configuration struct with the module's default values.
    system_gclk_chan_get_config_defaults(&gclk_chan_conf);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  8. 8.
    Adjust the configuration struct to request the previously configured and enabled clock generator is used as the clock source for the channel.
    gclk_chan_conf.source_generator = GCLK_GENERATOR_1;
    
  9. 9.
    Configure the channel using the configuration structure.
    system_gclk_chan_set_config(TC1_GCLK_ID, &gclk_chan_conf);
    
    Note: The existing configuration struct may be re-used, as long as any values that have been altered from the default settings are taken into account by the user application.
  10. 10.
    Enable the channel once it has been properly configured, to output the clock to the channel's peripheral module consumers.
    system_gclk_chan_enable(TC1_GCLK_ID);