A/D Converter

28 Nov 2011

This is probably somewhere on the site but I've been looking awhile and haven't found it yet. I'm trying to make it so that it samples one of the analog ports at a certain frequency. No matter what it is doing at the time, it must sample that port if its time for sampling. I am trying to make a program that will be doing two task at once. One task is just overhead of waiting for a person or another processor to ask them to do something and when they are asked, they do it but no matter what it is doing/what stage the process is in, when its time to take a sample, it must take one. If the process it is doing is transferring data over another port then it must be able to do both at once if it is at a point it can't stop. It will also be processing the sampled data in the background.

My question is how do you get it to do this and how do you set up the A/D converter to the correct parameters.

Note: The A/D converter is getting its input from a microphone that has been amplified and filtered.

28 Nov 2011

you should look at http://mbed.org/handbook/InterruptIn and http://mbed.org/handbook/Ticker.

Just set a Ticker at the sample rate and then read the ADC.

28 Nov 2011

Hi,

Johannes Sedlmeier wrote:

Just set a Ticker at the sample rate and then read the ADC.

I think this is exactly what causes the problem! The ADC is running continously (at high speed) and the app just takes/draws a sample from it every ticker's tick. Setting the Ticker says noting about the ADC characteristics, only that I pick/draw a sample at a particular interval.

In the timer/MAT code I described, the ADC is instructed to do a single conversions when I need then (and not a single one more).

My guess is that either software or hardware takes a reading when the ADCR content is not valid (any more). As the ADC is a sucessive approximation one it could result in a very large spike if a new conversion is already started.

wvd_vegt

28 Nov 2011

ah, alright, so you have to know, what time a conversion needs and if you can do other things while the conversion. Maybe there are some hints in the datasheet of the processor, that tell you how long a conversion lasts. but i think you can not do anything in parralel. got to check this myself.

29 Nov 2011

Which timer are you refering to? The RIT one?

29 Nov 2011

Hi

I wrote code for both the RIT/Ticker using the mBed ADC lib. Both have (many) spikes.

Besides that I used Timer1 code issuing small DMA transfers posted elsewhere on the forum. This one also had spikes.

Lastly I used code that uses Timer1 code that triggers the ADC by the MAT1:0 pin (using the timer match functionality). This code ran flawlessly for 30.000 * 2 * 100 samples (took several hours, including the data transfer).

But more riddles: When I removed the other three pieces of code (not nessecary anymore) the Timer1/MAT1:0 code suddenly started to show spikes.

I'm currently in the process of comparing sources before and after this change line by line to see where a cause might be and to find a clue.

wvd_vegt