Does anyone have an example using one ADC to measure 3 different signals at the same time with sdk 2.0 and frdm k64f?

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

Does anyone have an example using one ADC to measure 3 different signals at the same time with sdk 2.0 and frdm k64f?

2,071 Views
diegovalerio
Contributor II

Hi.!

I am using the FRDM k64F and KSDK 2.0.

I need to measure 3 different signals with an ADC and 3 different singals with the other one, but I don't know how to do it.

Can anybody help me?

Labels (1)
0 Kudos
6 Replies

830 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I paste the code here:

BR

XiangJun Rong

/*

* main implementation: use this 'C' sample to create your own application

*

*/

#define PE_MCUINIT

#include <stdio.h>

#include "derivative.h" /* include peripheral declarations */

#define SOFTWARE_TRIGGER 0

#define PIT_TRIGGER 0

#define PDB_TRIGGER 1

void MCU_init(void); /* Device initialization function declaration */

void ADC_ISR(void);

unsigned int sample[10];

//ADC1_DM1 is connected to adjustable resistor, so the code can be used to

//test the output of the adjustable resistor

int main(void)

{

    int counter = 0;

   

    MCU_init(); /* call device initialization */

    //toggle LED E1 by toggling PCT7 pin

    //set the PCT7 as GPIO output pin mode

    SIM_SCGC5=SIM_SCGC5|0x3E00; //enable port A/B/C/D/E clock

    asm(nop);

    PORTC_PCR7=0x100; //PTC7 in GPIO mode

    GPIOC_PDDR=0x80; //PTC direction register, PTC7 is in output mode

    NVICIP58=0x0F; //set ADC0 interrupt priority

    NVICICPR1|=1<<26;   //clear the pending register of interrupt source of ADC(57)

    NVICISER1|=1<<26;  //set the interrupt source of ADC0, 57%32=25

   

   

#if     SOFTWARE_TRIGGER

//Conclusion:     ADC_ISR(void) can be entered

    //enable ADC0 clock, FTM1 and FTM0 clock, PIT clock, PDB clock

        SIM_SCGC6|=0x0BC00000;

        SIM_SCGC3|=0x08000000; //enable ADC1 clock

            //ADICLK=00 Bus Clock, MODE=01 12 bits conversion

            //ADLSMP=0 short sample time

            //ADIV 00 divide ratio is 1

        ADC1_CFG1=0x04;

        ADC1_CFG2=0x00;

        ADC1_SC2=0x00; //software triggered,

        ADC1_SC3=0x00; //one conversion

        //initiate ADC conversion by software triggering

        ADC1_SC1A=0x54; //interrupt enable and select ADC1_DM1 channel

        asm(cpsie i); //interrupt enable

#endif

       

#if     PIT1_TRIGGER

        //enable ADC0 clock, FTM1 and FTM0 clock, PIT clock, PDB clock

//Conclusion:        ADC_ISR(void)        can be entered

                SIM_SCGC6|=0x0BC00000;

                SIM_SCGC3|=0x08000000; //enable ADC1 clock

                    //ADICLK=00 Bus Clock, MODE=01 12 bits conversion

                    //ADLSMP=0 short sample time

                    //ADIV 00 divide ratio is 1

                //PIT module configuration

                PIT_MCR = 0x00;

                PIT_LDVAL1 = 0x003FFFFF; // setup timer so that the LED have enough time to flash

                //select PIT1 trigger via SIM_SOP7

                SIM_SOPT7=0x8500; //PIT1 trigger

               

                ADC1_CFG1=0x04;

                ADC1_CFG2=0x00;

                ADC1_SC2=0x40; //hardware triggered,

                ADC1_SC3=0x00; //one conversion

                //initiate ADC conversion by software triggering

                ADC1_SC1A=0x54; //interrupt enable and select ADC1_DM1 channel

                PIT_TCTRL1 |= 0x01; // start Timer 1

                asm(cpsie i); //interrupt enable

#endif   

               

               

#if     PDB_TRIGGER

//software trigger PDB, PDB triggers ADC

//enable ADC0 clock, FTM1 and FTM0 clock, PIT clock, PDB clock

//Conclusion:        ADC_ISR(void)        can be entered

                SIM_SCGC6|=0x0BC00000;

                SIM_SCGC3|=0x08000000; //enable ADC1 clock

                    //ADICLK=00 Bus Clock, MODE=01 12 bits conversion

                    //ADLSMP=0 short sample time

                    //ADIV 00 divide ratio is 1

                //PDB module configuration

                PDB0_CH0S=0x0000;

                PDB0_SC=0x00F80; //PDB enable, PDB interrupt enable

                PDB0_MOD=0x8000;

                PDB0_IDLY=0x00;

                PDB0_CH0C1=0x0303; //Enable CH0

                PDB0_CH0DLY0=0x1000;

                PDB0_CH0DLY1=0x5000;

                PDB0_SC|=0x02; //write the register

                PDB0_SC|=0x01; //write the register

                //select PIT1 trigger via SIM_SOP7

                SIM_SOPT7=0x00; //PDB0 trigger ADC1

               

                ADC1_CFG1=0x04;

                ADC1_CFG2=0x00;

                ADC1_SC2=0x40; //hardware triggered,

                ADC1_SC3=0x00; //one conversion

                //initiate ADC conversion by software triggering

                ADC1_SC1A=0x54; //interrupt enable and select ADC1_DM1 channel

                ADC1_SC1B=0x53; //interrupt enable and select ADC1_DM0 channel           

                PDB0_SC|=0x10000; //start trigger

                asm(cpsie i); //interrupt enable

                //The ADC_ISR() can not be entered

#endif                   

               

    for(;;) {      

           counter++;

    }

   

    return 0;

}

