LPTMR0 as Pulse Counter

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

LPTMR0 as Pulse Counter

Jump to solution
1,391 Views
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

Labels (1)
Tags (3)
0 Kudos
Reply
1 Solution
779 Views
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

View solution in original post

0 Kudos
Reply
2 Replies
779 Views
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 Kudos
Reply
780 Views
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 Kudos
Reply