Tiny412 - Problem changing Main clock prescaler

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

 

I try to change the main clock prescaler without success

 

1. When CPU starts register defaults to: CLKCTRL.MCLKCTRLB = 0x11 (Prescaler enabled, CLK_PER = OSC20M / 6)

2. In my code I add: CLKCTRL.MCLKCTRLB = 0x13 (Prescaler enabled, CLK_PER = OSC20M / 10)

3. But it takes no effect

    When halting code (AtmelStudio7) and checking register, it is still: CLKCTRL.MCLKCTRLB = 0x11

 

Note:

    CLKCTRL.MCLKLOCK = 0 (Not locked)

    CLKCTRL.MCLKSTATUS = 0x10 (20MHz stable)

 

When halted I can manipulate the register to CLKCTRL.MCLKCTRLB = 0x13 (AtmelStudio7) and release the code

Now the clock is changed and works like intended

What Im I missing here?

 

/Conny

 

 

 

This topic has a solution.

Can

Last Edited: Thu. Nov 14, 2019 - 09:46 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

can@aros.se wrote:
What Im I missing here?

 

You are probably missing the CCP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It depends what toolchain you use but if it is GCC then search out _PROTECTED_WRITE()

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

in your clock control settings, you must set the CCP, otherwise your prescaler setting will not go through...in Tiny412 (X-MEGA) like...this is done like this:

 

int8_t CLKCTRL_init()
{
    ccp_write_io((void *)&(CLKCTRL.MCLKCTRLB),
    CLKCTRL_PDIV_4X_gc /* 4 */
    | 1 << CLKCTRL_PEN_bp /* Prescaler enable: enable */);
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

or as clawson said..

Last Edited: Thu. Nov 14, 2019 - 02:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thx all, CCP was the problem...

It works perfectly now

Can

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perfect, Please tick your thread as solved.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Were do I do that?

Can

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

Mark solution...

------------------------------------------------------------------

Source: awneil signature

Last Edited: Thu. Nov 14, 2019 - 09:51 AM