TWR-KM34Z ADC Configuration

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

TWR-KM34Z ADC Configuration

894 Views
homarpizar
Contributor I

Dear all,

I´m working with the TWR-KM34Z50MV3, and I want to read 7 signals using the 4 SD ADC and 3 SAR ADC of the board.

Know I´m trying to configure the SAR ADC´s using the MKMxxZxxACxx5 Bare Metal Software Drivers  R4.1.5,  but I can´t deal with the configuration, beacause if I want to use all channel they must to be triggered by HW.

I´ve set the ADC_Init(cfg,avg,CHA,CHB,CHC,CHD,ip,callback) as follows:

ADC_Init  (ADC_MODULE_16B_HWTRG_IREF_CONFIG,

             HWAVG_OFF,

             ADC_CH_SE_IRQ_CONFIG(AD10),

            ADC_CH_SE_IRQ_CONFIG(AD0),

            ADC_CH_SE_IRQ_CONFIG(AD1),

            ADC_CH_SE_IRQ_CONFIG(AD2),

             PRI_LVL0,

            (ADC_CALLBACK) Callback_ADC);

but the ADC Callback doesn´t run.

Do I have to do something with the callback function?

How I must configurate the hardware interrupt?

Is it something missing?

Please help me.

Omar.

0 Kudos
4 Replies

509 Views
MarMi
NXP Employee
NXP Employee

Hi Omar,

I have attached minimalist software example for your use-case - reading 7 signals using the 4 SD ADC and 3 SAR ADC of the board.

Examples initializes along with other on-chip peripherals also 4ch SD ADC to run with a slight phase shift and gathering 4 measurements at rate of 6 ksps. Each SD ADC channel triggers respective SAR ADC channel and this way up to 8 samples can be gathered of the board in the precise time sequence.

If you need to trigger SAR ADC with more flexibility, you can insert a QuadTimer channel into every SD ADC=> SAR ADC channel chain as Rong suggested. Also as Rong said, the only limitation is that you cannot request SAR ADC to perform more conversions simultaneously because there is only one instance of the analogue block on the MKM34 devices accompanied with four result registers.

Examples further transforms all measured values into Q8.23 fractional format.

Hope that helps.

Kind regards,

Martin M.

0 Kudos

509 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Homar,

Can you tell me where I can download the "MKMxxZxxACxx5 Bare Metal Software Drivers  R4.1.5"? Regarding your ADC init function:

ADC_Init  (ADC_MODULE_16B_HWTRG_IREF_CONFIG,

             HWAVG_OFF,

             ADC_CH_SE_IRQ_CONFIG(AD10),

            ADC_CH_SE_IRQ_CONFIG(AD0),

            ADC_CH_SE_IRQ_CONFIG(AD1),

            ADC_CH_SE_IRQ_CONFIG(AD2),

             PRI_LVL0,

            (ADC_CALLBACK) Callback_ADC);

From api function itself, it is okay, but it is difficult to implement.

As you know that the  ADC16 module support Ping-Pong-Pong-Pong mode with hardware triggering, in other words, the ADC16 module has ADC16_SC0, ADC16_SC1, ADC16_SC2, ADC16_SC3 register, which specify the respective sampling channels, you have to trigger the ADC with 4 sequential pulse, the pulses are from the crossbar, the ADC triggering pulses are called "SAR ADC trigger select A pulse", "SAR ADC trigger select B pulse", "SAR ADC trigger select C pulse" and "SAR ADC trigger select D pulse", the delay between the sequential pulse must be greater than conversion time. The problem is that it is difficult to generate 4 pulses with programmable delay, maybe you say that quadTimer can generate the 4 pulses, but the issue is that the 4 timer in one quadTimer module are independent timer, there is NOT a synchronization mechanism. The quadTimer supports master-slave mode, maybe it is okay to generate 4 pulse with programmable delay, but I never test it.