#pragma interrupt on

void ADC_ISR(void)

{

    //LED indicator

    GPIOC_PTOR=0x80;

        sample[0]=ADC1_RA;

    asm(nop);

#if     SOFTWARE_TRIGGER

    ADC1_SC1A=0x54; //software triggering interrupt enable

#endif   

}

#pragma interrupt on

0 Kudos

830 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

This is the ADC example code, you can refer to it.

BR

XiangJun Rong

0 Kudos

830 Views
diegovalerio
Contributor II

Hi Xiangjun.

Thanks for the explanation, but I can´t see the example code you send.

Could you send it to me one more time, if possible?

Thanks.

Diego.

0 Kudos

830 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Diego,

I think that the K64F supports to sample 3 different signals at the same time, this is the solution. As you know that the K64F has one PDB module and two ADC modules(ADC0 and ADC1), each ADC module support Ping-Pong operation for example, the Ping is controlled by ADC0_SC1A, the Pong is controlled by ADC0_SC1B, if you want to sample 3 different signals, you have to use two ADC modules at the same time. For example, this is the channels:

ADC0_SEx

ADC0_SEy

ADC1_SEz

ADC1_SEw(this can be a dummy channels)

The PDB Channel0 delay0 control the instant of sampling ADC0_SEx, the PDB Channel0 delay1 control the instant of sampling ADC0_SEy; the PDB Channel1 delay0 control the instant of sampling ADC1_SEz, the PDB Channel1 delay1 control the instant of sampling ADC1_SEw. If you set the PDBCH0DLY0=PDBCH0DLY1=PDBCH1DLY0=PDBCH1DLY1, all the four samples will be acquired at the same time.

I suggest you use software triggering mode for the PDB by setting the SWTRIG bit in PDBx_SC, in the case, external triggering source is not required. the ADC sampling cycle is controlled only  by the PDBx_MOD register.

If you want to sample another 3 different signals, you can change the channels of both ADC modules in the ISR of ADC, in this way, you can get 6 different samples in two ADC sampling cycles in interleaved mode, but I do not know if it can meet your requirements. If it do not meet your requirement, I think you can consider the Kinetis processor which the ADC supports scan mode for example KV58.

Hope it can help you.

BR

Xiangjun Rong

0 Kudos

830 Views
diegovalerio
Contributor II

Hi Xiangjun Rong.

I kinda understand the point, but I can´t make it real in a program.

I'm trying to measure a three phase signal with the FRDM K64F, that's why I need to measure three signals at the time.

By chance, do you have an example using the different channels of the ADC and how does the 'ping-pong' work?

It would be so helpful.

Thanks.

Diego.

0 Kudos

830 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Diego,

I am sorry, what I said previously is not totally correct. If you use Ping-Pong mode of SAR ADC, because there is only one ADC converter for each ADC module, the instant of Ping ADC sampling can not happen at the same time as the instant of Pong ADC sampling, the delay should be GREATER than one ADC conversion time, otherwise, there is error.

I copy part of ADC example code for Ping-Pong mode for K40, hope it can help you.

BR

Xiangjun Rong

0 Kudos