TWR-K20D72M can't read the multiple ADC channels from one ADC(ADC0 or ADC1)

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

TWR-K20D72M can't read the multiple ADC channels from one ADC(ADC0 or ADC1)

773 Views
bhavinmaru
Contributor III

Hello,
I am working with TWR-K20D72M EVM as controller and IAREW(IAR Embedded Workbench) software for programming.i download the sample codes for this board from the below link :

 

http://cache.nxp.com/files/32bit/software/KINETIS_72MHz_SRC.zip?fpsp=1&WT_TYPE=Lab%20and%20Test%20So...

 

i am working on ADC so i take the reference of those sample codes.in above linked sample codes ADC sample code is given on interrupt bases but i want to make the ADC code on polling bases and it works properly with one channel.i attached my code for your reference.in this code i select the ADC channel no-19 in board this channel is connected with the potentiometer.in this code i continuously read the ADC1_RA and ADC1_RB(ADC Data registers) and it works properly when i change the potentiometer's pot it's readings also changes.but i am facing one problem which i mention below please try to solve my below query:

 

  • i wants to read continuously two or more channels from one ADC(ADC0 or ADC1).for that in my attached code to change the channel i make the Change_channel() function.i tried this function to change the ADC channel but it not works.so give me suggestion to change the ADC channel and i can read the multiple ADC channels continuously.


Thank You
Bhavin

Original Attachment has been moved to: ADC.zip

Labels (1)
0 Kudos
4 Replies

581 Views
bhavinmaru
Contributor III

Is there any update on this issue?

please help me i am stuck in this issue and its urgent for me.

Any help in this will be appreciated more.

0 Kudos

581 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Regarding your problem, I suggest you modify the code as following:

void Change_channel(uint8 channelA,uint8 channelB)
{    
    Master_Adc_Config.STATUS1A = AIEN_OFF | DIFF_SINGLE | ADC_SC1_ADCH(channelA);
    Master_Adc_Config.STATUS1B = AIEN_OFF | DIFF_SINGLE | ADC_SC1_ADCH(channelB);
    ADC_Config_Alt(ADC1_BASE_PTR, &Master_Adc_Config);  // config ADC1         
}

uint8_t hw_adc_test(void)
{
    sim_init();
    pdb_init();    
    adc_init(19);
    lptmr_init(0x01110,3);                
    enable_irq(INT_LPTimer-16);    

    PDB0_SC |= PDB_SC_SWTRIG_MASK;    // kick off the PDB  - just once    

    while(1)
    {
        printf("R0A=%d  R0B=%d\n",ADC1_RA, ADC1_RB);
        time_delay_ms(3000);

      Change_channel(5,18);  //sample channel 5 and channel18
    }

    // disable the PDB
    PDB0_SC = 0;    
}

But the ADC16 can only sample two channels triggered by PDB, if you use software triggering, you can only sample one channel one times, the ADC16 does not support scan mode. If you want to sample multiple channel, you can change the channel by calling Change_channe().

Hope it can help you

BR

Xiangjun Rong

0 Kudos

581 Views
bhavinmaru
Contributor III

Hi Xiangjun Rong,

Thank you for your reply as per your suggestion i change the code but it still not works and it continuously prints "R0A=0  R0B=0" so ADC data register not getting update.

0 Kudos

581 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Bhavin,

The code I gave you just demos how to change the channels, which ADC channels do you want to sample so that I can check you how to configure the pin as ADC pin?

BR

XiangJun Rong

0 Kudos