Pulse not counting properly using LPTMR

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Pulse not counting properly using LPTMR

ソリューションへジャンプ
1,320件の閲覧回数
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 解決策
993件の閲覧回数
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 返答(返信)
994件の閲覧回数
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.

993件の閲覧回数
shabana
Contributor II

Hi Yasuhiko koumoto,

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

Best regards,

Shabana

0 件の賞賛
返信