In this use-case, the GCLK module is configured for:
- One generator attached to the internal 8MHz RC oscillator clock source
- Generator output equal to input frequency divided by a factor of 128
- One channel (connected to the TC0 module) enabled with the enabled generator selected
This use-case configures a clock channel to output a clock for a peripheral within the device, by first setting up a clock generator from a master clock source, and then linking the generator to the desired channel. This clock can then be used to clock a module within the device.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your user application:
{
#if (SAML21) || (SAML22) || (SAMR30)
gclock_gen_conf.division_factor = 128;
#elif (SAMC21)
gclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_OSC48M;
gclock_gen_conf.division_factor = 128;
#else
gclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_OSC8M;
gclock_gen_conf.division_factor = 128;
#endif
}
{
#if (SAMD10) || (SAMD11) || SAMR30
#else
#endif
}
Add to user application initialization (typically the start of main()
):
Workflow
- Create a GCLK generator configuration struct, which can be filled out to adjust the configuration of a single clock generator.
- Initialize the generator configuration struct with the module's default values.
- 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.division_factor = 128;
- Configure the generator using the configuration structure.
- 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.
- Create a GCLK channel configuration struct, which can be filled out to adjust the configuration of a single generic clock channel.
- Initialize the channel configuration struct with the module's default values.
- 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.
- Configure the channel using the configuration structure.
- 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.
Use-case
Code
Copy-paste the following code to your user application:
Workflow
- As the clock is generated asynchronously to the system core, no special extra application code is required.