Free Running ADC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Free Running ADC

Jump to solution
1,203 Views
aliasadzadeh
Contributor II

Dear All

I want to use my FRDM-KL25 board to sample 4 different analog signals on PE20-PE23, I want to write some code to scan the inputs alternatively, I want to set my sample time to 25600 samples per second, do you have any Idea how I should do that, Basically I want to set a timer interrupt and use ADC in software mode to read each channel, by this method can I get the same sample time interval on each channel the same? Can the device do continuous sampling and sending the results over uart? Do we have any speed limitation?

Here is a pseudo code, Is there a better approach? Do you have any Idea?

Time tick ISR is 25600HZ

{

I++;

If(i>3)

I=0;

analogRead(i);

}

And here is my ADC codes

int analogRead(int ch)

{

    // Start a conversion by writing the channel number

    ADC0->SC1[0] =    ADC_SC1_ADCH(ch);

    // Wait for it to complete.

    while( ((ADC0->SC2 & ADC_SC2_ADACT_MASK) ) != 0U)   ;

    return  (int)(ADC0->R[0]);

}

void ADC_Init(void)

{

                //Turn on ADC

                SIM->SCGC6 |= SIM_SCGC6_ADC0_MASK; 

                //bus clock/2 & singled-ended 16bit mode & div by 4

                ADC0->CFG1 = ADC_CFG1_ADICLK(2) | ADC_CFG1_MODE(3) | ADC_CFG1_ADIV(1);

                //select channel A & high speed mode

                //ADC0->CFG2 = !ADC_CFG2_MUXSEL_MASK;// | ADC_CFG2_ADHSC_MASK;

                ADC0->CFG2 &= ~(ADC_CFG2_ADACKEN_MASK | ADC_CFG2_ADHSC_MASK | ADC_CFG2_ADLSTS(0x03));

                //hardware trigger  & VREFH/VREFL

                //ADC0->SC2 = ADC_SC2_REFSEL(0);      //ADC_SC2_ADTRG_MASK | ADC_SC2_REFSEL(0);                          

                ADC0->SC2 =0;

                //single shot mode        

                //ADC0->SC3 &= ~ADC_SC3_ADCO_MASK; 

                ADC0->SC3 = ADC_SC3_CALF_MASK;

                //hardware average 32 sample

                //ADC0->SC3 |= ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(3);

}

0 Kudos
1 Solution
575 Views
adriansc
Contributor IV

Hi,

Check the document KLQRUG, there you will find excellent information about ADC and much more. Chapter 11: Using Low-Power Timer (LPTMR) to Schedule Analog-to-Digital Converter (ADC) Conversion probably will give you an idea of how this works and also there is an example doing this.

You can find KLQRUG here:

http://cache.freescale.com/files/32bit/doc/quick_ref_guide/KLQRUG.pdf

Hope this helps.

View solution in original post

0 Kudos
2 Replies
576 Views
adriansc
Contributor IV

Hi,

Check the document KLQRUG, there you will find excellent information about ADC and much more. Chapter 11: Using Low-Power Timer (LPTMR) to Schedule Analog-to-Digital Converter (ADC) Conversion probably will give you an idea of how this works and also there is an example doing this.

You can find KLQRUG here:

http://cache.freescale.com/files/32bit/doc/quick_ref_guide/KLQRUG.pdf

Hope this helps.

0 Kudos
575 Views
aliasadzadeh
Contributor II

Thanks for your help,I think using DMA and a Timer is good solution for scanning inputs without CPU activity,

0 Kudos