Set a sampling frequency (EVK1105)

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

Hi

I'm a bit of a newbie when it comes to Atmel and microcontroller programming, but I've gotten my hand on an EVK1105 sporting the AT32UC3A0512 microprocessor and would like to sample and play around with a signal using it. I've got the ADC up and running, but cannot seem to get the sampling frequency right. might be worth mentioning that at maximum I'd be interested in frequencies of about 20kHz.
At first I attempted

for(int i = 0; i < samples; i++){

        adc_start(adc);     
        adc_values[i] = adc_get_value(adc);
        delay_us(delay_time);
}

Where the delay_time constant is simply a million divided by the sampling frequency set by the user. This didn't produce accurate results, with an entered sampling frequency of 4kHz the system behaved as if sampling at about 3.73 kHz.
Now I'm attempting to set up a clock and checking it while sampling, taking a sample whenever it has counted beyond some certain number using Get_sys_count(), but I can't really get it to work either. How would I go about setting up a clock, or is there a better way to set my sampling frequency?

Best regards
Antiphates

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

Welcome to the Forum.

 

I've not used that chip, but I can share a few thoughts.

 

Typically one would set up a Timer/Counter to fire an interrupt at a given rate, (frequency).

Each time it fires the micro runs the ISR and reads the LAST ADC reading, and triggers the ADC to take the next reading.

 

In the ISR either set a flag that indicates a new value was obtained, or simply stuff it in a buffer / que / array while still inside the ISR.

 

Some of the micros have a DMA module that can also be set up to obtain ADC data somewhat automatically.

 

The Xmegas and some of the newer versions of the Mega/Tiny have an Event System that can also be configured to obtained ADC readings for you.

 

Know that there is a maximum rate at which the ADC can capture samples, (see the data sheet).

Know that there is a maximum rate at which the ADC can process data, so one has to set its pre-scaler to scale down the system clock, based upon whatever the system clock is.

 

Know, (finally), that if the bandwidth of the input signal of interest is 20 KHz, then typically one would sample at greater than twice the highest frequency in the signal, (20 kHz in your case).

That means that for some signal processing processes, (you didn't mention details of your processing), you would want to sample at 40 K Samples / second.

So, check that your micro is running fast enough to do that, and that the ADC can keep up at that rate, and that you can process the data at that rate.

Not all signal processing needs to be performed at that rate, it depends upon what you are wishing to accomplish.

 

Using foreground loops to sample data can certainly be done, but then the timing is somewhat suspect, and if there are any interrupts running it will really trash the "exact" timing of obtaining the data samples.

 

JC 

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

Antiphates wrote:
an EVK1105 sporting the AT32UC3A0512

This: https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/ATEVK1105 ?

 

That's an obsolete product - any particular reason for choosing that as your starting point ?

 

https://www.avrfreaks.net/forum/uc3-legacy

 

https://www.avrfreaks.net/forum/getting-started-avr-32-uc3-device

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you JC! I'll be looking into making an ISR then. Will probably make another thread when I fail to do that as well, hehe.

Awneil, no particular reason, I just happened to get my hands on one and thought I'd use it to further my understanding of micro controller programming in Atmel Studio! :)