TWR-K70F120M ADC ISSUE

cancel
Showing results for 
Search instead for 
Did you mean: 

TWR-K70F120M ADC ISSUE

341 Views
danieljabad
Contributor I

Hi,
I need your help

My problem:
I need 4 (A,B,C,D) measures at 16 bits in differential mode.
I can't find any example or "Typical usage" or Application Note...

My environment:

TWR-K70F120M

KDS_3.0.0

KSDK_1.2.0

PROCESSOR EXPERT

WHAT I NEED:

MEASURE A  <--  ( ADC0_DP0  ;  ADC0_DM0 )
MEASURE B  <--  ( ADC0_DP1  ;  ADC0_DM1 )

MEASURE C  <--  ( ADC1_DP0  ;  ADC1_DM0 )
MEASURE D  <--  ( ADC1_DP1  ;  ADC1_DM1 )

Thank you in advance

Daniel Abad

Tags (1)
0 Kudos
1 Reply

51 Views
isaacavila
NXP Employee
NXP Employee

Hello Daniel,

Kinetis K70 is not supported in KSDK 1.2.0 so you need to create a new project that uses Processor Expert Support.

Basically, you need to configure 2 ADC modules (ADC0 and ADC1, each one using 2 channels) to be triggered by Programmable Delay Module (PDB). PDB module will allow you to trigger every ADC channel with specific time intervals.

  • ADC:

    We configure every ADC module to use Single conversion mode, 16-bit format and HW Trigger.

ADC Configuration.jpg

   Then, we configure pins used for Channel 0 and Channel 1. After this, we configure trigger sources for Trigger A and B (Select PDB0_CH0_TriggerA and PDB0_CH0_TriggerB respectively)

Trigger A and B selection.jpg

  We will manage results using interrupt mode, so ensure to enable interrupt for every ADC module in both conversion complete (A and B):

ADC Interrupt configuration.jpg

Finally, we configure ADC part triggered by trigger A and B as follows:

ADC Initialization.jpg

ADC configuration the same for both modules (obviously, selecting corresponding channels to use ADCx_DPn and ADCx_DMn). Now it is time to configure PDB component.

  • PDB:

PDB is a timer that generates trigger pulses to peripherals such as ADC, DAC and CMP. In this case, we will use 4 triggers.

PDB Settings.jpg

In this configuration, we select the PDB source clock (Derived from Bus clock) This clock is calculated as (Bus Clock / (Divider * Prescaler)).

Once frequency is calculated, we set the value in which the timer will be reset, in this case, as source clock is 15MHz, we select modulus value to be 15000 to have 1 ms period.

(1 / 15MHz = 66nS; 15000 * 66nS = 1ms)

We select the continuous mode (once the input trigger is received, timer will count until it reaches modulus value, then, it is reset and start counting again.)

In next tab (Channels) we configure Channel 0 trigger and Channel 1 trigger to generate triggers at 250 us, 500us, 750us and 1ms:

PDB Channels.jpgThen, in Pins/Signals tab, we can select up to 16 different input trigger sources (the trigger to start counting), in this case, we select software trigger.

Software Trigger for PDB.jpgNow, that's it.

We have configured both peripherals in order to be read one ADC channel every 250 us (so every 1 ms we will read these 4 channles).

Now, generate PE code.

In main.c file, we add header files for ADC and PDB:

#include "PDB_PDD.h"

#include "ADC_PDD.h"

And add Interrupt Service Routines for ADC0 and ADC1:

void ADC0_ISR () {

    if (ADC_PDD_GetConversionCompleteFlag(ADC0_DEVICE,0)) {

        ADC0_A_conv = ADC_PDD_GetResultValueRaw(ADC0_DEVICE,0);

    }

    if (ADC_PDD_GetConversionCompleteFlag(ADC0_DEVICE,1)) {

        ADC0_B_conv = ADC_PDD_ReadDataResultReg(ADC0_DEVICE,1);

    }

}

void ADC1_ISR () {

    if (ADC_PDD_GetConversionCompleteFlag(ADC1_DEVICE,0)) {

        ADC1_A_conv = ADC_PDD_GetResultValueRaw(ADC1_DEVICE,0);

    }

    if (ADC_PDD_GetConversionCompleteFlag(ADC1_DEVICE,1)) {

        ADC1_B_conv = ADC_PDD_ReadDataResultReg(ADC1_DEVICE,1);

    }

}

ADC0_A_conv, ADC0_B_conv, ADC1_A_conv and ADC1_B_conv will save the converted value for each channel.

Then, we only need to trigger PDB channel in order to start conversions on ADC. Like we select PDB software trigger, we call next function:

/* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

  PDB_PDD_SoftwareTrigger(PDB0_DEVICE);

  for (;;) {

  }

I attach this project in which I add DAC support to convert this digital value into an analog value again, and verify that every channel (with constant analog value) is sample every 250us:

Sampling every 1 ms.jpg

As you can see on previous image, 4 channels are sample every 1 ms. If you desired to change this value, it is necessary to modify PDB's period and Channels delays.

I hope this can help you.

Best Regards,

Isaac

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos