Unable to invert polarity of encoder input

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to invert polarity of encoder input

434 Views
dave408
Senior Contributor II

In my previous implementation of QD with FTM1 and FTM2 on my K22F processor, I didn't bother to check for the correct sign on the feedback because I figured I could just invert it or swap the wires.  Well, now I'm back to testing and have found that the sign is incorrect.

On other processors I have used, like the dsPIC, I can just invert the polarity of the input channels.  I've tried this in the following ways:

  1. set the FTM_QDCTRL_PHAPOL_MASK and FTM_QDCTRL_PHBPOL_MASK bits in FTMx_QDCTRL
  2. cleared the FTM_QDCTRL_PHAPOL_MASK and FTM_QDCTRL_PHBPOL_MASK bits in FTMx_QDCTRL
  3. set the Invert Polarity setting in Processor Expert
  4. all permutations of the above

In *all* cases, the sign of my encoder value is always the same.  I would have expected one of the combinations to result in a flipped sign.

In the process of debugging this, I realized that I had never checked the "Quadrature decode initialization" checkbox in processor expert:

pastedImage_1.png

I interpreted this to mean that even though I have "Quadrature decode configurations" checked, the settings in the configuration list as shown below would *not* take effect:

pastedImage_3.png

So I also tried to check "Quadrature decode initialization", but when I did this, the encoder readings I got back had the wrong sign *and* magnitude.

At this point, I'm under the impression that 1) I am missing an undocumented step (perhaps another register needs to be cleared before I can invert polarity, 2) processor expert has a bug, or 3) I should just punt on this and swap the wiring.

Can anyone shed some light on this problem that I'm experiencing?

Tags (4)
0 Kudos
6 Replies

155 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Dave,

I hope you can attach your project so that we can review if the SDK generates correct code.

BR

Xiangjun Rong

0 Kudos

155 Views
dave408
Senior Contributor II

Hi xiangjun.rong​, would you mind looking over my original post to see if what I have done makes sense?  Thanks!

0 Kudos

155 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Dave,

As you know the purpose of the "Quadrature Decoder" module is to count the edges of both PhaseA and PhaseB to get position inf and to indicate the direction of rotation. Regarding your remark "In all cases, the sign of my encoder value is always the same", I suspect that you misunderstand the "sign" of encoder", firstly, the FTM_CNT can NOT be a negative value, the "sign of FTM encoder" represents the direction of counting. For example, if the rising edge of phaseB lags behind of that of PhaseA, the FTM_CNT will have addition operation for each edges of both PhaseA and PhaseB: 1,2,3,4,5,6...MOD-1, 0,1,2,3. If the rising edge of phaseB is ahead of that of PhaseA, the FTM_CNT will have subtraction operation for each edges of both PhaseA and PhaseB:...6,5,4,3,2,1,0,MOD-1,MOD-2,... The QUADDIR bit in FTMx_QDCTRL reflects the counting direction.

Of course, changing the polarity of PhaseA or PhaseB can change the counting direction. You can change the PHAPOL or PHBPOL bits in the FTMx_QDCTRL to change the counting direction, but you can change only ONE bit of PHAPOL or PHBPOL instead of both so that you can change the counting direction.

BR

XiangJun Rong

0 Kudos

155 Views
dave408
Senior Contributor II

I understand that it's an inversion of the encoder counting depending upon the relative phase lag of A and B.  I just call it the "sign" because we (at work) talk about a load moving in "the negative direction" or "the positive direction", so it is unfortunately natural for me to refer to it as "sign".  :smileyhappy:

I'm not looking for a negative FMT_CNT value -- I already have negative counts working based off of the bit in the register.  What I'm looking for is the programmatic equivalent of physically swapping the A and B encoder channel wires on my PCB.  In my particular application, I ended up having to swap the wires because I couldn't get it to swap by changing the register values. 

I just wanted someone to take a look at the information I had posted in my original post and let me know if what I had done there should have effectively swapped the A and B channels (i.e. count in the reverse direction).

0 Kudos

155 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Dave,

Okay, I see your question, unfortunately, the FTMx_QD_PHA and FTMx_QD_PHB pins are hardware connection, there is not software solution to exchange the two signals. But I think changing anyone  of the two PHAPOL or PHBPOL bits in the FTMx_QDCTRL can change the "sign" as you called. In SDK, it is okay to use the "Inverted Polarity" for only one signal.

Hope it can help you.

Have a nice Christmas day.

BR

Xiangjun Rong

0 Kudos

155 Views
dave408
Senior Contributor II

Hi xianjun, I cannot attach the project here, but I could email it to support since it's technically confidential.  But can you please still comment on the bitmask that I had used to try to get it to invert w/o using Processor Expert (shown above in my original post)?

0 Kudos