Pulse counter with MK60DN512 and MQX 3.7

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

Pulse counter with MK60DN512 and MQX 3.7

905 Views
feraro
Contributor IV

Hello.
I am working with micro K60DN512, CodeWarrior 10.3 and MQX 3.7. Need to measure a time interval of 2 msec around 3500 pulses. I've tried using dual-edge FlexTimer, but does not give me the accuracy I need. Could anyone advise an alternative?.
Thank you very much.

0 Kudos
Reply
3 Replies

402 Views
paulmartin
Contributor III

Hi,

Could you specify a bit more what you actually need to achieve.

Are the pulses uniform/ constant frequency or random? What accuracy do you need? Do you need a continuous measurement, like a pulse rate  measurement every 2 msec or is it a single measurement?

one alternative for example is the clock input of the FTM counter. It counts up with every pulse of the input up to I think a quarter of the bus clock.

second alternative: the quadrature decoder mode of the FTM can count up and down.

Martin

0 Kudos
Reply

402 Views
feraro
Contributor IV

Hi Martin.


Thank you very much for your answer.
Let me explain better. Every 10 msec, for 2 msec, pulses reach me, at a constant frequency which can be between 1.4 and 1.7 MHz. My purpose is to measure the frequency. I tried dual-edge mode but I have the problem that a system clock frequency of 50 MHz, the values ​​that are read between 28 and 35 respectively. And this for my application is very low resolution. Would need to get the frequency in MHz with two decimals.
I need something to count the pulses in an interval of time without working the mic, so that I can check then.


Thanks again.


Fernando.


0 Kudos
Reply

402 Views
paulmartin
Contributor III

Counting pulses is not the problem. The problem will be fixing the interval and synchronizing with the 10msec cycle.

If you know that the pulses are send for exactly 2 msec this is a possible solution:

Use the clock input FTM_CLKIN0/1 ( if you dont use EXTAL/XTAL pins ) or the quadrature decoder mode ( multiple options here: any pin with FTMX_QD_PHA ).

Both allow you to count pulses.

Then your measurement cycle could be like this.

-reset the counter to 0

-wait 10msec ( time for other computations )

-read the counter and compute frequency

(accuracy should be fine since you have about 3000 pulses)

If the pulses are sent for a variable amount of time, you would need more intervention from the processor.

- trigger an interrupt on the first pulse and then reset the counter to 0

- wait for as long as you are guaranteed to have pulses

- read the counter and compute frequency

or

- set the modulo of the counter to lets say 2500 and trigger another interrupt on this overflow event. But then you need a second FTM module to know how much time has passed for the 2500 pulses.

( this also suffers from the possibility that another interrupt may cause a variable delay between the overflow and your code to read the time)

Does your application have some kind of synchronization mechanism, like a pulse on a separate line 1 msec before the next set of pulses arrive. Or are the pulses somehow triggered by the MCU?