LPTMR0 as Pulse Counter

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

LPTMR0 as Pulse Counter

ソリューションへジャンプ
1,364件の閲覧回数
sebasira
Senior Contributor I

Hello everybody!

I'm working with K60N512, I'm trying to develop an odometer. I guess the best way to accomplish that is with the pulse counter, to measure wheel pulses, and then get the speed and distance with a simple conversion.

But I can not make the counter to increment.

This is how I configure the LPTMR0:

SIM_SCGC5 |= SIM_SCGC5_LPTIMER_MASK;// Enable LPT Module


// Reset LPTMR module

LPTMR0_CSR = 0x00;

LPTMR0_PSR = 0x00;

LPTMR0_CMR = 0x00;

// I choose PRESCALER = 1, because it says 0 is not supported on pusle counter mode

LPTMR0_PSR = LPTMR_PSR_PRESCALE(1) | LPTMR_PSR_PBYP_MASK;  // bypass glicth filter

LPTMR0_CSR |= LPTMR_CSR_TPS(2);            // Input pin select

LPTMR0_CSR &= ~LPTMR_CSR_TPP_MASK;  // Rising Edge

LPTMR0_CSR |= LPTMR_CSR_TMS_MASK;     // Timer as Pulse Counter

LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;     // Turn on LPTMR

Then I've got a function generator (square wave) connected to PTC5 (LPTMR0_ALT2), but the counter valur remains zero.

Am I missing something?

Thanks in advance!!

Best Regards,

SebaS

ラベル(1)
タグ(3)
0 件の賞賛
返信
1 解決策
752件の閲覧回数
sebasira
Senior Contributor I

Well I figure it out!

The correct value for MUX is 4 and the CMR register must have some value non-zero. So it counts till that value, and sets TCF flag when that value is reached. Also start over counting from zero.

Maybe someone could find it usefull.

SebaS

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
752件の閲覧回数
sebasira
Senior Contributor I

I've notice I've forgot to enable the PIN, but it is still not working

SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; //Turn on PORTC clock

PORTC_PCR5=PORT_PCR_MUX(0x3); //Use ALT3 on PTC5

About MUX value, the demo from IAR sets it to be 4... but on K60N512 Reference Manual I can see that it should be 3. What's the rigth value?

0 件の賞賛
返信
753件の閲覧回数
sebasira
Senior Contributor I

Well I figure it out!

The correct value for MUX is 4 and the CMR register must have some value non-zero. So it counts till that value, and sets TCF flag when that value is reached. Also start over counting from zero.

Maybe someone could find it usefull.

SebaS

0 件の賞賛
返信