Free Running ADC

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Free Running ADC

跳至解决方案
1,930 次查看
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 项奖励
回复
1 解答
1,302 次查看
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 项奖励
回复
2 回复数
1,303 次查看
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 项奖励
回复
1,302 次查看
aliasadzadeh
Contributor II

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

0 项奖励
回复