AnsweredAssumed Answered

S32K116 ADC Continuos Mode Opearion with PDB Back to Back Trigger

Question asked by Nimesh Modi on Jul 26, 2018
Latest reply on Aug 1, 2018 by Diana Batrlova

Hi,

 

I am able to get ADC data using one shot mode but we require ADC continuous mode operation. I tried to Implement that but didn't get any ADC Reading. Below i share my PDB ADC Back to Back One Shot Mode code.

 

void ADC_Init(void)
{
PCC->PCCn[PCC_ADC0_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Disable clock to change PCS */
PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_PCS(1); /* PCS=1: Select FIRC */
PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable bus clock in ADC */

 

ADC0->CFG1 |= ADC_CFG1_ADICLK(0) | /* Only ALTCLK1 is available */
                           ADC_CFG1_ADIV(0) | /* 16 MHz /1, 16MHZ clock is given as ADC input clock */
                           ADC_CFG1_MODE(0); /* 0b00: 8-bit, 0b01: 12-bit, 0b10: 10-bit */

 

ADC0->SC2 |= ADC_SC2_ADTRG(1); /* Conversion Trigger: 0b0= SW , 0b1 = HW */

 

 

ADC0->SC1[0] = ADC_SC1_ADCH(1); /* Select AD12 (ADC0_SE1) @PTA1 */
ADC0->SC1[1] = ADC_SC1_ADCH(3); /* Select AD12 (ADC0_SE3) @PTA7 */
ADC0->SC1[2] = ADC_SC1_ADCH(4); /* Select AD12 (ADC0_SE4) @PTB0 */
ADC0->SC1[3] = ADC_SC1_ADCH(5); /* Select AD12 (ADC0_SE5) @PTB1 */
ADC0->SC1[4] = ADC_SC1_ADCH(6); /* Select AD12 (ADC0_SE6) @PTB2 */
ADC0->SC1[5] = ADC_SC1_ADCH(7); /* Select AD12 (ADC0_SE7) @PTB3 */
ADC0->SC1[6] = ADC_SC1_ADCH(10); /* Select AD12 (ADC0_SE10) @PTC2 */
ADC0->SC1[7] = ADC_SC1_ADCH(11); /* Select AD12 (ADC0_SE11) @PTC3 */

}

 

void PDB_Init(void)
{
PCC->PCCn[PCC_PDB0_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable bus clock in PDB0 */

PDB0->SC |= PDB_SC_TRGSEL(0xF) | /* b1111: Software trigger is selected */
                        PDB_SC_PRESCALER(1) | /* Prescaler: 010 = per.clck/(4*MULT) = 80 / (4*1) = 20MHz */
                        PDB_SC_PDBIE(1) | /* PDB interrupt enabled */
                        PDB_SC_MULT(0) | /* 00: Multiplication factor is 1. */
                        PDB_SC_CONT(1) | /* Continuous mode of operation */
                        PDB_SC_PDBEN_MASK; /* 1: PDB enabled */

 

PDB0->CH[0].C1 |= PDB_C1_BB(0xFE) | // For Continuos Pre-Trigger Mode

                                 PDB_C1_TOS(0x00) | // Pretrigger Output Select: 0=bypassed , 1=enabled
                                 PDB_C1_EN(0xFF); // PDB channel's pre-trigger enabled

 

PDB0->MOD = 500; /* Specifies the period of the counter as 5000 */
PDB0->IDLY = 400; /* Specifies the delay value to schedule the PDB interrupt as 4000 */
// PDB0->CH[0].DLY[0] = 1; /* Pretrigger 0 : 1 * 50e-9 = 50e-9 */
// PDB0->CH[0].DLY[1] = 1; /* Pretrigger 0 : 1 * 50e-9 = 50e-9 */

 

PDB0->SC |= PDB_SC_LDOK_MASK;

 

//Enable_Interrupt(PDB0_IRQn);
PDB0_IRQ_Init();

 

PDB0->SC |= PDB_SC_SWTRIG_MASK; /* restart PDB counter */
}

 

void PDB0_IRQ_Init (void)
{
S32_NVIC->ICPR = 1 << PDB0_IRQn; /* IRQ11-FlexCAN ch0: clr any pending IRQ*/
S32_NVIC->ISER = 1 << PDB0_IRQn; /* IRQ11-FlexCAN ch0: enable IRQ */
S32_NVIC->IP[PDB0_IRQn] = 0x09; /* IRQ11-FlexCAN ch0: priority 10 of 0-15*/
}

 

void PDB0_IRQHandler(void)
{
   if( ( PDB0->SC & PDB_SC_PDBIF_MASK ) != 0 )
   {
      PDB0->SC &= ~PDB_SC_PDBIF_MASK; /* Write zero to clear PDBIF */

      PTE->PTOR |= 1 <<8; /* Toggle output on port D0 (blue LED) */

 

       ADC_U8_Int_Result[ADC_U8_ANI0] = ADC0->R[0];
      ADC_U8_Int_Result[ADC_U8_ANI1] = ADC0->R[1];
      ADC_U8_Int_Result[ADC_U8_ANI2] = ADC0->R[2];
      ADC_U8_Int_Result[ADC_U8_ANI3] = ADC0->R[3];
      ADC_U8_Int_Result[ADC_U8_ANI4] = ADC0->R[4];
      ADC_U8_Int_Result[ADC_U8_ANI5] = ADC0->R[5];
      ADC_U8_Int_Result[ADC_U8_ANI6] = ADC0->R[6];
      ADC_U8_Int_Result[ADC_U8_ANI7] = ADC0->R[7];

 

   PDB0->SC |= PDB_SC_SWTRIG_MASK; /* restart PDB counter */
   }

}

 

From This code i am able to get ADC Data But need to give PDB Software Trigger Every time Interrupt called. I need ADC Continuous Mode Operation so no need to give PDB SW Trigger Every time and When needed able to get ADC Reading. SO what changes should i made in this code. I tried with "PDB0->CH[0].C1 |= PDB_C1_BB(0xFF)" But not able to get ADC Reading.

 

Thanks&Regards,

Nimesh

Outcomes