can we vary the sampling rates of ADC?

01 Aug 2012

sampling rate of ADC can be changed? IS there any available library for that? if i want change it then how it is possible?

01 Aug 2012

Each time you read the ADC you get a reading for that time. You can control with timers or delays when the next and subsequent ones occur.

03 Aug 2012

thank you kevin

i understand this thing but i did not understand function of the timer and interrupt in sampling of analog input practically, do you any program that explain this process? please share it.

03 Aug 2012

Hi Tejas,

I have posted some extracts below to help, BUT this is my first mbed program and I searched and cut and paste from lots of other peoples code to get this working! So all due recognition to them.

I have also deleted bits and renamed variables in the code extract to make it 'more' understandable, but cannot say that it will function as is...

This is within main, which basically attaches a 'ticker' to occur at the set time interval which calls the function ADC_read every 0.1S. A timer is also set up that calls the function Duration_end at the end of the set time period of 30S.

//--------------------------------------------------------------------
  
Convert.attach(&ADC_read, 0.1);             //do ADC_read function every 0.1 second

SamplingDuration.attach(&Duration_end, 30); //do adc reads over 'duration'                                  // currently 30 seconds

//---------------------------------------------------------------------------------

Before 'main' I have the following functions and declarations which I have commented to help you understand.

Timeout SamplingDuration;   // set up a timeout for adc reading duration.
                            // my understanding is this declares SamplingDuration as a type Timeout

Ticker Convert;             // set up a ticker to do timed adc covertions.

AnalogIn Vinput(p20);       //Vin pin
int ADC_Count;
float Voltage;
float Voltage_total;
float samples[1024];        // array to save averaged sample data


void Duration_end()         
    {
    Convert.detach();
    
    }
    


void ADC_read()
    {
    ADC_Count++;
    
     
    Voltage_total =0;
    for (int i=0; i<25; i++)        // do 25 readings
        {
        Voltage = Vinput.read();    
                                                                
        Voltage_total = Voltage_total+ Voltage;     //Note Vinput.read can be summed then averaged
        wait_us(10);
        }
        Voltage=Voltage_total/25;
        samples[ADC_Count] = Voltage;     //Save averaged reading within an array
                                                              
}

The following links from my notebook may also help: http://www.nxp.com/documents/application_note/AN10974.pdf Useful reference for current design

http://mbed.org/handbook/Timeout

http://mbed.org/handbook/Ticker

So I hope the above helps you with your code development.