cancel
Showing results for 
Search instead for 
Did you mean: 

Two questions about the A/D

gullik
Associate II
Posted on November 13, 2013 at 17:31

Hi,

I am successfully running most of my software, and I am now debugging the A/D.

I first used the examples verbatim, to understand what I am setting up. I gave now

modified the code, and have two questions:

This is from the example:

ADC_SoftwareStartConv(ADC2);

while

(ADC_GetSoftwareStartConvStatus(ADC2) != RESET){ADC_Convert = 0;}

ADC_Convert = ADC_GetConversionValue(ADC2);

I am now *assuming* conversion is done, since conversion parameters are set such that conversion is much faster than use/access.

Thus I have a 8 khz interrupt for audio sampling and just the

ADC_Convert = ADC_GetConversionValue(ADC2);

ADC_SoftwareStartConv(ADC2);

in the interrupt routine, i.e. I do not test for ''DONE''. What problems would you expect this to cause me, or is all fine as the AD always completes befor int is hit again?

Second thing: I can see no ''format'' specifiers, I can get left or right alignment, but want signed 16-bit data. Is there something I can do to get this, or should I:

Audiobuffer[i] = (unsigned short) Adresult - 2048;

To get a ''16 bit'' signed int?

Regards

G

5 REPLIES 5
raptorhal2
Lead
Posted on November 13, 2013 at 20:15

Regarding ''Second thing'' - ADC 12 bit conversion result will range between 0 and 4095, corresponding to an input of 0 to ADC reference voltage. Your choice of biasing the converted result by 2048 is correct if the input audio signal zero bias value is half the ADC reference voltage.

Cheers, Hal

gullik
Associate II
Posted on November 14, 2013 at 23:49

Well, I am ''Discovering'' the STM32, and just an hour ago I successfully ''listened'' to the remote A/D, a 400 hz test tone sounds nice and smooth, and everything seems to work as intended. I frequently have some trouble with st-util and/or board and/or arm-eabi-none-gdb, it seems I get into a state where flashing fails, monitor reset halt does no good, and I have to stop gdb, kill st-util, and power cycle the board. It also happens the thing will not start, or breakpoints are not taken. the very-hard-reset-cycle clears it up, but I cannot figura out where the problem is.

gullik
Associate II
Posted on November 13, 2014 at 17:15

I am getting a lot of noise in my data. It amounts to several percent of range, so is excessive. I am using the STM32F4Disovery board, and pin PC1 as input. I currently have the pin connected to a vref point with two resistors from VDD & GND, bypassed by a capacitor to ground.

I would have expected some jitter in the one or two MSBits, but I am seeing much greater random values. I am sampling a single conversion, triggered by a timer interrupt at 125 uS, and retrieve the data on next interrupt, and then trigger the conversion. The end result is i DO get a reasonable audio from this arrangement, but there is far too much noise, even with ''no'' input. Any ideas of what I am doing wrong, or is the Discovery board just not god enough from a noise view?

gullik
Associate II
Posted on November 13, 2014 at 20:17

Ok, I am currently running with result left adjusted ( to mimic a 16 bit ad) and I have peak noise corresponding to about +/- 15. I cannot hear anything special, listening to captured data, and I do not have an audio spectrum analyzer, but it seems to me it is ''white'' noise. What clock and sample delay should I use , considering I want 0-4 khz, sampling at 8 khz? Are these critical at this low frequency?

With +/- 15, in effect I have a 7-bit a/d using 12 bit hw. Strange....

 

gullik
Associate II
Posted on November 16, 2014 at 15:17

Spectrum analysis of the resulting audio indicates 800 hz is a significant component, which is strange, since the only periodic component is 8khz, the sampling rate. There is also a signal at 50 hz, it is not coming from the input, since shorting input changes nothing.

The 800 Hz is -40 dB or so, there is also a signal at 1600 Hz, but much weaker, and finally at 3200 Hz even weaker. On strange thing is that there is nothing at 2400 hz, that would otherwise be 3'd overtone of 800 hz.   So, the question is where the 800 hz comes from? I have nothing that I know of running at that rate....