Setting up UC3 clock

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

Hi, I have a custom board that uses an AT32UC3AO256 and created a new project using the user application template for the User Board - UC3A0/A1. So far all good. I set up some I/O using gpio functions and all worked perfectly. I then decided to use the external 12MHz xtal OCS0 so i added the asf clock control module and added the following to user_board.h

#define BOARD_OSC0_HZ             12000000
#define OSC_ID_OSC0               0    //!< External Oscillator 0
#define BOARD_OSC0_STARTUP_US     OSC_STARTUP_4096   

Code all compiled ok but no go as it hangs on waiting for the xtal to satrt so i am obviously missing something in board.h

I tried the following code:

//Configure the oscillator 0 in crystal mode.
AVR32_PM.oscctrl0=AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3<<AVR32_PM_OSCCTRL0_MODE_OFFSET | 3<<AVR32_PM_OSCCTRL0_STARTUP_OFFSET;
  //Enable the oscillator 0.
  AVR32_PM.mcctrl |= AVR32_PM_MCCTRL_OSC0EN_MASK;
  //Wait for oscillator 0 to be ready.
  while (!(AVR32_PM.poscsr & AVR32_PM_POSCSR_OSC0RDY_MASK));
  //Switch main clock from internal RC oscillator to oscillator 0.
  AVR32_PM.mcctrl |= AVR32_PM_MCCTRL_MCSEL_OSC0;

and all worked perfectly.

So basically i wnat to get the asf code going.

Any help would be greatly appreciated.

Regards

Paul

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

Hello Paul,

Have you looked up the ASF online documentation, more specifically this
http://asf.atmel.com/docs/3.0.1/uc3a/html/group__sysclk__group.html ?
The function sysclk_init() is very common in the asf example. Unfortunately I can't help you more than that as I didn't have the time yet to play with my UC3L0 Xplained board, but I hope it could helped you a little...

Have a nice day,
Kraal

Have a nice day,
Kraal

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

Hey Kraal, thanks for the reply. I have an xplained board and can get that working with no issues. So that is not the issue. Its the user board template that i am having trouble setting up as far as the clock goes

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

Hello again Paul,

I am like you, the asf looks great to use, but it seems to me that the learning process is a bit harder than it should, regarding what function to call with what parameters/defines...Sorry that I can't help you with this,

Have a nice day,
Kraal

Have a nice day,
Kraal

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

if you want to use sysclk_init() you have to edit conf_clock.h.

By default the RC cicuit is used as clock. If you want to use the oscilator, you also have to define crystal characteristics. I'm using a user board with a UCB0512 and use the following defines:

#define BOARD_OSC0_HZ             12000000 
#define BOARD_OSC0_TYPE           XOSC_TYPE_XTAL
#define BOARD_OSC0_IS_XTAL        true 
#define BOARD_OSC0_STARTUP_US     17000

You used OSC_STARTUP_4096 but that symbol is not expanded to a startup delay in useconds. It is expanded to the value 4 instead. This value is to be set in the registry at the end. sysclk_init will calculate the proper value based on the delay in us.

If you specify

#define CONFIG_SYSCLK_SOURCE      SYSCLK_SRC_OSC0

in conf_clock.h youre processor will use the oscilator and will run at 12 MHz.

For higher frequencies you have to switch to the a PLL. Specify the following in conf_clock.h:

#define CONFIG_SYSCLK_SOURCE      SYSCLK_SRC_PLL0
#define CONFIG_PLL0_MUL      10
#define CONFIG_PLL0_DIV       2

And your processor will run on 60 MHz, which is the maximum for the UC3B series. To get a frequency of 66 MHz (maximum for the A series) change the multiplier to 11.

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

Kraal wrote:
Hello again Paul,

I am like you, the asf looks great to use, but it seems to me that the learning process is a bit harder than it should, regarding what function to call with what parameters/defines...Sorry that I can't help you with this,

Have a nice day,
Kraal

I concur, the documentation is lousy. Proper documentation includes some information about how to use the functions, not just a function definition and some (in most cases) poorly documented examples.

I have struggled quite some time to get started with the framework. The best way is to look at the source code what is actually happening. You also have to check the datasheet for registers modified, only then you have a change to understand what is happening.

And last but not least, not all code is perfect. I have rewritten the driver for SPI Flash memory. At one hand the driver is over complete (I don not want to deal with up to for different external chips), at the other hand it is incomplete (some functionality I need is missing). The SPI driver it self is also far from perfect and is another component I rewrote.

Apart from these minor inconveniences I am still happy with the framework, its free and improved frequently. If only that documentation ….

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

Hi rob.aarnts, that worked perfectly. Thanks so much for your help. Greatly appreciated. As you say and i agree ASF has potential but documentation is crap. Is there someone from atmel reading this and would like to comment.

I will say that for a user board which i have you need to add the code to user_board.h for the ext xtal to work.

Regards Paul

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

so to clarify for anyone who wants to use the code for an ext crystal add this code to user_board.h

#ifndef USER_BOARD_H
#define USER_BOARD_H

/* This file is intended to contain definitions and configuration details for
 * features and devices that are available on the board, e.g., frequency and
 * startup time for an external crystal, external memory devices, LED and USART
 * pins.
 */

#define BOARD_OSC0_HZ             12000000 
#define BOARD_OSC0_TYPE           XOSC_TYPE_XTAL 
#define BOARD_OSC0_IS_XTAL        true 
#define BOARD_OSC0_STARTUP_US     17000 

#endif // USER_BOARD_H
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Will also add the the ASF has so much potential. Will be glad when it becomes a stable release. As far as my avr32 project goes it has simplified the learning procedure.

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

rob.aarnts wrote:
....... For higher frequencies you have to switch to the a PLL. Specify the following in conf_clock.h:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_PLL0 #define CONFIG_PLL0_MUL 10 #define CONFIG_PLL0_DIV 2

And your processor will run on 60 MHz, which is the maximum for the UC3B series. To get a frequency of 66 MHz (maximum for the A series) change the multiplier to 11.

 

I understand this is an old thread. But the different posts there in has helped me in some way to setup USART on a UC3A mcu. I could use the 

SYSCLK_SRC_OSC0

which in my case runs at 16MHz.

 

As your post suggest (and as quoted above), I am trying to use the USART at higher frequencies with the PLL0, and I followed this setting as above. Unfortunately, I could not get anything on my USART. Looks like my PLL did not switch ON. I need some suggestions on how to get this done, as I am a newbie to programming of mcu's.