Conversion from usart serial to USB serial xmega256a3u

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

I'm working on a project using the xmega256a3u. We built this board using an FTDI FT232R USB to Serial chip on board to get the project going quickly. We did provide for depopulating the FT232R and connecting the USB lines directly to the xmega and using the internal USB controller as our 'serial' link to the the PC host.

Currently I have the firmware configured to use the internal 32mhz RC oscillator as the CPU clock, and it also provides the PerClock at the same rate. From looking at the documentation it seems to me that I have to switch this oscillator to 48mhz for the USB clock source, and would then have to divide it down for the CPU clock, which means that I have to change all the settings for existing devices that are clocked from the F_CPU source. It looks like I'm limited to a 24mhz cpu clock if I am using the full speed USB interface.

Does anybody been there and done that with this part and know the best way to configure the clock source for both the USB and CPU to get the highest possible clock rate for the CPU and PerClock (without over clocking)? I'm still going to need to use one of the usarts and will need a clock source to generate a baud rate of 115200 baud. I'm also using the A/D converters and need to generate a clock for them too.

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

The best way I've found is to run the RCOSC at 48MHz, and the PLL in x10 mode from the RCOSC (it goes through a DIV4). This gives you a PLL frequency of 120MHz, which can be used to clock clkPER4 at 120MHz, clkPER2 at 60MHz and clkCPU at 30MHz.

I imagine that the fractional baud rate generator will simplify the generation of the 115200 baud.

Jeff Nichols

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

120mhz??? I wonder what the max freq of the PLL is. Also what will that do to the current consumption of the thing? This project is running off a small battery!

As for the baud rate generator, my spreadsheet shows good values for all the popular rates with 0% to 0.03% max error. That fractional divider is nice.

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

You asked about the highest clock rates, not the most power efficient ones.

I assumed you made the distinction between the CPU and peripherals because you wanted to use the high-resolution timer extension. If that's not the case, then there are lower frequency PLL configurations that will give you 30MHz at the CPU (such as *5, div by 2). Though of course leaving the PLL off and using 24MHz divided from the 48MHz RCOSC is still going to be better for battery life.

The maximum PLL frequency is listed in the datasheet as the max CPU freq * 4 (i.e. the max clkPER4 frequency). For the A3U and A4U this is 128MHz.

Jeff Nichols

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

pixel2001n wrote:
You asked about the highest clock rates, not the most power efficient ones.

I assumed you made the distinction between the CPU and peripherals because you wanted to use the high-resolution timer extension. If that's not the case, then there are lower frequency PLL configurations that will give you 30MHz at the CPU (such as *5, div by 2). Though of course leaving the PLL off and using 24MHz divided from the 48MHz RCOSC is still going to be better for battery life.

The maximum PLL frequency is listed in the datasheet as the max CPU freq * 4 (i.e. the max clkPER4 frequency). For the A3U and A4U this is 128MHz.


We were fine with the 32mhz cpu and perclock, I don't need the timers clocked faster than that. Actually the xmega isn't the only device on board consuming power, we have a KCwireless BT module that probably is more power hungry. I'll look at the available divisor ratios for the PLL and the RC references. A 30mhz CPU / per clock should be OK. Then I'll have to figure out how to set up the ASF in a S6 project to generate the USB serial support. Dumping my existing project on top of that should be easy enough.

The big remaining hurdle would be to convert the xboot bootloader to use USB. I'd rather the bootloader remain avrdude compatible.

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

I've outlined a few options here:

https://www.avrfreaks.net/index.p...

If you want maximum speed, run the system clock from the 32MHz DFLL'd up to 48MHz, and PLL up the 2MHz RC oscillator to 32MHz.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

I set the usb clock src to the RCOSC32 (at 48mhz),
the PSADIV to 2, the PSBCDIV to 1_1, the PLL_MUL to 5 and the PLL_DIV to 1. I think this gives me a 60mhz PLL and PerClk = CPU_CLK = 30mhz.

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

abcminiuser wrote:
I've outlined a few options here:

https://www.avrfreaks.net/index.p...

If you want maximum speed, run the system clock from the 32MHz DFLL'd up to 48MHz, and PLL up the 2MHz RC oscillator to 32MHz.

- Dean :twisted:


You mean I can run the USB off the 32mhz RC clock, and the cpu/per clock off the pll referenced from the 2mhz RC clock? You can run BOTH RC clocks at once?

Register settings? I'm trying to use the ASF example for the CDC USB serial as a starting point.

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

Quote:

You mean I can run the USB off the 32mhz RC clock, and the cpu/per clock off the pll referenced from the 2mhz RC clock? You can run BOTH RC clocks at once?

You're darn tootin' you can - you can even DFLL the 2MHz RC oscillator before PLLing it, using an external 32KHz crystal to ensure perfect stability. It's awesome.

If you can't figure out ASF, I have my own thin wrappers around the XMEGA clocks as part of LUFA. The appropriate application code is:

/* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */

XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, 32000000);
XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);


/* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */

XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, 48000000);

With the clock functions being defined in this header:

https://github.com/abcminiuser/l...

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

