21.8.2.1.3 Workflow
- 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;
- 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. - 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;
- 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. - Enable the generator once it has been properly configured, to begin clock generation.
system_gclk_gen_enable(GCLK_GENERATOR_1);
- 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;
- 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. - 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;
- 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. - 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);