Author Topic: [SAMC] Peripheral clock connection  (Read 1451 times)

0 Members and 1 Guest are viewing this topic.

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18835
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
[SAMC] Peripheral clock connection
« on: June 19, 2024, 09:23:12 am »
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.

 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 5966
  • Country: nl
Re: [SAMC] Peripheral clock connection
« Reply #1 on: June 19, 2024, 09:56:49 am »
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.

See chapter 15.


Quote
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.
So your statement seems right.

Quote
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?

No 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.

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18835
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [SAMC] Peripheral clock connection
« Reply #2 on: June 19, 2024, 10:45:06 am »
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
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12455
  • Country: us
    • Personal site
Re: [SAMC] Peripheral clock connection
« Reply #3 on: June 19, 2024, 02:16:10 pm »
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.
Alex
 

Online SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18835
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [SAMC] Peripheral clock connection
« Reply #4 on: June 19, 2024, 07:15:12 pm »
OK, so the section that will not accept more than 16MHz will only be clocked after the ADC is enabled I assume.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12455
  • Country: us
    • Personal site
Re: [SAMC] Peripheral clock connection
« Reply #5 on: June 19, 2024, 07:29:57 pm »
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.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf