Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Very strange results when plotting a digitized sinewave, using a µC's 12bit ADC.

Status
Not open for further replies.

David_

Advanced Member level 2
Advanced Member level 2
Joined
Dec 6, 2013
Messages
573
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,308
Location
Sweden
Activity points
12,237
Hello.

I am using a arduino Due(SAM3X8E) with its 12bit ADC to read a sine wave, the reference voltage is 3V and the sine wave swings approximatly between 0 and 3V. I have writen a program to use DMA(Direct Memory Access) on the SAM3X8E µC to store the ADC results and then I send them over serial to matlab and plot the results. But I always come up with this type of plot, this is a 1kHz sine wave:
1kHz.jpg


Does any one know what the trouble is?
I have verified that the sine wave is a sine wave and the signal source is a low impedance.
No matter if I try a 100Hz wave or a 100kHz wave the plot is very strange, but I have very little experience with this sort of things and thought there might be some aspect I am not aware of.
The voltage reference is very stable, but I'm thinking that maybe the results are errorus because of the speed I use the ADC. Using PDC/DMA I should get 1MSPS which I have found a person on internet that has verified that but he has not verified whether or not that 1MSPS gives correct readings or not.
Next I am thinking that I should trigger the ADC from a timer and slow down the conversion rate and see if that changes anything.
 
Last edited:

Quite obviously, you are only displaying part of the ADC samples. There's a problem with your DMA setup or data handling concept.
 

Do you mean that there are conversions being made that is being lost?
Or not stored in memory.
I had never considered that a possibility, though I have very little experience.
 

Given the vertical distance between adjacent samples when the output jumps. It looks like there are 3 blocks of missing samples. So you are only displaying 1 out of 4 blocks of data. So as FvM states you have either a problem with your DMA setup or a problem with how you are handing the data (i.e. how you buffer the samples/where the DMA is writing the data or how you are reading the data back out).

Did you happen to divide the DMA up into 4 buffers? If so you are only displaying one of those buffers.
 

Hmm... I opened the plot again in matlab and zoomed in and you are right there are 3 samples missing, I certainly will be more observant of that kind of thing after this. I did not notice that and I was not near to do so ether.

I use a two dimensonal array(2x2048) for the DMA(its a PDC channel to be correct) and a ADC handler to switch between them when the current one has been filled up, from a function I can request(from matlab) a number of buffer to be transfered. I use only one for the moment so on request I use a for loop to go through one of the two buffers(2048 values in each) and in each 'for' iteration I do:
Serial.write(inp[idx] >> 8); // uint16_t inp[2][2048].
Serial.write(inp[idx] & 0xff)

and then in matlab(after appropiate setup of serial port):
ans = s.bytesavailable; // check how many bytes is in the receive buffer.
x = fread(s, ans); // reads those bytes into x.
msb = x(1:2:end); // stores the first byte of x, and every other from there.
lsb = x(2:2:end); // the same only from the second byte to split x in two.
data = ((msb .* 256) + lsb); // creating data containing all the original ADC results.
plot(data) // plot those results.

I don't see how the problem would be of my handling of the DMA(after the DMA buffer has been filled) I will try to do it without DMA once and see if that solves it, I could show how the PDC is set up but it would be better for another forum section since it would be purely SAM3X programming...

I've tested this on two different arduino Due so I think that's proved that it is a flaw in how I use it and not some flaw in the µC itself, I'll get back as soon as I have tried this without PDA/DMA. By the way, I intended to use the ADC PDC to store the results and then the UART PDC to send them to the PC but I have not gotten it working jet.
 

I haven't posed in a few days but at several times I sat down to try to make sense of the values that matlab received but t has been crazy.
What ever waveform I put on the results is ether a straight line of 2048 values or something resembling a square wave.
Now I discovered that the voltage reference used has not been properly power and power has not been on many times:)

With the voltage reference IC powered for sure I got this:
bummer.jpg

The title is how long it took to collect 10000 samples and how long each sample took... difficult calculation:)
But its nice to see.

I appear to have speant hours and hours fiddling with codes and going through all kind of material to read only to have had screwed up the reference voltage to the ADC:p

Case closed.
Thanks for you very much for your support.

- - - Updated - - -

Just to add, I abandoned the DMA/PDC solution after the last post in order to ensure that was not the problem. There might be some stuff there as well and now that I have obtained a proper sinewave plot I will again try to make the DMA/PDC approach work.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top