FlexTimer for Quadrature Decoder on K66 - How to

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

FlexTimer for Quadrature Decoder on K66 - How to

921 Views
xabier_arauzo
Contributor I

Hi everyone,

I own a Teensy 3.6 which runs a K66. I am currently trying to read the pulses of an encoder using the Quadrature Decoder mode of the FlexTimer Module 1 (FTM1).

First of all, I don't have the encoder with me, so I simulated the signals using the FTM0 Output Compare with the following code:

//initialise Flextimer 1
FTM0_MODE = 0x05; //set write-protect disable (WPDIS) bit to modify other registers
//FAULTIE=0, FAULTM=00, CAPTEST=0, PWMSYNC=0, WPDIS=1, INIT=0, FTMEN=1(no restriction FTM)
FTM0_SC = 0x00; //set status/control to zero = disabled (enabled in main loop)
FTM0_CNT = 0x0000; //reset count to zero
FTM0_MOD = FTM1MODCount; //max modulus = 23 (gives count = 24 on roll-over - 1 MHz)
FTM0_C0SC = 0x14; // CHF=0, CHIE=0 (disable interrupt), MSB=0 MSA=1, ELSB=0 ELSA=1 (output compare - toggle), 0, DMA=0
FTM0_C1SC = 0x14; // CHF=0, CHIE=0 (disable interrupt), MSB=0 MSA=1, ELSB=0 ELSA=1 (output compare - toggle), 0, DMA=0

//configure Teensy pins as outputs
PORTC_PCR1 = PORT_PCR_MUX(0x4);
PORTC_PCR2 = PORT_PCR_MUX(0x4);

//enable system clock (48 MHz), no prescale
FTM0_C0V = 0; //compare value = 0
FTM0_C1V = 0x8000; //compare value = 12
FTM0_SC = 0x0A; // (Note - FTM0_SC [TOF=0 TOIE=0 CPWMS=0 CLKS=01 (System Clock 48 MHz) PS=000 [no prescale divide])

This code works, as I can see the Pulses of 114 Hz on my osciloscope, so I don't think this is part of the problem.

Then, I run the following code in order to set the QD mode on my FTM1 (which is supported by the FTM1 in the K66):

SIM_SCGC6|=0x03000000; //enable FTM1 module clock

PORTA_PCR12 |= 0x300; //MUX = alternative function 3 on Chip Pin 28 (FTM1_CH0) = Teensy Pin 3
PORTA_PCR13 |= 0x300; //MUX = alternative function 3 on Chip Pin 29 (FTM1_CH1) = Teensy Pin 4

FTM1_MODE = 0x04;
FTM1_MODE = 0x05;
FTM1_C0SC = 0; //54
FTM1_C1SC = 0;


FTM1_CNT = 0;
FTM1_MOD = 0;
FTM1_C0SC = 0b00011100; // Set dual-capture both edges
FTM1_C1SC = 0b00011100; // Set dual-capture both edges
FTM1_SC = 0;
FTM1_MOD = 0xFFFF;
FTM1_CNTIN = 0;
FTM1_QDCTRL = 0x1;
FTM1_CNT = 0;

FTM1_SC=0x8;

Using this code I know the following. The MOD register gets modified, the CNT does not count up nor down and the QDCTRL enable bit is set high. I have tryed this code both using the FTM1_CnSC registers and without them (when use them, the CHF bit (interrupt flag) always goes up, even if I disable the interrupts).

If anyone can help me, I would really appreciate it.

PS: I have first tryed reading the other questions on this topic from the Forum, but could not get it working anyways.

0 Kudos
1 Reply

844 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Xabier,

 

I highly recommend you to check our SDK examples we offer for K66 devices. You can find ftm_quad_decoder demo that describes the usage of Quad Decoder feature in FTM module, which can be used to count the position of decoder.

You can download our SDK from the following link: Welcome | MCUXpresso SDK Builder 

Best regards,

Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos