Pulse not counting properly using LPTMR

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Pulse not counting properly using LPTMR

跳至解决方案
2,177 次查看
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

标签 (1)
1 解答
1,850 次查看
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.

在原帖中查看解决方案

2 回复数
1,851 次查看
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.

1,850 次查看
shabana
Contributor II

Hi Yasuhiko koumoto,

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

Best regards,

Shabana

0 项奖励
回复