XMEGA 128A1U USART BAUD RATE (4MHZ?)

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

Hi, I wish to drive WS2812 LEDs with the XMEGA USART peripheral and I have a problem when setting up baudrates over 2MHz.

 

Up to 2MHz everything is fine, the clock is rock solid 0.5us period, but when I try to set the baudrate to anything over 4MHz I see an odd 0.33us period... (testing the port speed with the classic putchar(0x55) square wave trick )

The processor is running off of an external 16MHz crystal, I'll post the conf_clock.h below.

 


#define CONFIG_SYSCLK_SOURCE          SYSCLK_SRC_PLL

#define CONFIG_SYSCLK_PSADIV          SYSCLK_PSADIV_1
#define CONFIG_SYSCLK_PSBCDIV         SYSCLK_PSBCDIV_1_1

#define CONFIG_PLL0_DIV             1
#define CONFIG_PLL0_MUL				3

#define BOARD_XOSC_HZ 16000000UL
#define BOARD_XOSC_STARTUP_US 1000
#define BOARD_XOSC_TYPE XOSC_TYPE_XTAL

#define CONFIG_XOSC_RANGE XOSC_RANGE_12TO16

#define CONFIG_USBCLK_SOURCE                USBCLK_SRC_PLL

Does anyone know what could be wrong?

Cheers!

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

sukuwc wrote:
but when I try to set the baudrate to anything over 4MHz I see an odd 0.33us period...
You sure that's not simply a sample limit of your observation device? Is it a scope or logic analyser or what? and what is the bandwidth?

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

That's what I thought first, so I checked with a 50MHz analog scope, the waveform is clear!

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

Does anyone know what could be wrong?

You aren't specifying a PLL clock source.  Didn't this generate a warning?

 

You are trying to clock the CPU at 48MHz even though it is spec'd for 32MHz.

 

 

 

 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

Well...

 

My first time running a WS2812 LED I used the same approach, an over-clocked Xmega.

For simple digital I/O, (no ADC, DAC, AC, eeprom, etc.), it is likely to run fine at 48 MHz.

 

Know that Ada Fruit, and others, have canned, working libraries for driving the LEDs and that might be a good place to start.

It will let you get the LEDs working, and prove the hardware, etc.

 

Then start working on your own driver.

 

Regarding your actual question about the variable timing, do you have any interrupts running?

 

I don't read C, but are you also sure that the delay is not in the program providing the data to the USART to transmit?

 

JC

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

The default is to sample the RX signal 16 times on each bit, that gives a miximum of 3Mbit/sec with F_CPU=48MHz. If you use the double speed mode (CLK2X = 1) you can get up to 6Mbit/sec (in asynchronous mode).

Last Edited: Wed. Mar 21, 2018 - 06:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not overclocking, F_CPU=32000000UL

 

thanks for snigelen for posting the solution, CLK2X works great.

 

USARTD0.CTRLB |= USART_CLK2X_bm;

 

sidenote: does anyone know how to write this "nicely" to look like the rest of the ASF initializations? (usart_mode_something(&USARTD0,  etc) )

 

thanks anyways! :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define CONFIG_PLL0_MUL				3

#define BOARD_XOSC_HZ 16000000UL

Really?  16MHz * 3 = ?

 

FCPU does not set the speed of the cpu, it just tells the compiler what you think it is!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

I'm not overclocking

If what you posted in your OP is the entire contents on conf_cock.h then the system clocking is not doing what you think it is. 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

Yes I realize that now...

 

I want to run the PLL at 48Mhz for the USB. (clocked from the external 16MHz crystal)

The rest of the system should run as fast as possible, also from the 16MHz crystal. I could route the XTAL to the SYSCLOCKMUX directly but that would only give me 16MHz sysclk. Is there any way I could have a 32MHz systemclock from the XTAL and also provide the needed 48MHz to the usb?

 

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

You can not use the 16MHz crystal as a common source to get both F_CPU=32Mz and F_USB=48MHz. One option is to use the crystal for F_CPU and let the internal 32MHz RC-oscilator be stretched to 48MHz by the DFLL (configured for USB start frame detection) for F_USB.

Or use 16MHz*3 for USB and some internal clock source for F_CPU (with or without DFLL).

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

#define CONFIG_SYSCLK_SOURCE          SYSCLK_SRC_PLL

#define CONFIG_SYSCLK_PSADIV          SYSCLK_PSADIV_1
#define CONFIG_SYSCLK_PSBCDIV         SYSCLK_PSBCDIV_1_1

#define CONFIG_PLL0_SOURCE            PLL_SRC_XOSC

#define CONFIG_PLL0_DIV               1
#define CONFIG_PLL0_MUL			      2


#define BOARD_XOSC_HZ 16000000UL
#define BOARD_XOSC_STARTUP_US 1000
#define BOARD_XOSC_TYPE XOSC_TYPE_XTAL



#define CONFIG_XOSC_RANGE XOSC_RANGE_12TO16

#define CONFIG_USBCLK_SOURCE                    USBCLK_SRC_RCOSC
#define CONFIG_OSC_RC32_CAL                     48000000UL
#define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC      OSC_ID_USBSOF

Just for confirmation, I posted the new conf_clock code here. I would really appreciate if someone could take a look at it!

16MHz XTAL x2 by by the PLL going to sysclk.

internal oscillator calibrated to 48MHz going to USB.

 

does this look ok?

thanks!

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

Looks OK to me. But I don't use ASF/Start (or what you are using), only used XMega/USB with LUFA and it sets up 32MHz RC and DFLL for 48 MHz USB-clock. Like this

    /* 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, F_USB);

 

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

Looks OK to me.

+1.  yes

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

Thank you very much guys for the help!

Great community, great forum! yes

(I'll post a short summery of the whole WS2812 USART solution soon)

 

Cheers!

 

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

This is one of the few flaws in the XMEGA clock system - there is no easy way to get a 48MHz USB clock and a 32MHz CPU clock from a single crystal.

 

You can fudge it with the USB SOF event triggering a timer capture and then doing manual adjustment of the 32MHz RC oscillator.