Jump to content

Getting ADC working on the Tiva LaunchPad

Recommended Posts

I have designed my very first circuit, it is a simple non-inverting amplifier. Its purpose is to take line-level audio (1.6v) and double it (3.2v) so that the TIva ADC can process the audio.


It seems to work, as in when I am not playing music, AIN0 returns values around 0. Where as when I play music AIN0 reports much larger numbers.


The problem however is that the numbers seem random, and don't seem to be following the music in anyway I can tell. 


I am wondering if I have done something silly with my circuit or do I require a low-pass filter or something to remove noise?? I have tried a 1uf cap between the audio in and the non-inverted input as a low pass filter, but results seemed the same.


Perhaps something in my code is incorrect, I did however just use similar code provided with Tivaware (single_ended.c).


I would like the numbers to reflect the bass in the music, so I guess frequencies less than 200hz.


Any suggestion very much welcomed!


Here is my circuit




And here is my code

    uint32_t pui32ADC0Value[1];



    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);

        ADCProcessorTrigger(ADC0_BASE, 3);

        while(!ADCIntStatus(ADC0_BASE, 3, false))

        ADCIntClear(ADC0_BASE, 3);
        ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);

        System_printf("AIN0 = %4d\r", pui32ADC0Value[0]);

        SysCtlDelay(SysCtlClockGet() / 120);


Link to post
Share on other sites


You have some problems -both hardware and software.

I will begin with the simplest -the software: you are sampling non-uniformly due to UART communication and delay inside the while loop. Try to use an uniform sampling - start with a sinusoid signal, a timer to sampling uniformly, and a buffer to store some 128 samples. Take only 128 samples and then inspect the buffer to see if the samples reconstruct the sine signal. You may use pencil/paper or some tools to see that. (Some tool chains have dedicated tools to reconstruct the shape). Keep in mind the range concept - while static is 1.6V, dynamic must be less, to accommodate some high frequency pulses.

As for hardware, you got 0V while no signal instead the line 1.6V - this is because your input is floating. Better to set it around the line level with a voltage divider and use a coupling capacitor for signal. And of coarse a low pass filter would be better.

The supply voltage is dangereous since it will allow max 5V outputs so better to use a rail-to-rail amplifier at 3.3V.

Also the digital noise picked up on the ground line will introduces some deviations from ideal samples - with a Launchpad will be more difficult - you need to set correctly a reference voltage and avoid the digital ground - this means the analogic signal, the external reference and the micro should have a single common point at VREF- pin.

Hope this will be not so difficult to implement, except for the last hardware problem which requires a special PCB....


Link to post
Share on other sites

Thanks Lyon,


I am learning a lot!


Ok, let me see if I have understood enough to develop solutions.


1. Sampling - I would be better off removing the delay, and then averaging the result of multiple samples for each data point produced? (I need about 20 unique data points a second that represents the bass/beat component of the music)


2. Regarding my floating input. I have now added a low pass filter which grounds the input, not sure if that is enough...do I still need a voltage divider, if so, what do they look like? See the results of the changes to my circuit below.


3. I have used 5V because I want to produce about 3.3v, so I had thought with a op amp I will require to provide it a little more volts than I wish it to produce? Scratch that, I just read what a rail-to-rail op amp does...that is pretty cool, any recommendations?


4. Noise from the LaunchPad ground - could I improve this situation by smoothing out some of the noise somehow, perhaps by using a capacitor? if so, any suggestions on values?






Link to post
Share on other sites


1) depends on your application - music need sampled much faster than that - usually is 44.1kHz if you need high fidelity but some other lower rates can be used such as 16kHz. Keep in mind that for a sinusoid the average value is 0 so be careful. Voice is sampled at 8 kHz. An I2s module would be better to sample music but you can experiment/learn a lot also from this approach.


2) Since you apply a signal, this must be centered on the mid scale ( the ADC is unipolar) so use two series resistors of equal value, say 10k from Vcc to ground, the mid point to be connected to opamp and then use a series capacitor to apply the signal - this is high pass so choose the capacitor value to allow the lowest frequency, 5...10 Hz.


3) Keep in mind you must protect the ADC inside the micro so it is mandatory to apply less than 5V... For the moment I do not have a recomandation for this, you can find out at TI.


4) For the moment keep experimenting like this, no other means to remove noise, since the music is not repetitive. There are some techniques to apply for repetitive signals: sample several times keeping up the sinchronization of signal (take samples at same position) and then average the bins(samples at each position). This does not apply to music, unfortunately...

You will be able to improve with a careful design of a PCB.


One more thing: after ADC conversion, the real sample value is what you get from ADC minus the center value!



Link to post
Share on other sites

For the sampling, you should be using a timer interrupt to ensure that the samples are taken at a regular interval.  The UART and such introduce randomness to the sample frequency if you don't use a timer interrupt to force the micro to sample the ADC at a specified interval.  And you need to set the timer interrupts priority higher than the UART and other interrupts so that it will interrupt them as well as whatever else the micro is doing.  You can't have much variance in the sample rate at the sample frequencies needed for audio work (+/- a few microseconds per sample will wreak havoc on your data).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...