Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
choafan2000
PostPosted: Feb 19, 2008 - 08:11 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


I have a UC3A1512 on an EVK1100 and I'm fairly new to programming uCs. I have been working through the examples and am trying to get the the uC running faster. So I wanted to know a little more about the high speed bus before i did something that might damage the uC. Is setting the HSB just like setting PBB and PBA (with the flash wait state set for speeds > 33 Mhz) or are there other settings i need to look into as well?

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
andreie
PostPosted: Feb 19, 2008 - 10:40 PM
Hangaround


Joined: Apr 12, 2005
Posts: 348
Location: Jõhvi, Estonia

I am not aware of any settings of HSB, it is locked to run at the core clock speed. Datasheet might be helpful.

OTOH the HSB matrix has plenty of settings, some of them are mentioned in the errata as well.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
choafan2000
PostPosted: Feb 19, 2008 - 11:00 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


pm_cksel has two arguments for 'High Speed Bus clock divisor enable' and 'High Speed Bus select' and the datasheet says I can use PLL0 for the CPU/HSB.

So I think that HSB/CPU speed are tied to each other, but i think i can set them together to be something other than their default values.

I may be mistaken though...
 
 View user's profile Send private message  
Reply with quote Back to top
sma
PostPosted: Feb 20, 2008 - 10:20 AM
Posting Freak


Joined: Jan 14, 2007
Posts: 1836
Location: Nantes, France

You have registers for each (HSB and CPU) but you MUST set the same value to both.

-sma
 
 View user's profile Send private message  
Reply with quote Back to top
choafan2000
PostPosted: Feb 20, 2008 - 01:45 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


Thanks sma,
So let me make sure i understand this correctly, HSB gets set like PBA and PBB using PM and PLL0. Where do i set CPU? Do they get set together or do i need to find and set the CPU register seperately?

is this MCSEL and MCCTRL?
 
 View user's profile Send private message  
Reply with quote Back to top
sma
PostPosted: Feb 20, 2008 - 07:24 PM
Posting Freak


Joined: Jan 14, 2007
Posts: 1836
Location: Nantes, France

In MCCTRL register, you can configure the main clock source frequency.
In CKSEL register, you can configure HSB, CPU, PBA, PBB clocks from main clock. Just make sure you apply the same conf for HSB and CPU (freqHSB must be equal to freqCPU).

-sma
 
 View user's profile Send private message  
Reply with quote Back to top
choafan2000
PostPosted: Feb 21, 2008 - 04:19 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


For instance my current code looks like

Code:

#include <avr32/io.h>
#include "board.h"
#include "pm.h"
#include "gpio.h"
#include "flashc.h"

#define FOSC_0     12000000 
#define OUTPUT_1   0          

void pllinitialize(void)
{

  volatile avr32_pm_t* pm = &AVR32_PM;
  pm_switch_to_osc0(pm, FOSC0, OSC0_STARTUP);
  pm_pll_setup(pm, 0, 10, 1, 0, 16);
  pm_pll_set_option(pm, 0, 1, 1, 0);
  pm_pll_enable(pm,0);
  pm_wait_for_pll0_locked(pm) ;
  pm_gc_setup(pm, 0, 1, 0, 0, 0);
  pm_gc_enable(pm, 0);
  pm_cksel(pm,1,0,1,0,0,0);

  flashc_set_wait_state(1);
 
  gpio_enable_module_pin(AVR32_PM_GCLK_0_0_PIN, AVR32_PM_GCLK_0_0_FUNCTION);
  pm_switch_to_clock(pm, AVR32_PM_MCCTRL_MCSEL_PLL0);

}

.
.
.




so if i change that to...
Code:
pm_cksel(pm,1,0,1,0,1,0);

is the CPU speed getting set by MCCTRL getting set in one of the other PM calls such as pm_switch_to_clock? or is there something i need to do in addition?
 
 View user's profile Send private message  
Reply with quote Back to top
sma
PostPosted: Feb 21, 2008 - 09:44 PM
Posting Freak


Joined: Jan 14, 2007
Posts: 1836
Location: Nantes, France

Nop, the CPU freq is only modified in the pm_cksel function.

-sma
 
 View user's profile Send private message  
