Fast Counter MK21FNM0VMD12

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

Fast Counter MK21FNM0VMD12

746 Views
ralf1694
Contributor III

Hi. I implemented an VRZ for my K21 with PHA and PHB.

But now I need a counter, which counting up/down when PHA is high or on rising / falling edge. I have only one phase (PHA).

I sampled it with the quadrature mode, but I think this is the wrong way.

Is there an other solution, how I can use the PHA to increment/decrement my counter?

When I use the normal FTM up counting mode my counter counting but not in the mercy of my PHA?

Have anybody an idea?

rgds Oliver

5 Replies

636 Views
egoodii
Senior Contributor III

Quadrature-mode requires interleaved edges on BOTH PHA and PHB to count -- the direction being defined by the interplay of 'high'/'low' 'rising'/falling' on both inputs.  Toggling just one input will simply make the counter go 'up' and 'down' 1 count on successive edges.

You don't explain further how you want to define whether you count 'up' or 'down' on any given edge of your 'clock'.  If you generally just want 'one way or the other' you simply select an external clock for the FTM in question and supply your signal to such external-clock-capable pin.  FTM will then count 'up' on one of 'rising' or 'falling' edges, and you can programmatically compute counts in an interval as 'one way or the other'.  If you want to supply a faster, externally-defined understanding of 'up' vs. 'down' you will have to build a bit of external hardware that will convert 'count & direction' into the 'PHA/PHB' sequence.

This will make rising-edges into quadrature:

Quadrature.GIF

Direction control can be implemented by letting it control a pair of 2to1 muxes that select either these /Q, Q feedback points OR their inverse (Q, /Q) (or exclusive-or gates).

636 Views
ralf1694
Contributor III

Thanks Earl that was very helpful! If I want to select an external clock for my FTM counter and the counter direction should be in up counting mode.

The K21 has an FTM_CLKN0 (pin IN24) and FTM_CLKN1 (pin 25). Can I use other pins for my external clock for example the FTM1_MOD_A (PTC18)? And how I do it. I try to change it in the SIM->SOPT4->FTM1CLKSEL but it does not work. On the rising edge from my external clock my counter should count up but the counter is always 0.

0 Kudos

636 Views
ralf1694
Contributor III

Sorry not FTM1_MOD_A (PTC18). I mean FTM1_QD_PHA (PTA8)

0 Kudos

636 Views
egoodii
Senior Contributor III

I'm not quite clear what part/package you are working with, but as you state the K21 family generally has two external FTM clock functions, that might be muxable (as ALT4) on either of PTA18/PTB16 and PTA19/PTB17.  As you note SOPT4 has a role in picking 'which one' is the external clock option, which you can then select as 0b11 in the CLKS field of FTMx_SC.  You will have to confirm pin function/mux options in the reference-manual for your particular chip, but 'where you can hook the clock' will be limited to those options.

636 Views
ralf1694
Contributor III

Thanks :smileyhappy:

0 Kudos