Pulse not counting properly using LPTMR

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

Pulse not counting properly using LPTMR

Jump to solution
1,315 Views
shabana
Contributor II

Hi,

In using LPTMR to count the pulse.

here is the snip shot of the code

void lptmr_pulse_count(uint32 count_val, int pc_src, int psg_src)

{

  // Reset LPTMR module

  lptmr_clear_registers();

  // For interupt handler

  lptmr_mode = LPT_CNTR_MODE;

  // Enable LPT Interrupt in NVIC

  enable_irq(LPTMR_IRQ_NUM); // LPTMR Vector is 101. IRQ# is 101-16=85

  // Set up the interrupt vector for counter == compare val

  // Set the compare value

  LPTMR0_CMR = count_val;

  // Set up LPTMR to bypass prescaler clock

  LPTMR0_PSR = (LPTMR_PSR_PBYP_MASK | LPTMR_PSR_PCS(psg_src));

  // select pulse counter mode, pulse counter clk src, and interrupt enable.

  LPTMR0_CSR |= LPTMR_CSR_TMS_MASK | LPTMR_CSR_TPS(pc_src) | LPTMR_CSR_TIE_MASK;

  LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;

  lptmr_intrpt = 0;

  return;

}

count_value = 0xFFFF

clock source is LPO.

in oscilloscope I counted the pulse it is 22 but in CNR register the value is 69.. please see the image for the pulse

Labels (1)
1 Solution
988 Views
yasuhikokoumoto
Senior Contributor I

Hi Shabana m,

do you mean the glitch filter clock is LPO?
However you disabled (or bypassed) the glitch filer.
I think the error came from the input signal glitch.
Therefore you should better set the glitch filter as the following
because your input signal is 2.27MHz and LPO is 1kHz.

[before]
LPTMR0_PSR = (LPTMR_PSR_PBYP_MASK | LPTMR_PSR_PCS(psg_src));

[after]
LPTMR0_PSR = (LPTMR_PSR_PRESCALE(0x6) | LPTMR_PSR_PCS(psg_src));
// PBYP=0 PCS=psg_src=0b01(?) PRESCALE=0b0110=128cycles(220cycles would be best but not available)

This means that the input low level should keep longer than 128ms and the high level should keep longer than 128ms.

I hope this will help you.

Best regards,
Yasuhiko Koumoto.

View solution in original post

2 Replies
989 Views
yasuhikokoumoto
Senior Contributor I

Hi Shabana m,

do you mean the glitch filter clock is LPO?
However you disabled (or bypassed) the glitch filer.
I think the error came from the input signal glitch.
Therefore you should better set the glitch filter as the following
because your input signal is 2.27MHz and LPO is 1kHz.

[before]
LPTMR0_PSR = (LPTMR_PSR_PBYP_MASK | LPTMR_PSR_PCS(psg_src));

[after]
LPTMR0_PSR = (LPTMR_PSR_PRESCALE(0x6) | LPTMR_PSR_PCS(psg_src));
// PBYP=0 PCS=psg_src=0b01(?) PRESCALE=0b0110=128cycles(220cycles would be best but not available)

This means that the input low level should keep longer than 128ms and the high level should keep longer than 128ms.

I hope this will help you.

Best regards,
Yasuhiko Koumoto.

988 Views
shabana
Contributor II

Hi Yasuhiko koumoto,

Thank u sooooo much...Its working... :smileyhappy:

Best regards,

Shabana

0 Kudos
Reply