ATtiny817 Xplained Mini Clock Configuration

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

As the Title summarizes , I am trying to configure the clock source for the main clock through Low Power 32khz Oscillator, but even after that my main clock is using the internal clock Oscillator of 8MHz. Kindly check whether the configuration is correct and help in identifying the issue.

CCP = CCP_IOREG_gc; //Disabling the Configuration Change Protection
CLKCTRL.MCLKCTRLA = CLKCTRL_CLKSEL_OSCULP32K_gc;
CCP = CCP_IOREG_gc; //Disabling the Configuration Change Protection
CLKCTRL_OSC32KCTRLA = CLKCTRL_RUNSTDBY_bm;//Enabling Low Power Oscillator to run in all modes
while(!(CLKCTRL_MCLKSTATUS & (CLKCTRL_OSC32KS_bm))) //Checking whether the Oscillator is Stable
;

 

Thanks,

Jaivvignesh | Associate Firmware Developer

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

Depending on the compiler optimization settings, this code may not be in time.

 

CCP = CCP_IOREG_gc; // Disabling the Configuration Change Protection
CLKCTRL.MCLKCTRLA = CLKCTRL_CLKSEL_OSCULP32K_gc;

 

It is appropriate to use a prepared macro.

And don't switch the main clock to it until OSC32K is stable. It ’s very dangerous.

    CLKCTRL_OSC32KCTRLA = CLKCTRL_RUNSTDBY_bm;//Enabling Low Power Oscillator to run in all modes
    while(!(CLKCTRL_MCLKSTATUS & (CLKCTRL_OSC32KS_bm))); //Checking whether the Oscillator is Stable
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, !CLKCTRL_PEN_bm);
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, CLKCTRL_CLKSEL_OSCULP32K_gc);

 

 

 

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

Thank for you the reply Sir, 

I still have a doubt that, Why will the code not be in time,  why not the next instruction after disabling will not complete within four clock pulses ? The header file to be included for using the macro. 

Adding to that on seeing the processor status while debugging still the frequency is still 1MHz

Thanks,

Jaivvignesh | Associate Firmware Developer

Last Edited: Sat. Sep 28, 2019 - 09:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First we must apologize.
If you waited for stability before switching the main clock, you fell into an infinite loop. I had the assumption that this feature is the same as xmega.

 

The following code must be executed within 4 clocks, but at the lowest optimization level, the machine code generated by the compiler takes 10 clocks or more.
To avoid such a situation, sages have prepared a macro that does not depend on the optimization level.

CCP = CCP_IOREG_gc; //Disabling the Configuration Change Protection
CLKCTRL.MCLKCTRLA = CLKCTRL_CLKSEL_OSCULP32K_gc;

 

The _PROTECTED_WRITE macro can be used without including a special header file.
When I tried the following code on a similar chip, tiny1616, I got the intended CLKOUT.

#include <avr/io.h>
int main(void){
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, !CLKCTRL_PEN_bm);
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, CLKCTRL_CLKOUT_bm | CLKCTRL_CLKSEL_OSCULP32K_gc);
    while (1){
    }
}

 

 

 

The default clock of tiny817 is 3.33MHz, and the clock will not become 1MHz unless it is set intentionally.

 

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

I haven't waited for any kind of stability before switching the main clock, as default the 16MHz oscillator runs with respect to fuse bits configuration. I was getting the power consumption of about 1 milli ampere rather than 11 micro ampere if it is being correctly for the Low power oscillator.This is the sequence I have followed for  changing the clock source as of now

_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, !CLKCTRL_PEN_bm);
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, CLKCTRL_CLKSEL_OSCULP32K_gc);
while(!(CLKCTRL_MCLKSTATUS & (CLKCTRL_OSC32KS_bm))); //Checking whether the Oscillator is Stable
_PROTECTED_WRITE(CLKCTRL_OSC32KCTRLA,  CLKCTRL_RUNSTDBY_bm); //Enabling Low Power Oscillator to run in all modes

Thanks,

Jaivvignesh | Associate Firmware Developer

Last Edited: Mon. Sep 30, 2019 - 05:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see, you are using the simulator mode.
That 1MHz does not reflect anything.
It became 10MHz in my environment.
However, if you run it on a real chip, you will get # 4 result.

 

The table shows only the current consumption of the core, not the current consumption of the entire chip including peripheral circuits.

 

The default fuse setting selects the 20MHz oscillator. And at startup, the 1/6 prescaler is enabled.

 

 

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

Sir, what is the power consumption you are getting? Is there any possibility of contacting you through official maid id?

Thanks,

Jaivvignesh | Associate Firmware Developer

Last Edited: Mon. Sep 30, 2019 - 11:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I ran this program on tiny1616 and measured the current.
Current consumption at 3V was about 11.5uA.
However, this code disables UPDI. Never run if you don't have a 12V programming environment.

 

#include <avr/io.h>

// FUSE settings
FUSES = {
    .WDTCFG     = FUSE_WDTCFG_DEFAULT,
    .BODCFG     = FUSE_BODCFG_DEFAULT,
    .OSCCFG     = FUSE_OSCCFG_DEFAULT,
//  .SYSCFG0    = FUSE_SYSCFG0_DEFAULT,
    .SYSCFG0    = 0xC0,                 // Disable UPDI
    .SYSCFG1    = FUSE_SYSCFG1_DEFAULT,
    .APPEND     = FUSE_APPEND_DEFAULT,
    .BOOTEND    = FUSE_BOOTEND_DEFAULT,
};

int main(void){
    PORTA_PIN0CTRL =
    PORTA_PIN1CTRL =
    PORTA_PIN2CTRL =
    PORTA_PIN3CTRL =
    PORTA_PIN4CTRL =
    PORTA_PIN5CTRL =
    PORTA_PIN6CTRL =
    PORTA_PIN7CTRL =
    PORTB_PIN0CTRL =
    PORTB_PIN1CTRL =
    PORTB_PIN2CTRL =
    PORTB_PIN3CTRL =
    PORTB_PIN4CTRL =
    PORTB_PIN5CTRL =
    PORTC_PIN0CTRL =
    PORTC_PIN1CTRL =
    PORTC_PIN2CTRL =
    PORTC_PIN3CTRL =
    PORT_ISC_INPUT_DISABLE_gc;

    _PROTECTED_WRITE(CLKCTRL.OSC32KCTRLA, CLKCTRL_RUNSTDBY_bm);
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, !CLKCTRL_PEN_bm);
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, !CLKCTRL_CLKOUT_bm | CLKCTRL_CLKSEL_OSCULP32K_gc);
    while (!(CLKCTRL.MCLKSTATUS & CLKCTRL_OSC32KS_bm));

    while (1){
    }
}

 

Postscript
Even with UPDI enabled, if the debugger was not connected, no difference in current consumption was seen.
There seems to be no need to make dangerous settings.

Last Edited: Tue. Oct 1, 2019 - 02:11 AM