Saturday, December 7, 2013

Measuring Xmega ADC sampling speed

The xmega ADC can give a sampling rate of 2Msps. To measure this, we have to use event system.

Here is how-

1. In the adc_init function, add the following
                adc_set_current_limit(&adc_conf, ADC_CURRENT_LIMIT_NO);
2. Write an evsys_init function
                static void evsys_init(void)
                {
                    sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_EVSYS);
                    EVSYS.CH0MUX = EVSYS_CHMUX_ADC_CH0_gc;
                }
  Here, we are enabling clock to the event system. The ADC is connected to the event system through Channel 0, hence the use of CH0MUX. In the main code, call this function.

3. Finally to route the conversion event to a pin, use the  PORTCFG_CLKEVOUT  register. Read page 154 of the Atmel Xmega AU manual about the CLK_EVOUT register.





The EVOUT bits are the once we are interested in.
After configuring all this, and connecting the pin 7 of either portC or D or E to the oscilloscope, we see a spike every time conversion completes.

 Also, note that the ADC is in free running mode and that the sampling rate is 1/4th of the system clock, if no prescalers are configured for the ADC and by default its Clkper/4.