Reply with quote Back to top
choafan2000
PostPosted: Feb 21, 2008 - 09:52 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


so the line
Code:
pm_cksel(pm,1,0,1,0,1,0);
should set PBA, PBB, HSB and CPU to 66MHz?
 
 View user's profile Send private message  
Reply with quote Back to top
choafan2000
PostPosted: Feb 25, 2008 - 06:07 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


If i run the following code and hook an oscilloscope up to PA00, i get a reading of ~211KHz.

Is this what you would expect from this code?
How do i increase that?

Please Advise.

Code:
#include <avr32/io.h>
#include "board.h"
#include "pm.h"
#include "gpio.h"
#include "flashc.h"

#define FOSC_0    12000000
#define OUTPUT_1  0

void pllinitialize(void)
{

  volatile avr32_pm_t* pm = &AVR32_PM;
  pm_switch_to_osc0(pm, FOSC0, OSC0_STARTUP);
  pm_pll_setup(pm, 0, 10, 1, 0, 16);
 
  pm_pll_set_option(pm, 0, 1, 1, 0);
  pm_pll_enable(pm,0);
  pm_wait_for_pll0_locked(pm) ;
  pm_gc_setup(pm, 0, 1, 0, 0, 0);
  pm_gc_enable(pm, 0);
  pm_cksel(pm,1,0,1,0,1,0);

  flashc_set_wait_state(1);
 
  gpio_enable_module_pin(AVR32_PM_GCLK_0_0_PIN, AVR32_PM_GCLK_0_0_FUNCTION);
  pm_switch_to_clock(pm, AVR32_PM_MCCTRL_MCSEL_PLL0);

}

void test(void)
{
  while(1)
   {
      gpio_tgl_gpio_pin(OUTPUT_1);
   }
}



int main(void)
{
  pllinitialize();
  test();
}
 
 View user's profile Send private message  
Reply with quote Back to top
choafan2000
PostPosted: Feb 26, 2008 - 09:50 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


Please People! You can not see this but I am on my knees typing this right now. I am on my knees because I am begging. Please help me. I want to learn. I want to be an AVR Freak. I want to understand. Please find it in the goodness of your AVR lovin' hearts to help a newb. Please.
 
 View user's profile Send private message  
Reply with quote Back to top
andreie
PostPosted: Feb 27, 2008 - 09:17 AM
Hangaround


Joined: Apr 12, 2005
Posts: 348
Location: Jõhvi, Estonia

Relax, take a deep breath, repeat after me: sky is not falling.

Copy the source code of the function "gpio_tgl_gpio_pin" into your forever loop and remove the slack.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
sma
PostPosted: Feb 27, 2008 - 07:28 PM
Posting Freak


Joined: Jan 14, 2007
Posts: 1836
Location: Nantes, France

Which frequency do you get on GCLK_0 pin ?

-sma
 
 View user's profile Send private message  
Reply with quote Back to top
choafan2000
PostPosted: Feb 27, 2008 - 10:29 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


I get 66 MHz on GLK_0.

I tried andreie's suggestion and it raised it from 211KHz to ~317KHz.

Does that seem like the flash running is running at the right speed?
 
 View user's profile Send private message  
Reply with quote Back to top
andreie
PostPosted: Feb 28, 2008 - 07:53 AM
Hangaround


Joined: Apr 12, 2005
Posts: 348
Location: Jõhvi, Estonia

choafan2000 wrote:
so the line
Code:
pm_cksel(pm,1,0,1,0,1,0);
should set PBA, PBB, HSB and CPU to 66MHz?

Perhaps that's the culprit. The documentation and sample code is as follows:
Code:
   /* Divide PBA clock by 2 from main clock (PBA clock = 48MHz/2 = 24MHz).
    Pheripheral Bus A clock divisor enable = 1
    Pheripheral Bus A select = 0
    Pheripheral Bus B clock divisor enable = 0
    Pheripheral Bus B select = 0
    High Speed Bus clock divisor enable = 0
    High Speed Bus select = 0
   */
   pm_cksel(pm, 1, 0, 0, 0, 0, 0);
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
choafan2000
PostPosted: Mar 01, 2008 - 05:54 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


