LPTMR to trigger ADC

cancel
Showing results for 
Search instead for 
Did you mean: 

LPTMR to trigger ADC

448 Views
Contributor III

Hello,

I am using the KL05-FRDM board. I want to trigger ADC conversions, via the LPTMR.

The LPTMR can be clocked by the MCRIRCLK (which is 32KH). I am toggling a pin with a value of '1' in

the CMR register. This si sdone to c the minimum clock/cycle. I saw that it is 2.5msecs, which is something

I was not expecting. WIth a prescaler of 2- the clock wld be 16KH. So a an avg of 62uSecs is what I was expecting.

The code is given -

int main(void)

{

    int count;

    uint16_t countTemp = 0;

  

  

  

                     

    SIM_SOPT1 = 0;                                           

    SIM_SCGC5 |= (SIM_SCGC5_LPTMR_MASK | SIM_SCGC5_PORTB_MASK);//PORTC_PCR1 |= PORT_PCR_MUX(1);//select RTC_CLKIN function

    PORTB_PCR8 |= 0x00000100;    // alternative pin mux selection //

    GPIOB_PDDR |= 0x00000100;    // pin direction //  

  

    SIM_SCGC5|=SIM_SCGC5_LPTMR_MASK;

      /* Reset LPTMR settings */

      SIM_SOPT1 = 0;                                           

    SIM_SCGC5 |= (SIM_SCGC5_LPTMR_MASK | SIM_SCGC5_PORTB_MASK);//PORTC_PCR1 |= PORT_PCR_MUX(1);//select RTC_CLKIN function

  

      LPTMR0_CSR=0;    

      /* Set the compare value to the number of ms to delay */    

      LPTMR0_CMR = 1;

      /* Start the timer */   

      LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;

      /* Wait for counter to reach compare value */

      while(1){

          while (!(LPTMR0_CSR & LPTMR_CSR_TCF_MASK));

          /* Disable counter and Clear Timer Compare Flag */    

          LPTMR0_CSR &= ~LPTMR_CSR_TEN_MASK;

          LPTMR0_CSR |= LPTMR_CSR_TCF_MASK;

          GPIOB_PTOR |= (1<<8);

          LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;

      }     

}

Can anyone pls advice me why this is happening.

Vinod.

0 Kudos
3 Replies

23 Views
NXP Employee
NXP Employee

Out of RESET the default hardware trigger for the ADC points to the TPMx channel trigger. Therefore, you need to select the ADC alternate hardware trigger, this can be done if you write to the SIM_SOPT7 register

SIM_SOPT7 = SIM_SOPT7_ADC0ALTTRGEN_MASK | SIM_SOPT7_ADC0TRGSEL( 14 );

ADC_LPTMR.png

You didn't post the ADC configuration, at the ADC registers you need to be sure that the hardware trigger option is selected. ADCx_SC2 - ADTRG bit

Hope this helps

- Alejandra

0 Kudos

23 Views
Contributor III

Hello Alejandra,

Thank you very much indeed for ur response.

I was aware of this. My issue is with the LPTMR clock/count.

If it can be clocked by the 32KH (MCGIRCLK), then, it shld be giving me

a clock pulse cycle of a few 10s of micro seconds when LPTMR0_CMR =1.

But, I am getting 2.5msecs with the same CMR value. The prescaler is a divided by 2 , value , so making it effectively 16Kh or so.

Hope you get my query pls.

Than k u.

Vinod .

0 Kudos

23 Views
NXP Employee
NXP Employee

Hi,

Do you still have some queries regarding the issue posted in this thread?

Please do not hesitate to ask if you are still having questions.


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer

0 Kudos