For simplicity, you can use PIT, quadtimer to generate only one pulse and have ADC16 sample one channel, it is easy. In other words, if you want to use hardware trigger, you have to configure the hardware triggering source for example PIT, initialize the crossbar so that you can trigger ADC.

For example, if you want to use PIT0 as "SAR ADC trigger select A pulse", you can write:

SIM_MISC_CTL&=~(0x3000);

XBAR_SEL7=16<<8;  //16 PIT Output

ADC_Init  (ADC_MODULE_16B_HWTRG_IREF_CONFIG,

             HWAVG_OFF,

             ADC_CH_SE_IRQ_CONFIG(AD10),

            ADC_CH_DISABLE_CONFIG,

           ADC_CH_DISABLE_CONFIG,

            ADC_CH_DISABLE_CONFIG,

             PRI_LVL0,

            (ADC_CALLBACK) Callback_ADC);

//initalize PIT module here

Hope it can help you.

BR

Xiangjun Rong

0 Kudos

509 Views
homarpizar
Contributor I

Dear Xiangjun Rong,

You can download the API here:

Kinetis KM3x 50-75 MHz|ARM Cortex-M0+|32-bit MCUs|NXP

Documentation/Application Notes/API reference manual for Kinetis M bare-metal drivers and software ... (Unzip and open refman.html)

I tried as you told me, and it works for the ADC HW trigger using de XBAR of the API.

But there is a problem, It looks like the PIT can´t trigger all ADC´s at the same time.

I made like this (Ussing the API):

...

/* XBAR Module                                                      */

  XBAR_Init (XBAR_MODULE_ANYEDGE_DETECT_CONFIG, PRI_LVL0, NULL);

  XBAR_Path (XBAR_PIT, (XBAR_ADCTRGCHB) | (XBAR_ADCTRGCHB) | (XBAR_ADCTRGCHC) | (XBAR_ADCTRGCHD));

...

  /* PIT Module                                                      */

  PIT_Init (PIT0, CH0, PIT_CH_TMR_EN_CONFIG, 1000000);

...

ADC_Init  (ADC_MODULE_16B_HWTRG_IREF_CONFIG,

              HWAVG_OFF,

              ADC_CH_SE_IRQ_CONFIG(AD10),

              ADC_CH_SE_IRQ_CONFIG(AD0),

              ADC_CH_SE_IRQ_CONFIG(AD1),

              ADC_CH_SE_IRQ_CONFIG(AD2),

              PRI_LVL0,

  (ADC_CALLBACK) Callback_ADC);

...

...

void Callback_ADC  (ADC_CALLBACK_TYPE type,  register uint16 result)

{

   if (type == CHA_CALLBACK)

   {  GPIO_Tgl (GPIOE, PIN5); //LED GREN  }

   if (type == CHB_CALLBACK)

     {  GPIO_Tgl (GPIOF, PIN1); //LED RED   }

   if (type == CHC_CALLBACK)

     {  GPIO_Tgl (GPIOD, PIN1); //LED ORANGE }

   if (type == CHD_CALLBACK)

     {  GPIO_Tgl (GPIOC, PIN1); //LED YELLOW  }

}

If I do like above, Just LED GREEN blinks.

Could be possible that I can select PIT0 ch0, PIT0 ch1, PIT1 ch0, PIT1 ch1 as inputs of the XBAR?

Is the any problem with the interrupt?

Do I have to clear the interrupt of each channel?

Can you help me?

Best regarts.

Omar

0 Kudos

509 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Homar,

I do not think you can use PIT0_CH0/PIT0_CH1 and PIT1_CH0/PIT1_CH1 to trigger ADC four times in sequential way, if you set the PIT in independent mode, the four PIT timers will have different cycle time. The PIT chained mode is in fact a cascading mode, it is useless.

But maybe you can use quadTimer to generate the sequential pulses in master-slave mode, but I have not the code. I will try to develop the example next week, I will update here no matter whether the solution is okay or not.

BR

Xiangjun rong

0 Kudos