FTM Quad Decoder with A/B/Z on TWR-K64F

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

FTM Quad Decoder with A/B/Z on TWR-K64F

922 Views
aberger
Contributor V

I am using a TWR-K64F-120M dev board and would like to input quadrature decoder A, B, and Z inputs. I have been able to successfully run the ftm_quad_decoder example based on A/B inputs. However, this demo uses FTM2. The 144-pin MAP BGA chip that I have only has pins available for CH0 and CH1 for FTM2. It does however have all 8 channels for FTM0, but in this case, there is no QD_PHA or QD_PHB (quadrature phase A and phase B) ALT functionality for any of the 8 pins, so it's not obvious to me how to set up FTM0 for this mode. 

For example, I can modify the FTM0_QDCTRL register, but how do I specify which of the 8 channels correspond to A, B, and Z?

Are there demo projects that I could reference for setting up A/B/Z decoding?

Labels (1)
0 Kudos
4 Replies

615 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Andy,

Regarding your question that you want to use Z pulse to reset the FTM counter FTM_CNT, i think it is okay to use both software triggering or hardware triggering to reset the FTM_CNT register.

If you use software triggering, you can connect the Z pulse to GPIO pin and trigger an interrupt with edge of the pulse, in the GPIO ISR, you can increments the revolution variable and reset the FTM_CNT by the code while the SWRSTCNT bit in FTMx_SYNCONF must be set.

FTM0_SYNC|=FTM_SYNC_SWSYNC_MASK;

If you use hardware triggering, the Z pulse has to be connected to the FTM hardware triggering pin. I attach the FTM hardware triggering pin for K64:

The edge of Z pulse can reset the FTM_CNT register if you set the HWRSTCNT in FTMx_SYNCONF.

Hope it can help you

BR

Xiangjun Rong

pastedImage_1.png

0 Kudos

615 Views
aberger
Contributor V

As a workaround, I decided to simply feed the Z index signal to a GPIO pin and write an ISR triggered by a rising edge on that pin. 

I've therefore tried to modify the original ftm_quad_decoder example code. I'm using PTB18 and PTB19 as FTM2_QD_PHA and FTM2_QD_PHB. This works perfectly if I run the original example code (it sends back the appropriate quad counter value based on a 1 s interrupt triggered by the PIT). 

In the attached code, I simply replace the PIT ISR with a GPIO-edge detect ISR on GPIO4 (GPIOB, Pin 8). 

The GPIO trigger seems to be firing just fine, but the Quad Decoder counter never changes from 0. As far as I can tell (by using a difftool), the FTM code attached here is identical to the ftm_quad_decode example file. Am I missing some initialization code that starts the quad counter?

0 Kudos

615 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Andy,

First of all, as you see that the K64 has 4 FTM modules:FTM0, FTM1, FTM2 and FTM3, only FTM1 and FTM2 supports quadrature decoder function, FTM0/FTM3 which have 8 PWM channels do not support quadrature decoder function. For detailed inf, pls refer to section 3.8.2 FlexTimer Configuration in Reference Manual of K64.

As you know that the quadrature decoder should have 4 signal: PhaseA, PhaseB, Index and Home, user can use Index signal to count the revolution, use the Home signal to Reset the quadrature decoder counter. But the quaduarure decoder feature of FlexFTM module does not have Index and Home pins, in other words, the quaduarure decoder feature of FlexFTM module does not implement the quadrature decoder function fully, it only implements the position counting. For revolution function, I suppose that byou can connect the Index pin to LPTMR input pin so that the LPTMR can gives the revolution. Of course, it is okay to use GPIO interrupt function to count index, but it needs core involvement.

The code you attached is used to generate PWM signals based on FTM0 and FTM1, maybe you posted by mistake.

Hope it can help you

BR

Xiangjun Rong

0 Kudos

615 Views
aberger
Contributor V

My apologies. I've now uploaded the correct version of the demo program. 

You mention that using GPIO interrupt to count the index will require core involvement. I realize that I could use another timer channel (LPTMR or another FTM instance) to simply count the Z index and keep track of revolutions, but I would also like a Z pulse to reset the Quad Decoder counter (i.e. to make sure I haven't counted extra or missed any quad counts). So will that necessarily require core involvement, or is there a way to trigger a reset of the quad counter with a sync event caused by the Z pulse? It seems that "FTM counter synchronization" (RM, 40.4.11.10) might be a way to do this.

0 Kudos