UC3A3, clock settings and ADC.

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

Hi, I recently discussed clock settings and UC3A3 on this form, and I changed my settings according to that discussion.

I changed from my settings:

pcl_freq_param_t pcl_freq_param =
{
  .cpu_f        = APPLI_CPU_SPEED,
  .pba_f        = APPLI_PBA_SPEED,
  .osc0_f       = FOSC0,
  .osc0_startup = OSC0_STARTUP
};
	// Configure system clocks.
	pcl_configure_clocks(&pcl_freq_param);

	// Switch to external oscillator 0.
	pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

To:

AVR32_PM.oscctrl0 = (AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC << AVR32_PM_OSCCTRL0_STARTUP_OFFSET) | (AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3    << AVR32_PM_OSCCTRL0_MODE_OFFSET);
AVR32_PM.mcctrl = AVR32_PM_MCCTRL_OSC0EN_MASK;

// Wait for it to be stable
while (!(AVR32_PM.poscsr & AVR32_PM_POSCSR_OSC0RDY_MASK));

// Switch to it
AVR32_PM.mcctrl = AVR32_PM_MCCTRL_OSC0EN_MASK | AVR32_PM_MCSEL_OSC0;

// Setup PLL0 on Osc0, mul=4 ,no divisor, lockcount=16: 12MHzx10 = 120MHz output
pm_pll_setup(&AVR32_PM,
    0,   // pll.
    4,   // mul.
    0,   // div.
    0,   // osc.
    16); // lockcount.

// PLL output VCO frequency is 120MHz.
// We divide it by 2 with the pll_div2=1 to get a main clock at 60MHz.
pm_pll_set_option(&AVR32_PM,
    0,  // pll.
    1,  // pll_freq.
    1,  // pll_div2.
    0); // pll_wbwdisable.

// Enable the PLL.
pm_pll_enable(&AVR32_PM, 0);

// Enable 1 wait-state mode for the flash
flashc_set_wait_state(1);

// Configure CPU/HSB for 60MHz and PBA/PBB for 30MHz
pm_cksel(&AVR32_PM,
    0,  // pbadiv.
    0,  // pbasel.
    0,  // pbbdiv.
    0,  // pbbsel.
    0,  // hsbdiv=cpudiv
    0); // hsbsel=cpusel

// Wait until the PLL output is stable.
while (!(AVR32_PM.poscsr & AVR32_PM_POSCSR_LOCK0_MASK));

// Switch the main clock source to PLL0.
pm_switch_to_clock(&AVR32_PM, AVR32_PM_MCCTRL_MCSEL_PLL0);

And it seemed to work all right.

But now when I wanted to make some changes to the temperature measurements that are made using the internal ADC, it was behaving very strange. Like I had a lot less resolution. I did some experimenting and finally changed back the clock to the initial way, and then it works.

Any suggestions?

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

What is your ADC clock frequency ?

Datasheet 36.9 ADC Characteristics says that the maximum ADC clock frequency is 5MHz in 10-bit resolution mode.

From 7.6.3 Clock Mask Registers The ADC is on the PBA bus.
Look at 7.6.2 Clock Select Register because your comment // Configure CPU/HSB for 60MHz and PBA/PBB for 30MHz is not correct.

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

Thanks. I think that did it. I went to my ADC setup function and found

AVR32_ADC.mr |= 0x1 << AVR32_ADC_MR_PRESCAL_OFFSET;

Which should mean a scaling of 4. I changed it to

AVR32_ADC.mr |= 0x5 << AVR32_ADC_MR_PRESCAL_OFFSET;

which should be a scaling of 12.

The comment error then, it sais 60 MHz for CPU/HSB and 30 MHz for PBA, PBB. But then the pbadiv and pbbdiv should be 1? Is that what you mean? Then I will get 30 MHz PBA and PBB.

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

Yes., the comment did not match the settings you had for pm_cksel(&AVR32_PM, ,,,,, )

I only had 2 coffees when I replied :(

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

Hi, I am struggling with noise (hiss) on the output of my ABDAC and I thought perhaps it is a result of not setting up my clocks correctly. I have search all the noise related forums with not luck. I have tried several filter topologies and the differential amp approach, still no luck.

Nonetheless, I noticed that ("AgwanII" code):

1,  // pll_freq.

Should this not be set to 0 since VCO frequency is 120MHz. (80HMhz < fVCO < 180Mhz). I am refering to page 60 of the UC3A3 datasheet PLLOPT[0] field in the PLL register.

Perhaps I should start a new topic for my noise ABDAC noise issue, but I try the current topics first.

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

AgwanII wrote:
Hi, I recently discussed clock settings and UC3A3 on this form, and I changed my settings according to that discussion.

I changed from my settings:

pcl_freq_param_t pcl_freq_param =
{
  .cpu_f        = APPLI_CPU_SPEED,
  .pba_f        = APPLI_PBA_SPEED,
  .osc0_f       = FOSC0,
  .osc0_startup = OSC0_STARTUP
};
	// Configure system clocks.
	pcl_configure_clocks(&pcl_freq_param);

	// Switch to external oscillator 0.
	pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

To:

AVR32_PM.oscctrl0 = (AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC << AVR32_PM_OSCCTRL0_STARTUP_OFFSET) | (AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3    << AVR32_PM_OSCCTRL0_MODE_OFFSET);
AVR32_PM.mcctrl = AVR32_PM_MCCTRL_OSC0EN_MASK;

// Wait for it to be stable
while (!(AVR32_PM.poscsr & AVR32_PM_POSCSR_OSC0RDY_MASK));

// Switch to it
AVR32_PM.mcctrl = AVR32_PM_MCCTRL_OSC0EN_MASK | AVR32_PM_MCSEL_OSC0;

// Setup PLL0 on Osc0, mul=4 ,no divisor, lockcount=16: 12MHzx10 = 120MHz output
pm_pll_setup(&AVR32_PM,
    0,   // pll.
    4,   // mul.
    0,   // div.
    0,   // osc.
    16); // lockcount.

// PLL output VCO frequency is 120MHz.
// We divide it by 2 with the pll_div2=1 to get a main clock at 60MHz.
pm_pll_set_option(&AVR32_PM,
    0,  // pll.
    1,  // pll_freq.
    1,  // pll_div2.
    0); // pll_wbwdisable.

// Enable the PLL.
pm_pll_enable(&AVR32_PM, 0);

// Enable 1 wait-state mode for the flash
flashc_set_wait_state(1);

// Configure CPU/HSB for 60MHz and PBA/PBB for 30MHz
pm_cksel(&AVR32_PM,
    0,  // pbadiv.
    0,  // pbasel.
    0,  // pbbdiv.
    0,  // pbbsel.
    0,  // hsbdiv=cpudiv
    0); // hsbsel=cpusel

// Wait until the PLL output is stable.
while (!(AVR32_PM.poscsr & AVR32_PM_POSCSR_LOCK0_MASK));

// Switch the main clock source to PLL0.
pm_switch_to_clock(&AVR32_PM, AVR32_PM_MCCTRL_MCSEL_PLL0);

And it seemed to work all right.

But now when I wanted to make some changes to the temperature measurements that are made using the internal ADC, it was behaving very strange. Like I had a lot less resolution. I did some experimenting and finally changed back the clock to the initial way, and then it works.

Any suggestions?

Hi, I don´t know if this is the correct place for my question, but I want to toggle a pin at the maximum speed for UC3A3, I´ve already used your code above to set PLL and clock, but in scope, I just see 1.034MHz,
is this right? how can I get faster clock speed?
I hope somebody can help me
thanks in advance.