[SAMC] Peripheral clock connection - Page 1
Forum section: electronics / general

author: Simon
author_rank: Unknown
timestamp: June 19, 2024, 09:23:12 am
content: I'm a little confused about how the clock connection to the peripherals works on a SAMC (atmel/microchip). I don't know if the same sort of system is used on other ARM based MCU's.There are registers in the MAIN CLOCK that have bits to enable the clock to peripherals, this seems to me to be more about the peripherals register/bus interface rather than the actual bulk of the peripheral.Then there are registers in the GCLK controller that select the clock generator for each peripheral.So are these two one and the same thing? do I enable them together? Or is the GLCK only needed when I enable the peripheral?OK so I am writing the ADC setup code, I can set the prescaler without the peripheral clock channel enabled, but the CTRLC register never synchronises without the clock. As I run the ADC from 48MHz but the converter itself must run from at most 16MHz I need to set the prescaler, does this need setting before anything else will work ? At the moment i set the prescaler then enable the peripheral clock channel, it seems to work.

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 19, 2024, 09:56:49 am
content: A quick scan of the SAM C20/C21 family datasheet shows me that you need to enable both clocks to get it to work.The MCLK is needed to interface with the peripheral via the CPU busses and the GCLK is needed to drive the actual peripheral logic. When the MCLK is not enabled the peripheral registers will read zero.Seechapter 15.QuoteSo your statement seems right.QuoteNo not the same, but in order to use a peripheral you most likely have to enable them both for that given peripheral.Appears to be a different setup in comparison with the STM devices, but it allows for a wider range of peripheral clock speeds. So more flexibility.

author: Simon
author_rank: Unknown
timestamp: June 19, 2024, 10:45:06 am
content: Yes I get that the main clock interface needs to be enabled in order to set registers. It's more a case of do I need to connect the peripheral clock channel as well to do the setup. Well I seem to have the answer to this, yes, but.I am starting to suspect that where the registers have a write synchronization features these are possibly tied up with the peripheral clock as well, else the synchronization would not be necessary as the bus speed is the main clock speed but if the register depends on the peripheral clock as well it could be running slower than the speed at which the CPU can update it.So the CTRLB register does not need synchronization, I can edit this with just the main clock, but to access CTRLC I need to connect the peripheral clock. I did not want to connect the peripheral clock before the prescaler was set as the ADC itself cannot run at the default speed while the specifications say that the ADC runs off 48MHz

author: ataradov
author_rank: Super Contributor
timestamp: June 19, 2024, 02:16:10 pm
content: Both clocks must be enabled before any of the registers are accessed. This is necessary and guaranteed to be safe.Specification tells the maximum input clock to the peripheral itself. Then you have the actual conversion clock, which is achieved though the prescaler.

author: Simon
author_rank: Unknown
timestamp: June 19, 2024, 07:15:12 pm
content: OK, so the section that will not accept more than 16MHz will only be clocked after the ADC is enabled I assume.

author: ataradov
author_rank: Super Contributor
timestamp: June 19, 2024, 07:29:57 pm
content: Yes, you set the prescaler first, but no actual internal prescaled clock is generated until you enable the ADC.In general, there is no physical harm in overclocking the ADC or any other peripheral. It is just analog performance would suffer until you get the clock into a correct range. It is still better to not overclock things, of course.