changing pm_cksel to those settings resulted in increasing the frequency to ~635KHz.
This still seems slow to me, shouldnt i be able to get a speed of at least 30MHz?
 
 View user's profile Send private message  
Reply with quote Back to top
andreie
PostPosted: Mar 05, 2008 - 09:46 PM
Hangaround


Joined: Apr 12, 2005
Posts: 348
Location: Jõhvi, Estonia

635 kHz is terribly slow indeed.

Could you post the code?
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
choafan2000
PostPosted: Mar 05, 2008 - 09:48 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


andreie wrote:
635 kHz is terribly slow indeed.

Could you post the code?


Code:
#include <avr32/io.h>
#include "board.h"
#include "pm.h"
#include "gpio.h"
#include "flashc.h"

#define FOSC_0    12000000
#define OUTPUT_1  0

void pllinitialize(void)
{

  volatile avr32_pm_t* pm = &AVR32_PM;
  pm_switch_to_osc0(pm, FOSC0, OSC0_STARTUP);
  pm_pll_setup(pm, 0, 10, 1, 0, 16);
 
  pm_pll_set_option(pm, 0, 1, 1, 0);
  pm_pll_enable(pm,0);
  pm_wait_for_pll0_locked(pm) ;
  pm_gc_setup(pm, 0, 1, 0, 0, 0);
  pm_gc_enable(pm, 0);
  pm_cksel(pm,1,0,0,0,0,0);

  flashc_set_wait_state(1);
 
  gpio_enable_module_pin(AVR32_PM_GCLK_0_0_PIN, AVR32_PM_GCLK_0_0_FUNCTION);
  pm_switch_to_clock(pm, AVR32_PM_MCCTRL_MCSEL_PLL0);

}

void test(void)
{
  while(1)
   {
      gpio_tgl_gpio_pin(OUTPUT_1);
   }
}



int main(void)
{
  pllinitialize();
  test();
}

That's all of it, minus the included headers which were bundled w/ the software framework.

Thanks, I really appreciate any help i can get on this.
 
 View user's profile Send private message  
Reply with quote Back to top
andreie
PostPosted: Mar 05, 2008 - 10:15 PM
Hangaround


Joined: Apr 12, 2005
Posts: 348
Location: Jõhvi, Estonia

choafan2000 wrote:
Code:

...
      gpio_tgl_gpio_pin(OUTPUT_1);
...

I propose to roll up the sleeves and the open file DRIVERS/GPIO/gpio.c to look up what is making gpio_tgl_gpio_pin so slow.

Unfortunately I am currently using my home computer which doesn't have the Framework installed, thus I cannot be more specific.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
choafan2000
PostPosted: Mar 05, 2008 - 11:32 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


I just realized that actually that i posted old code, it runs at ~310KHz, the updated code that runs at 635KHz replaces that line with the content of that function as you earlier suggested. I will update this thread with the current code later.
 
 View user's profile Send private message  
Reply with quote Back to top
andreie
PostPosted: Mar 06, 2008 - 08:08 AM
Hangaround


Joined: Apr 12, 2005
Posts: 348
Location: Jõhvi, Estonia

Untested:
Code:

gpio_tgl_gpio_pin(OUTPUT_1);
for (;;) {
    AVR32_GPIO.port[OUTPUT_1 >> 5].ovrt = 1 << (OUTPUT_1 & 0x1F);
}
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
choafan2000
PostPosted: Mar 06, 2008 - 05:52 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


andreie wrote:
Untested:
Code:

gpio_tgl_gpio_pin(OUTPUT_1);
for (;;) {
    AVR32_GPIO.port[OUTPUT_1 >> 5].ovrt = 1 << (OUTPUT_1 & 0x1F);
}

Hmm, i didnt think to approach it like this. i will try this tomorrow morning and let you know what kind of results i get. Thanks again, i really do appreciate the help.
 
 View user's profile Send private message  
Reply with quote Back to top
choafan2000
PostPosted: Mar 07, 2008 - 06:47 PM
Rookie


Joined: Nov 30, 2007
Posts: 31


This did the trick, it shows up on the oscilloscope at ~4.175MHZ. It bounces fairly severely when switching. I will need to work on making the transitions cleaner but i think this will work for what i need it for.

THANKS A TON!
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits