<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: quadrature decoder / FTM how-to in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259260#M7866</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a look at this&amp;nbsp; application note, it could be helpful in your project.&lt;/P&gt;&lt;P&gt;"Configuring the FlexTimer for Position and Speed Measurement with an Encoder" (AN4381)&lt;/P&gt;&lt;P&gt;&lt;A href="http://cache.freescale.com/files/32bit/doc/app_note/AN4381.pdf?fsrch=1&amp;amp;sr=3" title="http://cache.freescale.com/files/32bit/doc/app_note/AN4381.pdf?fsrch=1&amp;amp;sr=3"&gt;http://cache.freescale.com/files/32bit/doc/app_note/AN4381.pdf?fsrch=1&amp;amp;sr=3&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Apr 2013 17:28:04 GMT</pubDate>
    <dc:creator>adriansc</dc:creator>
    <dc:date>2013-04-10T17:28:04Z</dc:date>
    <item>
      <title>quadrature decoder / FTM how-to</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259258#M7864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm attempting to enable the quadrature decoder in a K10 series part. I have an encoder connected to inputs PHA/B or PTA10 &amp;amp; 11, corresponding to FTM2. Reading the manual, in order to enable this, I need to set FTMEN and QUADEN.&amp;nbsp; Here's what I did:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FTM2_MODE = 0x00000005;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // WRTDIS bit is already set, default after reset.&lt;/P&gt;&lt;P&gt;FTM2_SC = 0x00000028;&lt;/P&gt;&lt;P&gt;FTM2_QDCTRL = 0x00000001;&lt;/P&gt;&lt;P&gt;FTM2_CNT = 100;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // manual says write to this before writing to FTM2_CNTIN&lt;/P&gt;&lt;P&gt;FTM2_CNTIN = 0;&lt;/P&gt;&lt;P&gt;FTM2_MOD = 0x00007fff;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The WRTEN bit is set, and the WRTDIS bit is clear.&lt;/P&gt;&lt;P&gt;The filters are off, and should be disabled, and the clock is enabled to the FTM.&lt;/P&gt;&lt;P&gt;If I turn the encoder, I can see the PHA/B inputs changing on the pins, checked with a scope.&lt;/P&gt;&lt;P&gt;The FTM2_MOD register never reflects the write of 0x00007ffff to it &amp;amp; I never get anything other than 0 in the FTM2_CNT register.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've read and reread the section of the manual on quadrature decoder mode, and I can't see anything in the block diagram or anywhere else that I'm not putting into the required state. I have also tried the same configuration with FTM1, and got the same results. What am I missing?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2013 22:52:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259258#M7864</guid>
      <dc:creator>stderr</dc:creator>
      <dc:date>2013-04-09T22:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: quadrature decoder / FTM how-to</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259259#M7865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your code seems ok to me. Only thing i can imagine is that the order of register writes could be important. Some of the registers like MOD have "write buffers" that only take effect later.&lt;/P&gt;&lt;P&gt;When I tested quadrature encoder mode the following code worked for me:&lt;/P&gt;&lt;P&gt;It is counting pulses on Phase A with the abbility to count up or down according to Phase B&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Flextimer 1 Setup / Quadrature Decoder Mode for counting pulses&lt;/P&gt;&lt;P&gt; SIM-&amp;gt;SCGC6&amp;nbsp;&amp;nbsp;&amp;nbsp; |= (1UL &amp;lt;&amp;lt;&amp;nbsp; 25);/* Enable FTM1 Clock&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; SIM-&amp;gt;SCGC5&amp;nbsp;&amp;nbsp;&amp;nbsp; |= (1UL &amp;lt;&amp;lt;&amp;nbsp; 10);/* Enable Port B Clock&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt; PORTB-&amp;gt;PCR[0]&amp;nbsp; = 0x00000600;&amp;nbsp; /* setup pin for FTM1 PHA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt; PORTB-&amp;gt;PCR[0]&amp;nbsp; = 0x00000600;&amp;nbsp; /* setup pin for FTM1 PHB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt; FTM1-&amp;gt;MODE = 0x00000005;&amp;nbsp;&amp;nbsp; /* enable advanced FTM registers */&lt;/P&gt;&lt;P&gt; FTM1-&amp;gt;CNTIN = 0x00000000;&amp;nbsp;&amp;nbsp; /* initial counter value after overflow */&lt;/P&gt;&lt;P&gt; FTM1-&amp;gt;CNT = 0x00000000;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* current count, writing reloads CNTIN */&lt;/P&gt;&lt;P&gt; FTM1-&amp;gt;MOD = 0x0000FFFF;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* overflow count -&amp;gt; free running counter */&lt;/P&gt;&lt;P&gt; FTM1-&amp;gt;SC = 0x00000048;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* FTM clock = 48MHz / 8 = 6.0 MHz, TOF interrupt enabled */&lt;/P&gt;&lt;P&gt; FTM1-&amp;gt;FILTER = 0x000000044;&amp;nbsp; /* input filter on PHA and PHB, adjusted for counting up to 1MHz signals */&lt;/P&gt;&lt;P&gt; FTM1-&amp;gt;QDCTRL = 0x000000D9;&amp;nbsp; /* quadrature decoder ensabled*/&lt;/P&gt;&lt;P&gt; NVIC_EnableIRQ(FTM1_IRQn);&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable FTM1 Interrupt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So try changing the order of your register writes. Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 07:14:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259259#M7865</guid>
      <dc:creator>paulmartin</dc:creator>
      <dc:date>2013-04-10T07:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: quadrature decoder / FTM how-to</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259260#M7866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a look at this&amp;nbsp; application note, it could be helpful in your project.&lt;/P&gt;&lt;P&gt;"Configuring the FlexTimer for Position and Speed Measurement with an Encoder" (AN4381)&lt;/P&gt;&lt;P&gt;&lt;A href="http://cache.freescale.com/files/32bit/doc/app_note/AN4381.pdf?fsrch=1&amp;amp;sr=3" title="http://cache.freescale.com/files/32bit/doc/app_note/AN4381.pdf?fsrch=1&amp;amp;sr=3"&gt;http://cache.freescale.com/files/32bit/doc/app_note/AN4381.pdf?fsrch=1&amp;amp;sr=3&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 17:28:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259260#M7866</guid>
      <dc:creator>adriansc</dc:creator>
      <dc:date>2013-04-10T17:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: quadrature decoder / FTM how-to</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259261#M7867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the suggestions. I found that if I write something other than 0 to the CNTIN register&amp;nbsp; I can count from&amp;nbsp; whatever I write up to 0 before the counter stops counting, &amp;amp; counting works in both directions. If I look at the FTM2_MOD register in codewarrior, it's always 0, no matter what I write to it. Not only that, but the FTM_CNT register doesn't appear to be writable either. It comes up with a count (consistently) but it's not what I wrote, ever. Are these registers locked, or only writable at certain times? Is FTM2_MOD not readable? Do I need to write something somewhere else first in order to make it work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 19:13:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259261#M7867</guid>
      <dc:creator>stderr</dc:creator>
      <dc:date>2013-04-10T19:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: quadrature decoder / FTM how-to</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259262#M7868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Write something to FTMx_CNT resets the counter to CNTIN value. Try the configuration that is on the AN:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//enable the clock for FTM1 &lt;/P&gt;&lt;P&gt; SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK; &lt;/P&gt;&lt;P&gt;//enable the counter&lt;/P&gt;&lt;P&gt; FTM1_MODE |= FTM_MODE_FTMEN_MASK; &lt;/P&gt;&lt;P&gt;//enable the counter to run in the BDM mode&lt;/P&gt;&lt;P&gt; FTM1_CONF |= FTM_CONF_BDMMODE(3); &lt;/P&gt;&lt;P&gt;//load the Modulo register and counter initial value&lt;/P&gt;&lt;P&gt; FTM1_MOD = 4095;&lt;/P&gt;&lt;P&gt; FTM1_CNTIN = 0; &lt;/P&gt;&lt;P&gt;//configuring FTM for quadrature mode&lt;/P&gt;&lt;P&gt; FTM1_QDCTRL |= FTM_QDCTRL_QUADEN_MASK; &amp;lt;---------------(Note)&lt;/P&gt;&lt;P&gt;// start the timer clock, source is the external clock&lt;/P&gt;&lt;P&gt; FTM1_SC |= FTM_SC_CLKS(3); &amp;lt;--------------------------------------(Note)&lt;/P&gt;&lt;P&gt;//configuring the input pins:&lt;/P&gt;&lt;P&gt; PORTA_PCR8 = PORT_PCR_MUX(6); // FTM1 CH0&lt;/P&gt;&lt;P&gt; PORTA_PCR9 = PORT_PCR_MUX(6); // FTM1 CH1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;P&gt;There is something important here, QUADEN field selects quadrature mode for FTM and has to be written before FTM configuration. Also FTM1_SC[CLKS] needs to be 0 during the configuration in order to apply changes, after that you need to select a Clock Source.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 18:26:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259262#M7868</guid>
      <dc:creator>adriansc</dc:creator>
      <dc:date>2013-04-11T18:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: quadrature decoder / FTM how-to</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259263#M7869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank-you Adrian!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That you can't write FTMx_MOD and FTMx_CNTIN while the clock is enabled into the quadrature decoder is the piece of information I didn't understand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure about the philosophy behind such a restriction, but so long as I can make it do what I need, so be it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 20:37:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259263#M7869</guid>
      <dc:creator>stderr</dc:creator>
      <dc:date>2013-04-11T20:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: quadrature decoder / FTM how-to</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259264#M7870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might also get some benefit from my working implementation, complete with Index capture, in:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/thread/304806"&gt;QEI inputs, and index capture&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 May 2013 00:56:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/quadrature-decoder-FTM-how-to/m-p/259264#M7870</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2013-05-01T00:56:16Z</dc:date>
    </item>
  </channel>
</rss>