The ASF example uses a prod sig row value to set the 32mhz RC osc to 48mhz, I didn't see any mention of the DFLL's in that code. Since we don't want to use any crystals in our HW, I guess I could use the 32khz RC with the prod sig cal value with the DFLL on the 2mhz RC osc and the PLL to get my 32mhz CPU/PER clock, and the 32mhz RC osc with the DFLL or prod cal value to run at 48mhz for the USB clock. These options don't seem to be part of the ASF sysclk.c/sysclk.h/pll.h/conf_clock.h files though.....

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

The latest ASF has a new DFLL enable option for the 2MHz RC oscillator -- and yes, you can DFLL the 2MHz against the internal 32KHz oscillator. However, it depends on just how accurate you need the system clock to be, as it may be acceptable as-is without additional DFLL calibration before PLLing it to 32MHz.

As for the 32MHz RC oscillator, you load in the calibration constants from the user signature row and then fire up the DFLL using the USB Start of Frame as a reference.

If you are using ASF, the appropriate conf_clock.h would be:

#ifndef CONF_CLOCK_H_INCLUDED
#define CONF_CLOCK_H_INCLUDED

// USB from the 32MHz RC oscillator, up-scaled to 48MHz
#define CONFIG_USBCLK_SOURCE                USBCLK_SRC_RCOSC
#define CONFIG_OSC_RC32_CAL                 48000000UL

// Enable DFLLs to stabalize RC oscillators
#define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC  OSC_ID_USBSOF
#define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC   OSC_ID_RC32KHZ

// Enable PLL to multiply 2MHz RC oscillator to 32MHz
#define CONFIG_PLL0_SOURCE                  PLL_SRC_RC2MHZ
#define CONFIG_PLL0_MUL                     (32 / 2)
#define CONFIG_PLL0_DIV                     1

// Switch system clock to the internal 2MHz RC oscillator
#define CONFIG_SYSCLK_SOURCE                SYSCLK_SRC_PLL
#define CONFIG_SYSCLK_PSADIV                SYSCLK_PSADIV_1
#define CONFIG_SYSCLK_PSBCDIV               SYSCLK_PSBCDIV_1_1

#endif /* CONF_CLOCK_H_INCLUDED */

Requires ASF 3.3.x.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Guess I need to update the ASF package. I have Avr Studio 6 version 6.0.1843 and ASF version 3.1.3 installed (they came together) along with avrtool chain 3.4.0.663 (gcc 4.6.2), again what came with the studio 6 install.

What's out of date beside ASF if anything? Should I download individual packages, or does the latest AS6 come packaged with the latest of everything?

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

Rats!
Maintenance Notice

The page you have requested is temporarily not available. Please check back later. We are sorry for any inconvenience.

Looks like I can't get to the download for the new ASF at the moment. Is there a mirror???

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

You can download the ASF update here in the meantime:

http://www.atmel.com/tools/avrso...

And get the other updates later on when the system is back online. Only the ASF release is critical, the others can wait.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Thanks Dean. Your conf_clock.h compiles fine with the new ASF installed. One question, in this configuration if the USB cable isn't plugged in there won't be any sync of the 32mhz osc against the USB_OF clock. I don't think that's a problem since the 32mhz clock is only used (at 48mhz) for the USB. I know that the code can detect when the USB is enumerated by the host PC and a logical connection is available. So I don't see anything wrong with the configuration. (???)

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

Indeed, you will lose DFLL reference sync against the USB SOF when USB is disconnected. That won't cause issues for your application if you use the 2MHz RC oscillator PLLed up to 32MHz for the system clock, as that is controlled and synced separately.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Hello  I used the following code in my project. I am using XMEGA128a4u. I did two things,

1) I added these clock settings in my project which is running on a 3.7V battery. When i execute the USB code the device resets. I tried to find the problem by doing option 2.

 

2) I loaded a DEMO example application on my XMEGA-C3 Xplained board and added the same clock settings. When i executed the USB part WINDOWS fails to recognize the device.

#ifndef CONF_CLOCK_H_INCLUDED
#define CONF_CLOCK_H_INCLUDED

// USB from the 32MHz RC oscillator, up-scaled to 48MHz
#define CONFIG_USBCLK_SOURCE                USBCLK_SRC_RCOSC
#define CONFIG_OSC_RC32_CAL                 48000000UL

// Enable DFLLs to stabalize RC oscillators
#define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC  OSC_ID_USBSOF
#define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC   OSC_ID_RC32KHZ

// Enable PLL to multiply 2MHz RC oscillator to 32MHz
#define CONFIG_PLL0_SOURCE                  PLL_SRC_RC2MHZ
#define CONFIG_PLL0_MUL                     (32 / 2)
#define CONFIG_PLL0_DIV                     1

// Switch system clock to the internal 2MHz RC oscillator
#define CONFIG_SYSCLK_SOURCE                SYSCLK_SRC_PLL
#define CONFIG_SYSCLK_PSADIV                SYSCLK_PSADIV_1
#define CONFIG_SYSCLK_PSBCDIV               SYSCLK_PSBCDIV_1_1

#endif /* CONF_CLOCK_H_INCLUDED */

Any suggestions ? would appreciate your help.Thank you