AnsweredAssumed Answered

LPTMR as Pulse Counter Problem

Question asked by yar on Sep 24, 2014
Latest reply on Oct 6, 2014 by yar

Hi, I've got a custom MKL15Z128VFT4 board and trying to use LPTMR0 as pulse counter. Here is my code:

 

  unsigned int compare_value = 1;
  serial.baud(115200);

  /* Clock the timer */
    SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK;
  /* reset the counter */
  LPTMR0->CSR = 0;
  /* turn on portc */
  SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK; //Turn on PORTC clock
    PORTC->PCR[5] = PORT_PCR_MUX(0x4); //Use ALT2 on PTC5

  LPTMR0->PSR = LPTMR_PSR_PCS(0x1) | LPTMR_PSR_PBYP_MASK; //Use LPO clock but bypass glitch filter
  LPTMR0->CMR = LPTMR_CMR_COMPARE(compare_value);  //Set compare value
  /* set pulse mode */
  LPTMR0->CSR = LPTMR_CSR_TPS(0x2) | LPTMR_CSR_TMS_MASK; //Set LPT to use the pin selected, and put in pulse count mode, on rising edge (default)
  /* start pulse counter */
  LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;

  while(1) {
       if(LPTMR0->CNR != 0)
            printf("Current value of pulse count register CNR is %d\r\n", LPTMR0->CNR);
  }

 

I followed an example here http://peninsula.googlecode.com/svn/trunk/Kinetis512/kinetis-sc/src/projects/lptmr/lptmr_pulse.c

also tried to use PORT_PCR_MUX(0x3) and even PORT_PCR_MUX(0x2) with no luck - the value of LPTMR0_CNR is always 0.

Did I miss something? Will appreciate any help.

Outcomes