<?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 FTM QuadratureDecoder in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-QuadratureDecoder/m-p/1034142#M56613</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to read the quadrature signals generated by motor's encoder.&lt;/P&gt;&lt;P&gt;I implemented a solution similar to the example "ftm_quad_decoder" with the difference that I use a global variable to add the values read to each timer interrupt, and instead of PIT timer I use FTM timer&amp;nbsp;which trips very quickly (every 100 ms) so as not to have overflow problems.&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;void EncoderTimerInit(MotorStatus* motorStatus) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;hal_timer_handle_t halTimerHandle =&lt;SPAN style="font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: medium;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;(hal_timer_handle_t) (&amp;amp;halTimerHandleBuffer[0]);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;hal_timer_config_t halTimerConfig;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;halTimerConfig.timeout = 100;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;halTimerConfig.srcClock_Hz = CLOCK_GetBusClkFreq();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;halTimerConfig.instance = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;HAL_TimerInit(halTimerHandle, &amp;amp;halTimerConfig);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;HAL_TimerInstallCallback(halTimerHandle, &amp;amp;TimerCallBack,&lt;SPAN style="font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: medium;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;(void*) (motorStatus));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;HAL_TimerEnable(halTimerHandle);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px; background-color: #f6f6f6;"&gt;void TimerCallBack(void* param)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;MotorStatus* motorStatus = (MotorStatus*) param;&lt;BR /&gt;&amp;nbsp;volatile int16_t value = 0;&lt;BR /&gt;&amp;nbsp;value = FTM_GetQuadDecoderCounterValue(QUAD_DECODER_COUNTER);&lt;BR /&gt;&amp;nbsp;FTM_ClearQuadDecoderCounterValue(QUAD_DECODER_COUNTER);&lt;BR /&gt;&amp;nbsp;encoder_count += value;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px; background-color: #f6f6f6;"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately I have seen that in this way the value read is quite far from what is expected.&lt;/P&gt;&lt;P&gt;Could it be that instructions &lt;SPAN style="display: inline !important; float: none; background-color: #f6f6f6; color: #3d3d3d; font-family: courier new,courier,monospace; font-size: 11px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;FTM_GetQuadDecoderCounterValue&lt;/SPAN&gt; e&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #f6f6f6; color: #3d3d3d; font-family: courier new,courier,monospace; font-size: 11px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;FTM_ClearQuadDecoderCounterValue&lt;/SPAN&gt;&amp;nbsp;take some time so while motors are in movement I lose some values?&lt;/P&gt;&lt;P&gt;Is better to leave timer free running (MOD = 0xFFFF) and use overlap callback?&lt;/P&gt;&lt;P&gt;In this case how a can&amp;nbsp;how can I understand the verse of the overflow? I saw in the "&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;ftm_quad_decoder" example&lt;/SPAN&gt; are defined several variables (&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;dir_when_overflow&lt;/SPAN&gt;,&amp;nbsp;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;counter_overflow_flag&lt;/SPAN&gt;,&amp;nbsp;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;counter_overflow_count&lt;/SPAN&gt;) that are defined but now used,&amp;nbsp;therefore not showing this type of use...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Mar 2020 13:55:37 GMT</pubDate>
    <dc:creator>LArmstrong1985</dc:creator>
    <dc:date>2020-03-30T13:55:37Z</dc:date>
    <item>
      <title>FTM QuadratureDecoder</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-QuadratureDecoder/m-p/1034142#M56613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to read the quadrature signals generated by motor's encoder.&lt;/P&gt;&lt;P&gt;I implemented a solution similar to the example "ftm_quad_decoder" with the difference that I use a global variable to add the values read to each timer interrupt, and instead of PIT timer I use FTM timer&amp;nbsp;which trips very quickly (every 100 ms) so as not to have overflow problems.&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;void EncoderTimerInit(MotorStatus* motorStatus) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;hal_timer_handle_t halTimerHandle =&lt;SPAN style="font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: medium;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;(hal_timer_handle_t) (&amp;amp;halTimerHandleBuffer[0]);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;hal_timer_config_t halTimerConfig;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;halTimerConfig.timeout = 100;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;halTimerConfig.srcClock_Hz = CLOCK_GetBusClkFreq();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;halTimerConfig.instance = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;HAL_TimerInit(halTimerHandle, &amp;amp;halTimerConfig);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;HAL_TimerInstallCallback(halTimerHandle, &amp;amp;TimerCallBack,&lt;SPAN style="font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: medium;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;(void*) (motorStatus));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;&amp;nbsp;HAL_TimerEnable(halTimerHandle);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px;"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px; background-color: #f6f6f6;"&gt;void TimerCallBack(void* param)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;MotorStatus* motorStatus = (MotorStatus*) param;&lt;BR /&gt;&amp;nbsp;volatile int16_t value = 0;&lt;BR /&gt;&amp;nbsp;value = FTM_GetQuadDecoderCounterValue(QUAD_DECODER_COUNTER);&lt;BR /&gt;&amp;nbsp;FTM_ClearQuadDecoderCounterValue(QUAD_DECODER_COUNTER);&lt;BR /&gt;&amp;nbsp;encoder_count += value;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: courier new,courier,monospace; font-size: 11px; background-color: #f6f6f6;"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately I have seen that in this way the value read is quite far from what is expected.&lt;/P&gt;&lt;P&gt;Could it be that instructions &lt;SPAN style="display: inline !important; float: none; background-color: #f6f6f6; color: #3d3d3d; font-family: courier new,courier,monospace; font-size: 11px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;FTM_GetQuadDecoderCounterValue&lt;/SPAN&gt; e&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #f6f6f6; color: #3d3d3d; font-family: courier new,courier,monospace; font-size: 11px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;FTM_ClearQuadDecoderCounterValue&lt;/SPAN&gt;&amp;nbsp;take some time so while motors are in movement I lose some values?&lt;/P&gt;&lt;P&gt;Is better to leave timer free running (MOD = 0xFFFF) and use overlap callback?&lt;/P&gt;&lt;P&gt;In this case how a can&amp;nbsp;how can I understand the verse of the overflow? I saw in the "&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;ftm_quad_decoder" example&lt;/SPAN&gt; are defined several variables (&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;dir_when_overflow&lt;/SPAN&gt;,&amp;nbsp;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;counter_overflow_flag&lt;/SPAN&gt;,&amp;nbsp;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;counter_overflow_count&lt;/SPAN&gt;) that are defined but now used,&amp;nbsp;therefore not showing this type of use...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Mar 2020 13:55:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-QuadratureDecoder/m-p/1034142#M56613</guid>
      <dc:creator>LArmstrong1985</dc:creator>
      <dc:date>2020-03-30T13:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: FTM QuadratureDecoder</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-QuadratureDecoder/m-p/1034143#M56614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Fabio,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please let me know which device are you working on?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Felipe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:09:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FTM-QuadratureDecoder/m-p/1034143#M56614</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2020-04-02T16:09:32Z</dc:date>
    </item>
  </channel>
</rss>

